From 0445aa61ddf587c518547e526e910543c6e48e65 Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Mon, 5 Sep 2016 02:53:32 -0400 Subject: [PATCH] Add NovaFlavors.create_and_get_flavor The scenario first creates a flavor,then get detailed information of the created flavor Change-Id: I99dd4f0ae39ed7587bbd71e83b205dc205acacca --- rally-jobs/nova.yaml | 14 ++++++++++ .../openstack/scenarios/nova/flavors.py | 20 ++++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 8 ++++++ .../scenarios/nova/create-and-get-flavor.json | 27 +++++++++++++++++++ .../scenarios/nova/create-and-get-flavor.yaml | 19 +++++++++++++ .../openstack/scenarios/nova/test_flavors.py | 10 +++++++ .../openstack/scenarios/nova/test_utils.py | 11 ++++++++ 7 files changed, 109 insertions(+) create mode 100644 samples/tasks/scenarios/nova/create-and-get-flavor.json create mode 100644 samples/tasks/scenarios/nova/create-and-get-flavor.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index cac9d07a..7109ce61 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -1069,6 +1069,20 @@ failure_rate: max: 0 + NovaFlavors.create_and_get_flavor: + - + args: + ram: 500 + vcpus: 1 + disk: 1 + runner: + type: "constant" + times: 5 + concurrency: 2 + sla: + failure_rate: + max: 0 + NovaFlavors.create_and_list_flavor_access: - args: diff --git a/rally/plugins/openstack/scenarios/nova/flavors.py b/rally/plugins/openstack/scenarios/nova/flavors.py index 83f36eb2..e0cc5d65 100644 --- a/rally/plugins/openstack/scenarios/nova/flavors.py +++ b/rally/plugins/openstack/scenarios/nova/flavors.py @@ -73,3 +73,23 @@ class NovaFlavors(utils.NovaScenario): :param kwargs: Optional additional arguments for flavor creation """ self._create_flavor(ram, vcpus, disk, **kwargs) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["nova"]}, + name="NovaFlavors.create_and_get_flavor") +class CreateAndGetFlavor(utils.NovaScenario): + """Scenario for create and get flavor.""" + + def run(self, ram, vcpus, disk, **kwargs): + """Create flavor and get detailed information of the flavor. + + :param ram: Memory in MB for the flavor + :param vcpus: Number of VCPUs for the flavor + :param disk: Size of local disk in GB + :param kwargs: Optional additional arguments for flavor creation + + """ + flavor = self._create_flavor(ram, vcpus, disk, **kwargs) + self._get_flavor(flavor.id) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 949752e2..a492b981 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -987,3 +987,11 @@ class NovaScenario(scenario.OpenStackScenario): description=description) else: return server.update(name=new_name) + + @atomic.action_timer("nova.get_flavor") + def _get_flavor(self, flavor_id): + """Show a flavor + + :param flavor_id: The flavor ID to get + """ + return self.admin_clients("nova").flavors.get(flavor_id) diff --git a/samples/tasks/scenarios/nova/create-and-get-flavor.json b/samples/tasks/scenarios/nova/create-and-get-flavor.json new file mode 100644 index 00000000..e75e46f2 --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-get-flavor.json @@ -0,0 +1,27 @@ +{ + "NovaFlavors.create_and_get_flavor": [ + { + "runner": { + "type": "constant", + "concurrency": 2, + "times": 10 + }, + "args": { + "ram": 500, + "vcpus" : 1, + "disk": 1 + }, + "context": { + "users": { + "tenants": 1, + "users_per_tenant": 1 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/nova/create-and-get-flavor.yaml b/samples/tasks/scenarios/nova/create-and-get-flavor.yaml new file mode 100644 index 00000000..b31cec2b --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-get-flavor.yaml @@ -0,0 +1,19 @@ + +--- + NovaFlavors.create_and_get_flavor: + - + runner: + type: "constant" + concurrency: 2 + times: 10 + args: + ram: 500 + vcpus : 1 + disk: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py b/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py index 5367508d..ea7236eb 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py @@ -54,3 +54,13 @@ class NovaFlavorsTestCase(test.TestCase): scenario.create_flavor(ram=100, vcpus=1, disk=1, fakeargs="fakeargs") scenario._create_flavor.assert_called_once_with(100, 1, 1, fakeargs="fakeargs") + + def test_create_and_get_flavor(self, **kwargs): + scenario = flavors.CreateAndGetFlavor() + scenario._create_flavor = mock.Mock() + scenario._get_flavor = mock.Mock() + scenario.run(ram=100, vcpus=1, disk=1, **kwargs) + + scenario._create_flavor.assert_called_once_with(100, 1, 1, **kwargs) + scenario._get_flavor.assert_called_once_with( + scenario._create_flavor.return_value.id) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 7e9178a1..c6c1e049 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -995,6 +995,17 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.create_flavor") + def test__get_flavor(self): + nova_scenario = utils.NovaScenario() + result = nova_scenario._get_flavor("foo_flavor_id") + self.assertEqual( + self.admin_clients("nova").flavors.get.return_value, + result) + self.admin_clients("nova").flavors.get.assert_called_once_with( + "foo_flavor_id") + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.get_flavor") + def test__update_server(self): server = mock.Mock() nova_scenario = utils.NovaScenario()