diff options
author | Juha Kosonen <juha.kosonen@nokia.com> | 2017-09-20 10:15:07 +0300 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2017-09-20 22:00:09 +0200 |
commit | e6b3c6fe942672461d448d13bd614b3b6e598e62 (patch) | |
tree | 188d54257ce60168341d77c688af6c9c152eef92 | |
parent | e171c13059358d32d9263076aeceb211942af3cd (diff) |
Dedicated flavors for rally tests
Create flavors and use them in rally scenarios instead of expecting
certain flavors to pre-exist.
Change-Id: I77c94ab80fcabd7b80ffb36f9856a48121858009
Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
(cherry picked from commit 3b98874f010329198b8c3a13a4711c17a593b9cc)
-rw-r--r-- | functest/ci/config_functest.yaml | 2 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/rally/rally.py | 32 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/rally/scenario/full/opnfv-nova.yaml | 2 | ||||
-rw-r--r-- | functest/tests/unit/openstack/rally/test_rally.py | 46 |
4 files changed, 79 insertions, 3 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index 16ba8b822..575b44783 100644 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -136,6 +136,8 @@ rally: subnet_name: rally-subnet subnet_cidr: 192.168.140.0/24 router_name: rally-router + flavor_name: rally-tiny + flavor_alt_name: rally-mini vnf: juju_epc: diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index 44c7f2bad..e92639b29 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -29,6 +29,7 @@ from functest.energy import energy from functest.opnfv_tests.openstack.snaps import snaps_utils from functest.utils.constants import CONST +from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor from snaps.openstack.create_image import ImageSettings from snaps.openstack.create_network import NetworkSettings, SubnetSettings from snaps.openstack.create_router import RouterSettings @@ -54,7 +55,11 @@ class RallyBase(testcase.TestCase): if hasattr(CONST, 'openstack_extra_properties'): GLANCE_IMAGE_EXTRA_PROPERTIES = CONST.__getattribute__( 'openstack_extra_properties') - FLAVOR_NAME = "m1.tiny" + FLAVOR_NAME = CONST.__getattribute__('rally_flavor_name') + FLAVOR_ALT_NAME = CONST.__getattribute__('rally_flavor_alt_name') + FLAVOR_EXTRA_SPECS = None + if hasattr(CONST, 'flavor_extra_specs'): + FLAVOR_EXTRA_SPECS = CONST.__getattribute__('flavor_extra_specs') RALLY_DIR = pkg_resources.resource_filename( 'functest', 'opnfv_tests/openstack/rally') @@ -105,6 +110,8 @@ class RallyBase(testcase.TestCase): self.image_name = None self.ext_net_name = None self.priv_net_id = None + self.flavor_name = None + self.flavor_alt_name = None self.smoke = None self.test_name = None self.start_time = None @@ -114,7 +121,8 @@ class RallyBase(testcase.TestCase): def _build_task_args(self, test_file_name): task_args = {'service_list': [test_file_name]} task_args['image_name'] = self.image_name - task_args['flavor_name'] = self.FLAVOR_NAME + task_args['flavor_name'] = self.flavor_name + task_args['flavor_alt_name'] = self.flavor_alt_name task_args['glance_image_location'] = self.GLANCE_IMAGE_PATH task_args['glance_image_format'] = self.GLANCE_IMAGE_FORMAT task_args['tmpl_dir'] = self.TEMPLATE_DIR @@ -472,6 +480,8 @@ class RallyBase(testcase.TestCase): subnet_name = self.RALLY_PRIVATE_SUBNET_NAME + self.guid router_name = self.RALLY_ROUTER_NAME + self.guid self.image_name = self.GLANCE_IMAGE_NAME + self.guid + self.flavor_name = self.FLAVOR_NAME + self.guid + self.flavor_alt_name = self.FLAVOR_ALT_NAME + self.guid self.ext_net_name = snaps_utils.get_ext_net_name(self.os_creds) LOGGER.debug("Creating image '%s'...", self.image_name) @@ -511,6 +521,24 @@ class RallyBase(testcase.TestCase): raise Exception("Failed to create router") self.creators.append(router_creator) + LOGGER.debug("Creating flavor '%s'...", self.flavor_name) + flavor_creator = OpenStackFlavor( + self.os_creds, FlavorSettings( + name=self.flavor_name, ram=512, disk=1, vcpus=1, + metadata=self.FLAVOR_EXTRA_SPECS)) + if flavor_creator is None or flavor_creator.create() is None: + raise Exception("Failed to create flavor") + self.creators.append(flavor_creator) + + LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name) + flavor_alt_creator = OpenStackFlavor( + self.os_creds, FlavorSettings( + name=self.flavor_alt_name, ram=1024, disk=1, vcpus=1, + metadata=self.FLAVOR_EXTRA_SPECS)) + if flavor_alt_creator is None or flavor_alt_creator.create() is None: + raise Exception("Failed to create flavor") + self.creators.append(flavor_alt_creator) + def _run_tests(self): if self.test_name == 'all': for test in self.TESTS: diff --git a/functest/opnfv_tests/openstack/rally/scenario/full/opnfv-nova.yaml b/functest/opnfv_tests/openstack/rally/scenario/full/opnfv-nova.yaml index d7622093d..8fb5f5eef 100644 --- a/functest/opnfv_tests/openstack/rally/scenario/full/opnfv-nova.yaml +++ b/functest/opnfv_tests/openstack/rally/scenario/full/opnfv-nova.yaml @@ -215,7 +215,7 @@ args: {{ vm_params(image_name, flavor_name) }} to_flavor: - name: "m1.small" + name: {{ flavor_alt_name }} confirm: true force_delete: false nics: diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index 63c0192ba..191722dc0 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -328,6 +328,52 @@ class OSRallyTesting(unittest.TestCase): mock_get_net.assert_called() mock_create_router.assert_called() + @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.' + 'get_ext_net_name', return_value='test_net_name') + @mock.patch('snaps.openstack.utils.deploy_utils.create_image', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.utils.deploy_utils.create_network', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.utils.deploy_utils.create_router', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create', + return_value=None) + def test_prepare_env_flavor_creation_failed( + self, mock_create_flavor, mock_create_router, mock_create_net, + mock_get_img, mock_get_net): + self.rally_base.TESTS = ['test1', 'test2'] + self.rally_base.test_name = 'test1' + with self.assertRaises(Exception): + self.rally_base._prepare_env() + mock_create_net.assert_called() + mock_get_img.assert_called() + mock_get_net.assert_called() + mock_create_router.assert_called() + mock_create_flavor.assert_called_once() + + @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.' + 'get_ext_net_name', return_value='test_net_name') + @mock.patch('snaps.openstack.utils.deploy_utils.create_image', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.utils.deploy_utils.create_network', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.utils.deploy_utils.create_router', + return_value=mock.Mock()) + @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create', + side_effect=[mock.Mock, None]) + def test_prepare_env_flavor_alt_creation_failed( + self, mock_create_flavor, mock_create_router, mock_create_net, + mock_get_img, mock_get_net): + self.rally_base.TESTS = ['test1', 'test2'] + self.rally_base.test_name = 'test1' + with self.assertRaises(Exception): + self.rally_base._prepare_env() + mock_create_net.assert_called() + mock_get_img.assert_called() + mock_get_net.assert_called() + mock_create_router.assert_called() + self.assertEqual(mock_create_flavor.call_count, 2) + @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.' '_run_task', return_value=mock.Mock()) def test_run_tests_all(self, mock_run_task): |