From 343a83d7725225e106288863af0771df3310d01c Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Mon, 19 Sep 2016 02:47:56 -0400 Subject: [PATCH] Add nova.ListAndGetHypervisors The scenario fist list all hypervisors,then get detailed information of the listed hypervisors in trun. Change-Id: I62d10ba42c7dfdfa75e61a04af7028deb99bbdfb --- rally-jobs/nova.yaml | 17 +++++++++++++ .../openstack/scenarios/nova/hypervisors.py | 24 ++++++++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 12 +++++++++ .../nova/list-and-get-hypervisors.json | 25 +++++++++++++++++++ .../nova/list-and-get-hypervisors.yaml | 16 ++++++++++++ .../scenarios/nova/test_hypervisors.py | 12 +++++++++ .../openstack/scenarios/nova/test_utils.py | 12 +++++++++ 7 files changed, 118 insertions(+) create mode 100644 samples/tasks/scenarios/nova/list-and-get-hypervisors.json create mode 100644 samples/tasks/scenarios/nova/list-and-get-hypervisors.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index cac9d07a..27429448 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -642,6 +642,23 @@ failure_rate: max: 0 + + NovaHypervisors.list_and_get_hypervisors: + - + args: + detailed: True + runner: + type: "constant" + times: 5 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + NovaImages.list_images: - args: diff --git a/rally/plugins/openstack/scenarios/nova/hypervisors.py b/rally/plugins/openstack/scenarios/nova/hypervisors.py index 34978d01..956f539d 100644 --- a/rally/plugins/openstack/scenarios/nova/hypervisors.py +++ b/rally/plugins/openstack/scenarios/nova/hypervisors.py @@ -16,6 +16,7 @@ from rally import consts from rally.plugins.openstack import scenario from rally.plugins.openstack.scenarios.nova import utils +from rally.task import atomic from rally.task import validation @@ -34,3 +35,26 @@ class NovaHypervisors(utils.NovaScenario): detailed information about all of them """ self._list_hypervisors(detailed) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(name="NovaHypervisors.list_and_get_hypervisors") +class ListAndGetHypervisors(utils.NovaScenario): + """Benchmark scenario for Nova hypervisors.""" + def run(self, detailed=True): + """List and Get hypervisors. + + The scenario fist list all hypervisors,then get detailed information + of the listed hypervisors in trun. + + Measure the "nova hypervisor-show" command performance. + + :param detailed: True if the hypervisor listing should contain + detailed information about all of them + """ + hypervisors = self._list_hypervisors(detailed) + + with atomic.ActionTimer(self, "nova.get_hypervisor"): + for hypervisor in hypervisors: + self._get_hypervisor(hypervisor) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 949752e2..d044a25b 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -863,6 +863,18 @@ class NovaScenario(scenario.OpenStackScenario): """List hypervisors.""" return self.admin_clients("nova").hypervisors.list(detailed) + @atomic.optional_action_timer("nova.get_hypervisor") + def _get_hypervisor(self, hypervisor): + """Get a specific hypervisor. + + :param hypervisor: Hypervisor to get. + :param atomic_action: True if this is atomic action. added and + handled by the optional_action_timer() + decorator. + :returns: Hypervisor object + """ + return self.admin_clients("nova").hypervisors.get(hypervisor) + @atomic.action_timer("nova.lock_server") def _lock_server(self, server): """Lock the given server. diff --git a/samples/tasks/scenarios/nova/list-and-get-hypervisors.json b/samples/tasks/scenarios/nova/list-and-get-hypervisors.json new file mode 100644 index 00000000..9deb4000 --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-get-hypervisors.json @@ -0,0 +1,25 @@ +{ + "NovaHypervisors.list_and_get_hypervisors": [ + { + "args": { + "detailed": true + }, + "runner": { + "type": "constant", + "concurrency": 2, + "times": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/nova/list-and-get-hypervisors.yaml b/samples/tasks/scenarios/nova/list-and-get-hypervisors.yaml new file mode 100644 index 00000000..40497f12 --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-get-hypervisors.yaml @@ -0,0 +1,16 @@ +--- + NovaHypervisors.list_and_get_hypervisors: + - + args: + detailed: True + runner: + type: "constant" + times: 2 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py b/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py index 709d6f71..4433e45d 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py @@ -29,3 +29,15 @@ class NovaHypervisorsTestCase(test.ScenarioTestCase): scenario._list_hypervisors = mock.Mock() scenario.list_hypervisors(detailed=False) scenario._list_hypervisors.assert_called_once_with(False) + + def test_list_and_get_hypervisors(self): + scenario = hypervisors.ListAndGetHypervisors(self.context) + scenario._list_hypervisors = mock.MagicMock(detailed=False) + scenario._get_hypervisor = mock.MagicMock() + scenario.run(detailed=False) + + scenario._list_hypervisors.assert_called_once_with(False) + for hypervisor in scenario._list_hypervisors.return_value: + scenario._get_hypervisor.assert_called_once_with(hypervisor) + self._test_atomic_action_timer(scenario.atomic_actions(), + "nova.get_hypervisor") diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 7e9178a1..e2b3ec69 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -841,6 +841,18 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.list_hypervisors") + def test__get_hypervisor(self): + hypervisor = mock.Mock() + nova_scenario = utils.NovaScenario() + result = nova_scenario._get_hypervisor(hypervisor) + self.assertEqual( + self.admin_clients("nova").hypervisors.get.return_value, + result) + self.admin_clients("nova").hypervisors.get.assert_called_once_with( + hypervisor) + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.get_hypervisor") + def test__list_images(self): nova_scenario = utils.NovaScenario() result = nova_scenario._list_images(detailed=False, fakearg="fakearg")