From 84360fac42f97fca0109e0b731f826413df6bc45 Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Fri, 14 Oct 2016 07:32:51 -0400 Subject: [PATCH] Add nova.ListAndGetHypervisorUptime The scenario first list all hypervisors,then display the uptime of the listed hypervisors in trun. Measure the "nova hypervisor-uptime" command performance. Change-Id: I25449dd2c3bc76c59d6a9dcaf4b69919441791a3 --- rally-jobs/nova.yaml | 16 ++++++++++++ .../openstack/scenarios/nova/hypervisors.py | 22 ++++++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 12 +++++++++ .../nova/list-and-get-uptime-hypervisors.json | 25 +++++++++++++++++++ .../nova/list-and-get-uptime-hypervisors.yaml | 16 ++++++++++++ .../scenarios/nova/test_hypervisors.py | 12 +++++++++ .../openstack/scenarios/nova/test_utils.py | 9 +++++++ 7 files changed, 112 insertions(+) create mode 100644 samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.json create mode 100644 samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index 15587d62..0d9a0cc5 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -679,6 +679,22 @@ failure_rate: max: 0 + NovaHypervisors.list_and_get_uptime_hypervisors: + - + args: + detailed: True + runner: + type: "constant" + times: 5 + concurrency: 2 + context: + users: + tenants: 3 + 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 84e62aac..ff22749a 100644 --- a/rally/plugins/openstack/scenarios/nova/hypervisors.py +++ b/rally/plugins/openstack/scenarios/nova/hypervisors.py @@ -60,3 +60,25 @@ class ListAndGetHypervisors(utils.NovaScenario): with atomic.ActionTimer(self, "nova.get_hypervisor"): for hypervisor in hypervisors: self._get_hypervisor(hypervisor) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(name="NovaHypervisors.list_and_get_uptime_hypervisors") +class ListAndGetUptimeHypervisors(utils.NovaScenario): + def run(self, detailed=True): + """List hypervisors,then display the uptime of it. + + The scenario first list all hypervisors,then display + the uptime of the listed hypervisors in trun. + + Measure the "nova hypervisor-uptime" 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.uptime_hypervisor"): + for hypervisor in hypervisors: + self._uptime_hypervisor(hypervisor, atomic_action=False) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 4a62e01b..a51575fc 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -883,6 +883,18 @@ class NovaScenario(scenario.OpenStackScenario): """ server.lock() + @atomic.optional_action_timer("nova.uptime_hypervisor") + def _uptime_hypervisor(self, hypervisor, atomic_action=False): + """Display the uptime of the specified 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.uptime(hypervisor) + @atomic.action_timer("nova.unlock_server") def _unlock_server(self, server): """Unlock the given server. diff --git a/samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.json b/samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.json new file mode 100644 index 00000000..0f5396eb --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.json @@ -0,0 +1,25 @@ +{ + "NovaHypervisors.list_and_get_uptime_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-uptime-hypervisors.yaml b/samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.yaml new file mode 100644 index 00000000..51e0a2f3 --- /dev/null +++ b/samples/tasks/scenarios/nova/list-and-get-uptime-hypervisors.yaml @@ -0,0 +1,16 @@ +--- + NovaHypervisors.list_and_get_uptime_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 d44a8ed0..53aef0d7 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_hypervisors.py @@ -37,3 +37,15 @@ class NovaHypervisorsTestCase(test.ScenarioTestCase): scenario._get_hypervisor.assert_called_once_with(hypervisor) self._test_atomic_action_timer(scenario.atomic_actions(), "nova.get_hypervisor") + + def test_list_and_get_uptime_hypervisors(self): + scenario = hypervisors.ListAndGetUptimeHypervisors(self.context) + scenario._list_hypervisors = mock.MagicMock(detailed=False) + scenario._uptime_hypervisor = mock.MagicMock() + scenario.run(detailed=False) + + scenario._list_hypervisors.assert_called_once_with(False) + for hypervisor in scenario._list_hypervisors.return_value: + scenario._uptime_hypervisor.assert_called_once_with(hypervisor) + self._test_atomic_action_timer(scenario.atomic_actions(), + "nova.uptime_hypervisor") diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index a0fc30ed..aaf02a4c 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -1119,3 +1119,12 @@ class NovaScenarioTestCase(test.ScenarioTestCase): "fake_agg", "fake_host") self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.aggregate_remove_host") + + def test__uptime_hypervisor(self): + nova_scenario = utils.NovaScenario() + nova_scenario._uptime_hypervisor("fake_hostname") + + self.admin_clients("nova").hypervisors.uptime.assert_called_once_with( + "fake_hostname") + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.uptime_hypervisor")