def test__clean_up_boot_iso_for_instance_exc(self, swift_mock, boot_object_name_mock, log_mock): swift_obj_mock = swift_mock.return_value exc = exception.SwiftObjectNotFoundError('error') swift_obj_mock.delete_object.side_effect = exc CONF.ilo.swift_ilo_container = 'ilo-cont' boot_object_name_mock.return_value = 'boot-object' i_info = self.node.instance_info i_info['ilo_boot_iso'] = 'swift:bootiso' self.node.instance_info = i_info self.node.save() ilo_boot._clean_up_boot_iso_for_instance(self.node) swift_obj_mock.delete_object.assert_called_once_with('ilo-cont', 'boot-object') self.assertTrue(log_mock.called)
def test_cleanup_vmedia_boot_exc_resource_not_found( self, get_name_mock, swift_api_mock, eject_mock, log_mock): exc = exception.SwiftObjectNotFoundError('error') swift_obj_mock = swift_api_mock.return_value swift_obj_mock.delete_object.side_effect = exc CONF.ilo.swift_ilo_container = 'ilo_cont' get_name_mock.return_value = 'image-node-uuid' with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.cleanup_vmedia_boot(task) swift_obj_mock.delete_object.assert_called_once_with( 'ilo_cont', 'image-node-uuid') self.assertTrue(log_mock.called) eject_mock.assert_called_once_with(task)
def test_remove_image_from_swift_suppresses_notfound_exc( self, swift_api_mock, LOG_mock): # | GIVEN | self.config(swift_ilo_container='ilo_container', group='ilo') container = CONF.ilo.swift_ilo_container swift_obj_mock = swift_api_mock.return_value object_name = 'object_name' raised_exc = exception.SwiftObjectNotFoundError( operation='delete_object', object=object_name, container=container) swift_obj_mock.delete_object.side_effect = raised_exc # | WHEN | ilo_common.remove_image_from_swift(object_name) # | THEN | LOG_mock.warning.assert_called_once_with( mock.ANY, {'associated_with_msg': "", 'err': raised_exc})
def delete_object(self, container, obj): """Deletes the given Swift object. :param container: The name of the container in which Swift object is placed. :param obj: The name of the object in Swift to be deleted. :raises: SwiftObjectNotFoundError, if object is not found in Swift. :raises: SwiftOperationError, if operation with Swift fails. """ try: self.connection.delete_object(container, obj) except swift_exceptions.ClientException as e: operation = _("delete object") if e.http_status == http_client.NOT_FOUND: raise exception.SwiftObjectNotFoundError(obj=obj, container=container, operation=operation) raise exception.SwiftOperationError(operation=operation, error=e)