From 06b6e85210c8a3a23fa16b8e8972189ea5e94bb5 Mon Sep 17 00:00:00 2001 From: Nikita Konovalov Date: Fri, 18 Jul 2014 12:28:33 +0400 Subject: [PATCH] Added cleanup for sahara objects This change is required befor adding any sahara benchmarks. Change-Id: I5f35cb17cfbacdee80afc7e5c153e6acea6451bb --- rally/benchmark/context/cleanup/cleanup.py | 5 +- rally/benchmark/context/cleanup/utils.py | 52 +++++++++++++++++++ tests/benchmark/context/cleanup/test_utils.py | 14 +++++ tests/fakes.py | 26 +++++++++- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/rally/benchmark/context/cleanup/cleanup.py b/rally/benchmark/context/cleanup/cleanup.py index 521cb92d87..06e683ed67 100644 --- a/rally/benchmark/context/cleanup/cleanup.py +++ b/rally/benchmark/context/cleanup/cleanup.py @@ -42,7 +42,7 @@ class ResourceCleaner(base.Context): "items": { "type": "string", "enum": ["nova", "glance", "cinder", - "quotas", "neutron", "ceilometer", "heat"] + "quotas", "neutron", "ceilometer", "heat", "sahara"] }, "uniqueItems": True } @@ -69,7 +69,8 @@ class ResourceCleaner(base.Context): tenant_id), "ceilometer": (utils.delete_ceilometer_resources, clients.ceilometer, tenant_id), - "heat": (utils.delete_heat_resources, clients.heat) + "heat": (utils.delete_heat_resources, clients.heat), + "sahara": (utils.delete_sahara_resources, clients.sahara) } for service_name in self.config: diff --git a/rally/benchmark/context/cleanup/utils.py b/rally/benchmark/context/cleanup/utils.py index b9a22d4445..9fb86be986 100644 --- a/rally/benchmark/context/cleanup/utils.py +++ b/rally/benchmark/context/cleanup/utils.py @@ -162,6 +162,58 @@ def delete_alarms(ceilometer, project_uuid): ceilometer.alarms.delete(alarm.alarm_id) +def delete_sahara_resources(sahara): + # Delete EDP related objects + delete_job_executions(sahara) + delete_jobs(sahara) + delete_job_binaries(sahara) + delete_data_sources(sahara) + + # Delete cluster related objects + delete_clusters(sahara) + delete_cluster_templates(sahara) + delete_node_group_templates(sahara) + + +def delete_job_executions(sahara): + for je in sahara.job_executions.list(): + sahara.job_executions.delete(je.id) + + _wait_for_empty_list(sahara.job_executions) + + +def delete_jobs(sahara): + for job in sahara.jobs.list(): + sahara.jobs.delete(job.id) + + +def delete_job_binaries(sahara): + for jb in sahara.job_binaries.list(): + sahara.job_binaries.delete(jb.id) + + +def delete_data_sources(sahara): + for ds in sahara.data_sources.list(): + sahara.data_sources.delete(ds.id) + + +def delete_clusters(sahara): + for cluster in sahara.clusters.list(): + sahara.clusters.delete(cluster.id) + + _wait_for_empty_list(sahara.clusters) + + +def delete_cluster_templates(sahara): + for ct in sahara.cluster_templates.list(): + sahara.cluster_templates.delete(ct.id) + + +def delete_node_group_templates(sahara): + for ngt in sahara.node_group_templates.list(): + sahara.node_group_templates.delete(ngt.id) + + def _wait_for_empty_list(mgr, timeout=10, check_interval=1): _wait_for_list_size(mgr, sizes=[0], timeout=timeout, check_interval=check_interval) diff --git a/tests/benchmark/context/cleanup/test_utils.py b/tests/benchmark/context/cleanup/test_utils.py index ba0be891d2..39967ecaba 100644 --- a/tests/benchmark/context/cleanup/test_utils.py +++ b/tests/benchmark/context/cleanup/test_utils.py @@ -49,3 +49,17 @@ class CleanupUtilsTestCase(test.TestCase): network1["network"]["tenant_id"]) self.assertEqual(total(neutron), 0) + + def test_delete_sahara_resources(self): + + sahara = fakes.FakeClients().sahara() + utils.delete_sahara_resources(sahara) + + sahara.job_executions.delete.assert_called_once_with(42) + sahara.jobs.delete.assert_called_once_with(42) + sahara.job_binaries.delete.assert_called_once_with(42) + sahara.data_sources.delete.assert_called_once_with(42) + + sahara.clusters.delete.assert_called_once_with(42) + sahara.cluster_templates.delete.assert_called_once_with(42) + sahara.node_group_templates.delete.assert_called_once_with(42) diff --git a/tests/fakes.py b/tests/fakes.py index 6f6666bbfa..79329bf98c 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -810,7 +810,31 @@ class FakeIronicClient(object): class FakeSaharaClient(object): def __init__(self): - pass + self.job_executions = mock.MagicMock() + self.jobs = mock.MagicMock() + self.job_binaries = mock.MagicMock() + self.data_sources = mock.MagicMock() + + self.clusters = mock.MagicMock() + self.cluster_templates = mock.MagicMock() + self.node_group_templates = mock.MagicMock() + + self.setup_list_methods() + + def setup_list_methods(self): + mock_with_id = mock.MagicMock() + mock_with_id.id = 42 + + # First call of list returns a list with one object, the next should + # empty after delete. + self.job_executions.list.side_effect = [[mock_with_id], []] + self.jobs.list.side_effect = [[mock_with_id], []] + self.job_binaries.list.side_effect = [[mock_with_id], []] + self.data_sources.list.side_effect = [[mock_with_id], []] + + self.clusters.list.side_effect = [[mock_with_id], []] + self.cluster_templates.list.side_effect = [[mock_with_id], []] + self.node_group_templates.list.side_effect = [[mock_with_id], []] class FakeClients(object):