From e24740f5ab8409c31a2fc3ee1a687cf5f46b0b86 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Thu, 29 Sep 2016 00:27:51 -0400 Subject: [PATCH] Add NovaAggregates.create_and_delete_aggregate This scenario first creates a aggregate and then delete it. Change-Id: I35d34f9ea899c234cb79d2ba484c957a64e7fddd --- rally-jobs/nova.yaml | 16 ++++++++++++ .../openstack/scenarios/nova/aggregates.py | 16 ++++++++++++ .../plugins/openstack/scenarios/nova/utils.py | 9 +++++++ .../nova/create-and-delete-aggregate.json | 25 +++++++++++++++++++ .../nova/create-and-delete-aggregate.yaml | 16 ++++++++++++ .../scenarios/nova/test_aggregates.py | 9 +++++++ .../openstack/scenarios/nova/test_utils.py | 11 ++++++++ 7 files changed, 102 insertions(+) create mode 100644 samples/tasks/scenarios/nova/create-and-delete-aggregate.json create mode 100644 samples/tasks/scenarios/nova/create-and-delete-aggregate.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml index f05ce4c2..01395628 100755 --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -1172,3 +1172,19 @@ sla: failure_rate: max: 0 + + NovaAggregates.create_and_delete_aggregate: + - + 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/rally/plugins/openstack/scenarios/nova/aggregates.py b/rally/plugins/openstack/scenarios/nova/aggregates.py index 0630882d..946415fe 100644 --- a/rally/plugins/openstack/scenarios/nova/aggregates.py +++ b/rally/plugins/openstack/scenarios/nova/aggregates.py @@ -48,3 +48,19 @@ class CreateAndListAggregates(utils.NovaScenario): """ self._create_aggregate(availability_zone) self._list_aggregates() + + +@validation.required_services(consts.Service.NOVA) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["nova"]}, + name="NovaAggregates.create_and_delete_aggregate") +class CreateAndDeleteAggregate(utils.NovaScenario): + """Scenario for create and delete aggregate.""" + + def run(self, availability_zone): + """Create an aggregate and then delete it. + + This scenario first creates an aggregate and then delete it. + """ + aggregate = self._create_aggregate(availability_zone) + self._delete_aggregate(aggregate) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index fa697e5a..f2167478 100755 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -1006,3 +1006,12 @@ class NovaScenario(scenario.OpenStackScenario): aggregate_name = self.generate_random_name() return self.admin_clients("nova").aggregates.create(aggregate_name, availability_zone) + + @atomic.action_timer("nova.delete_aggregate") + def _delete_aggregate(self, aggregate): + """Delete the specified aggregate. + + :param aggregate: The aggregate to delete + :returns: An instance of novaclient.base.TupleWithMeta + """ + return self.admin_clients("nova").aggregates.delete(aggregate) diff --git a/samples/tasks/scenarios/nova/create-and-delete-aggregate.json b/samples/tasks/scenarios/nova/create-and-delete-aggregate.json new file mode 100644 index 00000000..b02d58f9 --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-delete-aggregate.json @@ -0,0 +1,25 @@ +{ + "NovaAggregates.create_and_delete_aggregate": [ + { + "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-delete-aggregate.yaml b/samples/tasks/scenarios/nova/create-and-delete-aggregate.yaml new file mode 100644 index 00000000..e442639b --- /dev/null +++ b/samples/tasks/scenarios/nova/create-and-delete-aggregate.yaml @@ -0,0 +1,16 @@ +--- + NovaAggregates.create_and_delete_aggregate: + - + 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/scenarios/nova/test_aggregates.py b/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py index 870fd83f..0bc28420 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_aggregates.py @@ -34,3 +34,12 @@ class NovaAggregatesTestCase(test.TestCase): scenario.run(availability_zone="nova") scenario._create_aggregate.assert_called_once_with("nova") scenario._list_aggregates.assert_called_once_with() + + def test_create_and_delete_aggregate(self): + scenario = aggregates.CreateAndDeleteAggregate() + scenario._create_aggregate = mock.Mock() + scenario._delete_aggregate = mock.Mock() + scenario.run(availability_zone="nova") + scenario._create_aggregate.assert_called_once_with("nova") + aggregate = scenario._create_aggregate.return_value + scenario._delete_aggregate.assert_called_once_with(aggregate) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 641ea745..4935a6d0 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -1044,3 +1044,14 @@ class NovaScenarioTestCase(test.ScenarioTestCase): random_name, "nova") self._test_atomic_action_timer(nova_scenario.atomic_actions(), "nova.create_aggregate") + + def test_delete_aggregate(self): + nova_scenario = utils.NovaScenario(context=self.context) + result = nova_scenario._delete_aggregate("fake_aggregate") + self.assertEqual( + self.admin_clients("nova").aggregates.delete.return_value, + result) + self.admin_clients("nova").aggregates.delete.assert_called_once_with( + "fake_aggregate") + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.delete_aggregate")