From 3d87b6aebe23af7f83be483169b2e54f1f337742 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Wed, 22 Feb 2017 04:51:36 -0500 Subject: [PATCH] Add NovaServerGroups.create_and_get_server_group Create a server group, then get its detailed information. Measure the "nova server-group-create" and "nova server-group-get" command performance. Change-Id: I865fda72b88af017caba96be1b11183d7ca804e9 --- rally-jobs/nova.yaml | 19 ++++++ .../openstack/scenarios/nova/server_groups.py | 23 ++++++++ .../plugins/openstack/scenarios/nova/utils.py | 10 ++++ .../nova/create-and-get-server-group.json | 29 ++++++++++ .../nova/create-and-get-server-group.yaml | 16 +++++ .../scenarios/nova/test_server_groups.py | 58 +++++++++++++++++++ .../openstack/scenarios/nova/test_utils.py | 12 ++++ 7 files changed, 167 insertions(+) create mode 100644 samples/tasks/scenarios/nova/create-and-get-server-group.json create mode 100644 samples/tasks/scenarios/nova/create-and-get-server-group.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index d26eaf87bb..ce3ebb089c 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -181,6 +181,25 @@ failure_rate: max: 0 + NovaServerGroups.create_and_get_server_group: + {% for s in (["affinity"], ["anti-affinity"]) %} + - + args: + kwargs: + policies: {{s}} + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + {% endfor %} + NovaServerGroups.create_and_list_server_groups: {% for s in (["affinity"], ["anti-affinity"]) %} - diff --git a/rally/plugins/openstack/scenarios/nova/server_groups.py b/rally/plugins/openstack/scenarios/nova/server_groups.py index 910206d60b..30d87c78df 100755 --- a/rally/plugins/openstack/scenarios/nova/server_groups.py +++ b/rally/plugins/openstack/scenarios/nova/server_groups.py @@ -53,3 +53,26 @@ class CreateAndListServerGroups(utils.NovaScenario): "list of server groups: {}").format(server_group, server_groups_list) self.assertIn(server_group, server_groups_list, err_msg=msg) + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(users=True) +@scenario.configure(context={"cleanup": ["nova"]}, + name="NovaServerGroups.create_and_get_server_group") +class CreateAndGetServerGroup(utils.NovaScenario): + + def run(self, kwargs=None): + """Create a server group, then get its detailed information. + + Measure the "nova server-group-create" and "nova server-group-get" + command performance. + + :param kwargs: Server group name and policy + """ + kwargs["name"] = self.generate_random_name() + server_group = self._create_server_group(**kwargs) + msg = ("Server Groups isn't created") + self.assertTrue(server_group, err_msg=msg) + + server_group_info = self._get_server_group(server_group.id) + self.assertEqual(server_group.id, server_group_info.id) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 07671ab788..693d518fbb 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -466,6 +466,16 @@ class NovaScenario(scenario.OpenStackScenario): """ return self.clients("nova").server_groups.create(**kwargs) + @atomic.action_timer("nova.get_server_group") + def _get_server_group(self, id): + """Get a specific server group. + + :param id: Unique ID of the server group to get + + :rtype: :class:`ServerGroup` + """ + return self.clients("nova").server_groups.get(id) + @atomic.action_timer("nova.list_server_groups") def _list_server_groups(self, all_projects=False): """Get a list of all server groups. diff --git a/samples/tasks/scenarios/nova/create-and-get-server-group.json b/samples/tasks/scenarios/nova/create-and-get-server-group.json new file mode 100644 index 0000000000..46fb5296cb --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-get-server-group.json @@ -0,0 +1,29 @@ +{ + "NovaServerGroups.create_and_get_server_group": [ + { + "args": { + "kwargs": { + "policies": [ + "affinity" + ] + } + }, + "runner": { + "type": "constant", + "times": 4, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/nova/create-and-get-server-group.yaml b/samples/tasks/scenarios/nova/create-and-get-server-group.yaml new file mode 100644 index 0000000000..e1d2d2e15c --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-get-server-group.yaml @@ -0,0 +1,16 @@ + NovaServerGroups.create_and_get_server_group: + - + args: + kwargs: + policies: ["affinity"] + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_server_groups.py b/tests/unit/plugins/openstack/scenarios/nova/test_server_groups.py index 7290bb4ed8..06c9b7aed1 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_server_groups.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_server_groups.py @@ -60,3 +60,61 @@ class NovaServerGroupsTestCase(test.ScenarioTestCase): kwargs=create_args) scenario._create_server_group.assert_called_with(**create_args) scenario._list_server_groups.assert_called_with(all_projects) + + @ddt.data( + {}, + {"create_args": {"policies": ["fake_policy"]}} + ) + @ddt.unpack + def test_create_and_get_server_group_positive(self, create_args=None): + scenario = server_groups.CreateAndGetServerGroup(self.context) + gen_name = mock.MagicMock() + scenario.generate_random_name = gen_name + fake_server_group = mock.MagicMock() + fake_server_group_info = mock.MagicMock() + fake_server_group.id = 123 + fake_server_group_info.id = 123 + scenario._create_server_group = mock.MagicMock() + scenario._get_server_group = mock.MagicMock() + create_args = create_args or {} + # Positive case + scenario._create_server_group.return_value = fake_server_group + scenario._get_server_group.return_value = fake_server_group_info + scenario.run(create_args) + scenario._create_server_group.assert_called_once_with(**create_args) + scenario._get_server_group.assert_called_once_with( + fake_server_group.id) + + @ddt.data( + {}, + {"create_args": {"policies": ["fake_policy"]}} + ) + @ddt.unpack + def test_create_and_get_server_group_negative(self, create_args=None): + scenario = server_groups.CreateAndGetServerGroup(self.context) + gen_name = mock.MagicMock() + scenario.generate_random_name = gen_name + fake_server_group = mock.MagicMock() + fake_server_group_info = mock.MagicMock() + fake_server_group.id = 123 + fake_server_group_info.id = 123 + scenario._create_server_group = mock.MagicMock() + scenario._get_server_group = mock.MagicMock() + create_args = create_args or {} + + # Negative case1: server group isn't created + scenario._create_server_group.return_value = None + self.assertRaises(rally_exceptions.RallyAssertionError, + scenario.run, + create_args) + scenario._create_server_group.assert_called_with(**create_args) + + # Negative case2: server group to get information not the created one + fake_server_group_info.id = 456 + scenario._create_server_group.return_value = fake_server_group + self.assertRaises(rally_exceptions.RallyAssertionError, + scenario.run, + create_args) + scenario._create_server_group.assert_called_with(**create_args) + scenario._get_server_group.assert_called_with( + fake_server_group.id) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 495c102b36..5485794046 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -806,6 +806,18 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.create_keypair") + def test__get_server_group(self): + nova_scenario = utils.NovaScenario() + fakeid = 12345 + result = nova_scenario._get_server_group(fakeid) + self.assertEqual( + self.clients("nova").server_groups.get.return_value, + result) + self.clients("nova").server_groups.get.assert_called_once_with( + fakeid) + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.get_server_group") + def test__create_server_group(self): nova_scenario = utils.NovaScenario() result = nova_scenario._create_server_group(fakeargs="fakeargs")