diff options
author | Juha Kosonen <juha.kosonen@nokia.com> | 2018-08-14 16:00:58 +0300 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-08-16 10:56:12 +0200 |
commit | ca46e50190055c9752847d89d044e9fc6c307e81 (patch) | |
tree | cd50f915bec7ac4a5072c109aa27b3de3d2a6ee0 | |
parent | 86656df19a9496c18ad1b40eaba65a425eb494ea (diff) |
Create new project/user for rally test
FUNCTEST-1002
Change-Id: Id19b9aa70aeded6d99978084b3de4a63e31a81ad
Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
(cherry picked from commit 4b7d89de42fe9a3867b12ea39721ad92aff96340)
4 files changed, 30 insertions, 11 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index 4fd2d021f..91b795389 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -33,7 +33,7 @@ from functest.utils import env LOGGER = logging.getLogger(__name__) -class RallyBase(singlevm.VmReady1): +class RallyBase(singlevm.VmReady2): """Base class form Rally testcases implementation.""" # pylint: disable=too-many-instance-attributes @@ -62,6 +62,18 @@ class RallyBase(singlevm.VmReady1): def __init__(self, **kwargs): """Initialize RallyBase object.""" super(RallyBase, self).__init__(**kwargs) + assert self.orig_cloud + assert self.project + if self.orig_cloud.get_role("admin"): + role_name = "admin" + elif self.orig_cloud.get_role("Admin"): + role_name = "Admin" + else: + raise Exception("Cannot detect neither admin nor Admin") + self.orig_cloud.grant_role( + role_name, user=self.project.user.id, + project=self.project.project.id, + domain=self.project.domain.id) self.creators = [] self.mode = '' self.summary = [] @@ -492,7 +504,13 @@ class RallyBase(singlevm.VmReady1): try: assert super(RallyBase, self).run( **kwargs) == testcase.TestCase.EX_OK - conf_utils.create_rally_deployment() + environ = dict( + os.environ, + OS_USERNAME=self.project.user.name, + OS_PROJECT_NAME=self.project.project.name, + OS_PROJECT_ID=self.project.project.id, + OS_PASSWORD=self.project.password) + conf_utils.create_rally_deployment(environ=environ) self._prepare_env() self._run_tests() self._generate_report() diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py index 88ad3b2d9..a23eb1747 100644 --- a/functest/opnfv_tests/openstack/tempest/conf_utils.py +++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py @@ -44,7 +44,7 @@ CI_INSTALLER_TYPE = env.get('INSTALLER_TYPE') LOGGER = logging.getLogger(__name__) -def create_rally_deployment(): +def create_rally_deployment(environ=None): """Create new rally deployment""" # set the architecture to default pod_arch = env.get("POD_ARCH") @@ -73,7 +73,7 @@ def create_rally_deployment(): cmd = ['rally', 'deployment', 'create', '--fromenv', '--name', str(getattr(config.CONF, 'rally_deployment_name'))] - output = subprocess.check_output(cmd) + output = subprocess.check_output(cmd, env=environ) LOGGER.info("%s\n%s", " ".join(cmd), output) cmd = ['rally', 'deployment', 'check'] diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index 6a9581af0..34c6818b4 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -23,12 +23,15 @@ class OSRallyTesting(unittest.TestCase): # pylint: disable=too-many-public-methods def setUp(self): with mock.patch('os_client_config.get_config'), \ - mock.patch('shade.OperatorCloud') as mock_shade: + mock.patch('shade.OperatorCloud') as mock_shade, \ + mock.patch('functest.core.tenantnetwork.NewProject') \ + as mock_new_project: self.rally_base = rally.RallyBase() self.rally_base.image = munch.Munch(name='foo') self.rally_base.flavor = munch.Munch(name='foo') self.rally_base.flavor_alt = munch.Munch(name='bar') self.assertTrue(mock_shade.called) + self.assertTrue(mock_new_project.called) def test_build_task_args_missing_floating_network(self): os.environ['OS_AUTH_URL'] = '' @@ -293,16 +296,13 @@ class OSRallyTesting(unittest.TestCase): self.rally_base.test_name = 'test1' with mock.patch.object(self.rally_base.cloud, 'list_hypervisors') as mock_list_hyperv, \ - mock.patch.object(self.rally_base.cloud, - 'set_flavor_specs') as mock_set_flavor_specs, \ - mock.patch.object(self.rally_base.cloud, 'create_flavor', + mock.patch.object(self.rally_base, 'create_flavor_alt', side_effect=Exception) \ as mock_create_flavor: with self.assertRaises(Exception): self.rally_base._prepare_env() mock_list_hyperv.assert_called_once() mock_create_flavor.assert_called_once() - mock_set_flavor_specs.assert_not_called() @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.' '_run_task') @@ -322,7 +322,7 @@ class OSRallyTesting(unittest.TestCase): mock_run_task.assert_any_call('test1') def test_clean_up_default(self): - with mock.patch.object(self.rally_base.cloud, + with mock.patch.object(self.rally_base.orig_cloud, 'delete_flavor') as mock_delete_flavor: self.rally_base.flavor_alt = mock.Mock() self.rally_base.clean() diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index 1585cac09..81febd8c0 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -27,7 +27,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase): mock.call(['rally', 'deployment', 'destroy', '--deployment', str(getattr(config.CONF, 'rally_deployment_name'))]), mock.call(['rally', 'deployment', 'create', '--fromenv', '--name', - str(getattr(config.CONF, 'rally_deployment_name'))]), + str(getattr(config.CONF, 'rally_deployment_name'))], + env=None), mock.call(['rally', 'deployment', 'check'])] mock_exec.assert_has_calls(calls) |