From 9c165148fd044e8a3c6be84902b5497665e512b7 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Tue, 13 Sep 2016 22:55:41 -0400 Subject: [PATCH] Add NovaAggregates.create_and_list_aggregates This scenario creates a aggregate and then lists all aggregates. Change-Id: If0a9aa864d5e912d72e197f5042b9c050768ddfe --- rally-jobs/nova.yaml | 16 ++++++++++++ rally/plugins/openstack/cleanup/resources.py | 8 ++++++ .../openstack/scenarios/nova/aggregates.py | 17 +++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 11 ++++++++ .../nova/create-and-list-aggregates.json | 25 +++++++++++++++++++ .../nova/create-and-list-aggregates.yaml | 16 ++++++++++++ .../openstack/cleanup/test_resources.py | 16 ++++++++++++ .../scenarios/nova/test_aggregates.py | 8 ++++++ .../openstack/scenarios/nova/test_utils.py | 14 +++++++++++ 9 files changed, 131 insertions(+) create mode 100644 samples/tasks/scenarios/nova/create-and-list-aggregates.json create mode 100644 samples/tasks/scenarios/nova/create-and-list-aggregates.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index 7109ce61..126bf53d 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -1136,3 +1136,19 @@ sla: failure_rate: max: 0 + + NovaAggregates.create_and_list_aggregates: + - + args: + availability_zone: "nova" + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/rally/plugins/openstack/cleanup/resources.py b/rally/plugins/openstack/cleanup/resources.py index 7983ed3b..8a95fefb 100644 --- a/rally/plugins/openstack/cleanup/resources.py +++ b/rally/plugins/openstack/cleanup/resources.py @@ -262,6 +262,14 @@ class NovaNetworks(SynchronizedDeletion, base.ResourceManager): if utils.name_matches_object(net.label, *classes)] +@base.resource("nova", "aggregates", order=next(_nova_order), + admin_required=True, perform_for_admin_only=True) +class NovaAggregate(SynchronizedDeletion, base.ResourceManager): + def list(self): + return [r for r in self._manager().list() + if utils.name_matches_object(r.name, nova_utils.NovaScenario)] + + # EC2 _ec2_order = get_order(250) diff --git a/rally/plugins/openstack/scenarios/nova/aggregates.py b/rally/plugins/openstack/scenarios/nova/aggregates.py index bd01b779..0630882d 100644 --- a/rally/plugins/openstack/scenarios/nova/aggregates.py +++ b/rally/plugins/openstack/scenarios/nova/aggregates.py @@ -31,3 +31,20 @@ class NovaAggregates(utils.NovaScenario): Measure the "nova aggregate-list" command performance. """ self._list_aggregates() + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["nova"]}, + name="NovaAggregates.create_and_list_aggregates") +class CreateAndListAggregates(utils.NovaScenario): + """scenario for create and list aggregate.""" + + def run(self, availability_zone): + """Create a aggregate and then list all aggregates. + + This scenario creates a aggregate and then lists all aggregates. + :param availability_zone: The availability zone of the aggregate + """ + self._create_aggregate(availability_zone) + self._list_aggregates() diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index a492b981..fa697e5a 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -995,3 +995,14 @@ class NovaScenario(scenario.OpenStackScenario): :param flavor_id: The flavor ID to get """ return self.admin_clients("nova").flavors.get(flavor_id) + + @atomic.action_timer("nova.create_aggregate") + def _create_aggregate(self, availability_zone): + """Create a new aggregate. + + :param availability_zone: The availability zone of the aggregate + :returns: The created aggregate + """ + aggregate_name = self.generate_random_name() + return self.admin_clients("nova").aggregates.create(aggregate_name, + availability_zone) diff --git a/samples/tasks/scenarios/nova/create-and-list-aggregates.json b/samples/tasks/scenarios/nova/create-and-list-aggregates.json new file mode 100644 index 00000000..7e976223 --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-list-aggregates.json @@ -0,0 +1,25 @@ +{ + "NovaAggregates.create_and_list_aggregates": [ + { + "args": { + "availability_zone": "nova" + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/nova/create-and-list-aggregates.yaml b/samples/tasks/scenarios/nova/create-and-list-aggregates.yaml new file mode 100644 index 00000000..6ccd85ec --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-list-aggregates.yaml @@ -0,0 +1,16 @@ +--- + NovaAggregates.create_and_list_aggregates: + - + args: + availability_zone: "nova" + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/cleanup/test_resources.py b/tests/unit/plugins/openstack/cleanup/test_resources.py index 3572231f..f6cb5409 100644 --- a/tests/unit/plugins/openstack/cleanup/test_resources.py +++ b/tests/unit/plugins/openstack/cleanup/test_resources.py @@ -173,6 +173,22 @@ class NovaFlavorsTestCase(test.TestCase): self.assertRaises(TypeError, flavor.is_deleted) +class NovaAggregatesTestCase(test.TestCase): + + @mock.patch("%s.base.ResourceManager._manager" % BASE) + @mock.patch("rally.common.utils.name_matches_object") + def test_list(self, mock_name_matches_object, + mock_resource_manager__manager): + aggregates = [mock.MagicMock(name="rally_foo1"), + mock.MagicMock(name="rally_foo2"), + mock.MagicMock(name="foo3")] + mock_name_matches_object.side_effect = [False, True, True] + mock_resource_manager__manager().list.return_value = aggregates + self.assertEqual(aggregates[1:], resources.NovaAggregate().list()) + mock_name_matches_object.assert_has_calls( + [mock.call(r.name, nutils.NovaScenario) for r in aggregates]) + + class NovaSecurityGroupTestCase(test.TestCase): @mock.patch("%s.base.ResourceManager._manager" % BASE) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py b/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py index 5b2e4ca7..870fd83f 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py @@ -26,3 +26,11 @@ class NovaAggregatesTestCase(test.TestCase): scenario._list_aggregates = mock.Mock() scenario.list_aggregates() scenario._list_aggregates.assert_called_once_with() + + def test_create_and_list_aggregates(self): + scenario = aggregates.CreateAndListAggregates() + scenario._create_aggregate = mock.Mock() + scenario._list_aggregates = mock.Mock() + scenario.run(availability_zone="nova") + scenario._create_aggregate.assert_called_once_with("nova") + scenario._list_aggregates.assert_called_once_with() diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index c6c1e049..641ea745 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -1030,3 +1030,17 @@ class NovaScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.update_server") + + def test_create_aggregate(self): + nova_scenario = utils.NovaScenario(context=self.context) + random_name = "random_name" + nova_scenario.generate_random_name = mock.Mock( + return_value=random_name) + result = nova_scenario._create_aggregate("nova") + self.assertEqual( + self.admin_clients("nova").aggregates.create.return_value, + result) + self.admin_clients("nova").aggregates.create.assert_called_once_with( + random_name, "nova") + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.create_aggregate")