From 87d4c972abf480fa6111e455d99ed52a89214ae2 Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Wed, 12 Oct 2016 07:22:02 -0400 Subject: [PATCH] Add nova.ListAndSearchHypervisors scenario List all servers belonging to specific hypervisor. The scenario first list all hypervisors,then find its hostname, then list all servers belonging to the hypervisor Measure the "nova hypervisor-servers " command performance. Change-Id: I8511a9790037ee5f3bab003309f2debe31b00590 --- rally-jobs/nova.yaml | 16 +++++++++++ .../openstack/scenarios/nova/hypervisors.py | 27 ++++++++++++++++++- .../plugins/openstack/scenarios/nova/utils.py | 14 ++++++++++ .../nova/list-and-search-hypervisor.json | 25 +++++++++++++++++ .../nova/list-and-search-hypervisor.yaml | 16 +++++++++++ .../scenarios/nova/test_hypervisors.py | 14 ++++++++++ .../openstack/scenarios/nova/test_utils.py | 9 +++++++ 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 samples/tasks/scenarios/nova/list-and-search-hypervisor.json create mode 100644 samples/tasks/scenarios/nova/list-and-search-hypervisor.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index ffa449dc..6c409aa9 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -709,6 +709,22 @@ failure_rate: max: 0 + NovaHypervisors.list_and_search_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 2691bef6..883c7d0f 100644 --- a/rally/plugins/openstack/scenarios/nova/hypervisors.py +++ b/rally/plugins/openstack/scenarios/nova/hypervisors.py @@ -59,7 +59,7 @@ class ListAndGetHypervisors(utils.NovaScenario): with atomic.ActionTimer(self, "nova.get_hypervisor"): for hypervisor in hypervisors: - self._get_hypervisor(hypervisor) + self._get_hypervisor(hypervisor, atomic_action=False) @validation.required_services(consts.Service.NOVA) @@ -95,3 +95,28 @@ class ListAndGetUptimeHypervisors(utils.NovaScenario): with atomic.ActionTimer(self, "nova.uptime_hypervisor"): for hypervisor in hypervisors: self._uptime_hypervisor(hypervisor, atomic_action=False) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(name="NovaHypervisors.list_and_search_hypervisors") +class ListAndSearchHypervisors(utils.NovaScenario): + def run(self, detailed=True): + """List all servers belonging to specific hypervisor. + + The scenario first list all hypervisors,then find its hostname, + then list all servers belonging to the hypervisor + + Measure the "nova hypervisor-servers " 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.search_%s_hypervisors" % len(hypervisors) + ): + for hypervisor in hypervisors: + self._search_hypervisors(hypervisor.hypervisor_hostname, + atomic_action=False) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 35610b91..8e18ca30 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -898,6 +898,20 @@ class NovaScenario(scenario.OpenStackScenario): """ return self.admin_clients("nova").hypervisors.get(hypervisor) + @atomic.optional_action_timer("nova.search_hypervisors") + def _search_hypervisors(self, hypervisor_match, servers=False): + """List all servers belonging to specific hypervisor. + + :param hypervisor_match: Hypervisor's host name. + :param servers: If True, server information is also retrieved. + :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.search(hypervisor_match, + servers=servers) + @atomic.action_timer("nova.lock_server") def _lock_server(self, server): """Lock the given server. diff --git a/samples/tasks/scenarios/nova/list-and-search-hypervisor.json b/samples/tasks/scenarios/nova/list-and-search-hypervisor.json new file mode 100644 index 00000000..17e2f263 --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-search-hypervisor.json @@ -0,0 +1,25 @@ +{ + "NovaHypervisors.list_and_search_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-search-hypervisor.yaml b/samples/tasks/scenarios/nova/list-and-search-hypervisor.yaml new file mode 100644 index 00000000..d4fdb45f --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-search-hypervisor.yaml @@ -0,0 +1,16 @@ +--- + NovaHypervisors.list_and_search_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 45c793d4..ad999991 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py @@ -55,3 +55,17 @@ class NovaHypervisorsTestCase(test.ScenarioTestCase): scenario._uptime_hypervisor.assert_called_once_with(hypervisor) self._test_atomic_action_timer(scenario.atomic_actions(), "nova.uptime_hypervisor") + + def test_list_and_search_hypervisors(self): + fake_hypervisors = [mock.Mock(hypervisor_hostname="fake_hostname")] + scenario = hypervisors.ListAndSearchHypervisors(self.context) + scenario._list_hypervisors = mock.MagicMock( + return_value=fake_hypervisors) + scenario._search_hypervisors = mock.MagicMock() + scenario.run(detailed=False) + + scenario._list_hypervisors.assert_called_once_with(False) + scenario._search_hypervisors.assert_called_once_with( + "fake_hostname", atomic_action=False) + self._test_atomic_action_timer(scenario.atomic_actions(), + "nova.search_1_hypervisors") diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 96d76c92..1010f32f 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -880,6 +880,15 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.get_hypervisor") + def test__search_hypervisors(self): + nova_scenario = utils.NovaScenario() + nova_scenario._search_hypervisors("fake_hostname", servers=False) + + self.admin_clients("nova").hypervisors.search.assert_called_once_with( + "fake_hostname", servers=False) + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.search_hypervisors") + def test__list_images(self): nova_scenario = utils.NovaScenario() result = nova_scenario._list_images(detailed=False, fakearg="fakearg")