From 98f3bf16722e5e718130f960910d64bc76951e3b Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 6 Sep 2018 14:03:22 +0200 Subject: Add role to users created by rally if required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It sets [openstack] keystone_default_role if NEW_USER_ROLE differs from member. Change-Id: Ib6be5cf22654e882ea110298cba421c1e87c78fd Signed-off-by: Cédric Ollivier --- functest/opnfv_tests/openstack/rally/rally.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 @@ -140,6 +141,30 @@ class RallyBase(singlevm.VmReady2): self._apply_blacklist(scenario_file_name, test_file_name) 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): """ @@ -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() -- cgit 1.2.3-korg