From 47505e29814d427b5ee691f5a3a49be9c4d08fb0 Mon Sep 17 00:00:00 2001 From: zhangzhang <zhangzh.fnst@cn.fujitsu.com> Date: Tue, 20 Sep 2016 04:31:27 -0400 Subject: [PATCH] Add nova.CreateFlavorAndSetKeys the scenario first creates a flavor,then add the extra specs to it. Measure the "nova flavor-key" command performance. Change-Id: I10181bfd3bdcc4334f4f1e479b94dabfc86cbe6d --- rally-jobs/nova.yaml | 20 +++++++++++++ .../openstack/scenarios/nova/flavors.py | 21 +++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 9 ++++++ .../nova/create-flavor-and-set-keys.json | 30 +++++++++++++++++++ .../nova/create-flavor-and-set-keys.yaml | 20 +++++++++++++ .../openstack/scenarios/nova/test_flavors.py | 13 ++++++++ .../openstack/scenarios/nova/test_utils.py | 13 ++++++++ 7 files changed, 126 insertions(+) create mode 100644 samples/tasks/scenarios/nova/create-flavor-and-set-keys.json create mode 100644 samples/tasks/scenarios/nova/create-flavor-and-set-keys.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index 0139562889..c035e1f610 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -1089,6 +1089,26 @@ failure_rate: max: 0 + NovaFlavors.create_flavor_and_set_keys: + - + args: + ram: 500 + vcpus : 1 + disk: 1 + extra_specs: + quota:disk_read_bytes_sec: 10240 + runner: + type: "constant" + concurrency: 2 + times: 10 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + NovaFlavors.create_and_get_flavor: - args: diff --git a/rally/plugins/openstack/scenarios/nova/flavors.py b/rally/plugins/openstack/scenarios/nova/flavors.py index 60cf2b22e4..32c40edb47 100644 --- a/rally/plugins/openstack/scenarios/nova/flavors.py +++ b/rally/plugins/openstack/scenarios/nova/flavors.py @@ -104,3 +104,24 @@ class CreateAndGetFlavor(utils.NovaScenario): """ flavor = self._create_flavor(ram, vcpus, disk, **kwargs) self._get_flavor(flavor.id) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["nova"]}, + name="NovaFlavors.create_flavor_and_set_keys") +class CreateFlavorAndSetKeys(utils.NovaScenario): + def run(self, ram, vcpus, disk, extra_specs, **kwargs): + """Create flavor and set keys to the flavor. + + Measure the "nova flavor-key" command performance. + the scenario first create a flavor,then add the extra specs to it. + + :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 extra_specs: additional arguments for flavor set keys + :param kwargs: Optional additional arguments for flavor creation + """ + flavor = self._create_flavor(ram, vcpus, disk, **kwargs) + self._set_flavor_keys(flavor, extra_specs) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index aa7b18eb1b..1fcf4d2907 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -909,6 +909,15 @@ class NovaScenario(scenario.OpenStackScenario): """ return self.clients("nova").flavors.list(detailed, **kwargs) + @atomic.action_timer("nova.set_flavor_keys") + def _set_flavor_keys(self, flavor, extra_specs): + """set flavor keys + + :param flavor: flavor to set keys + :param extra_specs: additional arguments for flavor set keys + """ + return flavor.set_keys(extra_specs) + @atomic.action_timer("nova.list_agents") def _list_agents(self, hypervisor=None): """List all nova-agent builds. diff --git a/samples/tasks/scenarios/nova/create-flavor-and-set-keys.json b/samples/tasks/scenarios/nova/create-flavor-and-set-keys.json new file mode 100644 index 0000000000..e150a2967c --- /dev/null +++ b/samples/tasks/scenarios/nova/create-flavor-and-set-keys.json @@ -0,0 +1,30 @@ +{ + "NovaFlavors.create_flavor_and_set_keys": [ + { + "runner": { + "type": "constant", + "concurrency": 2, + "times": 10 + }, + "args": { + "ram": 500, + "vcpus" : 1, + "disk": 1, + "extra_specs": { + "quota:disk_read_bytes_sec": 10240 + } + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/nova/create-flavor-and-set-keys.yaml b/samples/tasks/scenarios/nova/create-flavor-and-set-keys.yaml new file mode 100644 index 0000000000..c376cc00a6 --- /dev/null +++ b/samples/tasks/scenarios/nova/create-flavor-and-set-keys.yaml @@ -0,0 +1,20 @@ +--- + NovaFlavors.create_flavor_and_set_keys: + - + runner: + type: "constant" + concurrency: 2 + times: 10 + args: + ram: 500 + vcpus : 1 + disk: 1 + extra_specs: + quota:disk_read_bytes_sec: 10240 + context: + users: + tenants: 3 + users_per_tenant: 2 + 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 b75050d79b..219affe18c 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_flavors.py @@ -63,3 +63,16 @@ class NovaFlavorsTestCase(test.TestCase): scenario._create_flavor.assert_called_once_with(100, 1, 1, **kwargs) scenario._get_flavor.assert_called_once_with( scenario._create_flavor.return_value.id) + + def test_create_flavor_and_set_keys(self): + scenario = flavors.CreateFlavorAndSetKeys() + scenario._create_flavor = mock.MagicMock() + scenario._set_flavor_keys = mock.MagicMock() + specs_args = {"fakeargs": "foo"} + scenario.run(ram=100, vcpus=1, disk=1, extra_specs=specs_args, + fakeargs="fakeargs") + + scenario._create_flavor.assert_called_once_with(100, 1, 1, + fakeargs="fakeargs") + scenario._set_flavor_keys.assert_called_once_with( + scenario._create_flavor.return_value, specs_args) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 4935a6d0cf..d9eda2841c 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -909,6 +909,19 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.list_flavors") + def test__set_flavor_keys(self): + flavor = mock.MagicMock() + nova_scenario = utils.NovaScenario() + extra_specs = {"fakeargs": "foo"} + flavor.set_keys = mock.MagicMock() + + result = nova_scenario._set_flavor_keys(flavor, extra_specs) + self.assertEqual(flavor.set_keys.return_value, result) + flavor.set_keys.assert_called_once_with(extra_specs) + + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.set_flavor_keys") + @ddt.data({}, {"hypervisor": "foo_hypervisor"}) @ddt.unpack