Merge "Added cleanup for sahara objects"

This commit is contained in:
Jenkins 2014-07-22 14:17:01 +00:00 committed by Gerrit Code Review
commit 4497b2f5a4
4 changed files with 94 additions and 3 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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):