summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-09-06 14:03:22 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-09-06 21:09:44 +0200
commit98f3bf16722e5e718130f960910d64bc76951e3b (patch)
tree6b1c860af9b341c5ad21778875674cf1a0d9d955
parent95bd62a751501caf0755e79e33de7a42f72deb27 (diff)
Add role to users created by rally if required
It sets [openstack] keystone_default_role if NEW_USER_ROLE differs from member. Change-Id: Ib6be5cf22654e882ea110298cba421c1e87c78fd Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index a91059a2b..00e759150 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -21,6 +21,7 @@ import time
import pkg_resources
import prettytable
+from six.moves import configparser
from xtesting.core import testcase
from xtesting.energy import energy
import yaml
@@ -141,6 +142,30 @@ class RallyBase(singlevm.VmReady2):
return test_file_name
@staticmethod
+ def update_keystone_default_role(rally_conf='/etc/rally/rally.conf'):
+ """Set keystone_default_role in rally.conf"""
+ if env.get("NEW_USER_ROLE").lower() != "member":
+ rconfig = configparser.RawConfigParser()
+ rconfig.read(rally_conf)
+ if not rconfig.has_section('openstack'):
+ rconfig.add_section('openstack')
+ rconfig.set(
+ 'openstack', 'keystone_default_role', env.get("NEW_USER_ROLE"))
+ with open(rally_conf, 'wb') as config_file:
+ rconfig.write(config_file)
+
+ @staticmethod
+ def clean_rally_conf(rally_conf='/etc/rally/rally.conf'):
+ """Clean Rally config"""
+ if env.get("NEW_USER_ROLE").lower() != "member":
+ rconfig = configparser.RawConfigParser()
+ rconfig.read(rally_conf)
+ if rconfig.has_option('openstack', 'keystone_default_role'):
+ rconfig.remove_option('openstack', 'keystone_default_role')
+ with open(rally_conf, 'wb') as config_file:
+ rconfig.write(config_file)
+
+ @staticmethod
def get_task_id(cmd_raw):
"""
Get task id from command rally result.
@@ -390,6 +415,7 @@ class RallyBase(singlevm.VmReady2):
raise Exception("Task file '{}' does not exist.".
format(self.task_file))
+ self.update_keystone_default_role()
self.compute_cnt = len(self.cloud.list_hypervisors())
self.flavor_alt = self.create_flavor_alt()
LOGGER.debug("flavor: %s", self.flavor_alt)
@@ -470,6 +496,7 @@ class RallyBase(singlevm.VmReady2):
def clean(self):
"""Cleanup of OpenStack resources. Should be called on completion."""
+ self.clean_rally_conf()
if self.flavor_alt:
self.orig_cloud.delete_flavor(self.flavor_alt.id)
super(RallyBase, self).clean()