Merge "Fix for bug which leaves logs in swift after App deletion"
This commit is contained in:
commit
b1fe4a1a3e
@ -112,19 +112,20 @@ class Handler(object):
|
||||
def _delete_app_artifacts_from_swift(self, ctxt, t_logger,
|
||||
logs_resource_id, assem):
|
||||
# Delete image file from swift
|
||||
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]
|
||||
try:
|
||||
swift = solum_swiftclient.SwiftClient(ctxt)
|
||||
swift.delete_object('solum_du', img_filename)
|
||||
except swiftexp.ClientException:
|
||||
msg = "Unable to delete DU image from swift."
|
||||
t_logger.log(logging.ERROR, msg)
|
||||
LOG.debug(msg)
|
||||
t_logger.upload()
|
||||
return
|
||||
img.destroy(ctxt)
|
||||
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]
|
||||
try:
|
||||
swift = solum_swiftclient.SwiftClient(ctxt)
|
||||
swift.delete_object('solum_du', img_filename)
|
||||
except swiftexp.ClientException:
|
||||
msg = "Unable to delete DU image from swift."
|
||||
t_logger.log(logging.ERROR, msg)
|
||||
LOG.debug(msg)
|
||||
t_logger.upload()
|
||||
return
|
||||
img.destroy(ctxt)
|
||||
|
||||
# Delete logs
|
||||
try:
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user