aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Kosonen <juha.kosonen@nokia.com>2018-08-14 16:00:58 +0300
committerJuha Kosonen <juha.kosonen@nokia.com>2018-08-14 16:35:53 +0300
commit4b7d89de42fe9a3867b12ea39721ad92aff96340 (patch)
tree18ed8582b287df71a341bd1aaf045dad41728fca
parent8d3eb364d84f90b19f9e7234d01add8764843081 (diff)
Create new project/user for rally test
FUNCTEST-1002 Change-Id: Id19b9aa70aeded6d99978084b3de4a63e31a81ad Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py22
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py4
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py12
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py3
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 4a6362903..bb67fc270 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 = []
@@ -476,7 +488,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 6eb79ed41..63493ec28 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 1a43e561d..b1dee91cb 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -23,13 +23,16 @@ class OSRallyTesting(unittest.TestCase):
# pylint: disable=too-many-public-methods
def setUp(self):
with mock.patch('os_client_config.get_config') as mock_get_config, \
- mock.patch('shade.OpenStackCloud') as mock_shade:
+ mock.patch('shade.OpenStackCloud') 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_get_config.called)
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'] = ''
@@ -281,16 +284,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')
@@ -310,7 +310,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)