Merge "Fix for bug which leaves logs in swift after App deletion"

This commit is contained in:
Jenkins 2015-06-30 15:41:15 +00:00 committed by Gerrit Code Review
commit b1fe4a1a3e
2 changed files with 51 additions and 13 deletions

View File

@ -112,6 +112,7 @@ class Handler(object):
def _delete_app_artifacts_from_swift(self, ctxt, t_logger,
logs_resource_id, assem):
# Delete image file from swift
if assem.image_id:
img = objects.registry.Image.get_by_id(ctxt, assem.image_id)
if img.docker_image_name:
img_filename = img.docker_image_name.split('-', 1)[1]

View File

@ -561,6 +561,43 @@ class HandlerTest(base.BaseTestCase):
id = handler._find_id_if_stack_exists(assem)
self.assertEqual(id, '123')
@mock.patch('solum.common.solum_swiftclient.SwiftClient.delete_object')
@mock.patch('solum.objects.registry')
@mock.patch('solum.deployer.handlers.heat.tlog')
@mock.patch('solum.api.handlers.userlog_handler.UserlogHandler')
def test_delete_app_artifacts_from_swift(self, mock_log_handler, m_log,
mock_registry, mock_swift_delete):
fake_assembly = fakes.FakeAssembly()
fake_image = fakes.FakeImage()
mock_registry.Image.get_by_id.return_value = fake_image
log_handler = mock_log_handler.return_value
handler = heat_handler.Handler()
handler._delete_app_artifacts_from_swift(self.ctx, mock_log_handler,
'fake_log_id', fake_assembly)
mock_registry.Image.get_by_id.assert_called_once_with(
mock.ANY, fake_assembly.image_id)
docker_image_name = fake_image.docker_image_name
img_filename = docker_image_name.split('-', 1)[1]
mock_swift_delete.assert_called_once_with('solum_du', img_filename)
log_handler.delete.assert_called_once_with('fake_log_id')
@mock.patch('solum.common.solum_swiftclient.SwiftClient.delete_object')
@mock.patch('solum.objects.registry')
@mock.patch('solum.deployer.handlers.heat.tlog')
@mock.patch('solum.api.handlers.userlog_handler.UserlogHandler')
def test_delete_app_artifacts_from_swift_no_image(self, mock_log_handler,
m_log, mock_registry,
mock_swift_delete):
fake_assembly = fakes.FakeAssembly()
fake_assembly.image_id = None
log_handler = mock_log_handler.return_value
handler = heat_handler.Handler()
handler._delete_app_artifacts_from_swift(self.ctx, mock_log_handler,
'fake_log_id', fake_assembly)
self.assertFalse(mock_registry.Image.get_by_id.called)
self.assertFalse(mock_swift_delete.called)
log_handler.delete.assert_called_once_with('fake_log_id')
@mock.patch('solum.common.solum_swiftclient.SwiftClient.delete_object')
@mock.patch('solum.api.handlers.userlog_handler.UserlogHandler')
@mock.patch('solum.deployer.handlers.heat.tlog')