Skip image validation if failed

This allows image validation to fail and continue lauching the
container. This is because image validation might depend on
external image registry (i.e. DockerHub) which is not always stable.

Change-Id: I3c65cdef17d8279233bfbb74a38c9db79b01a2de
Closes-Bug: #1827968
This commit is contained in:
Hongbin Lu 2019-05-07 02:50:45 +00:00
parent b00bba2483
commit 07e5f01afa
2 changed files with 10 additions and 11 deletions

View File

@ -86,10 +86,8 @@ class API(object):
"is invalid.")
% new_container.image)
except Exception as e:
new_container.status = consts.ERROR
new_container.status_reason = str(e)
new_container.save(context)
raise
LOG.warning("Skip validation since image search failed with "
"unexpected exception: %s", str(e))
self._record_action_start(context, new_container,
container_actions.CREATE)

View File

@ -96,12 +96,15 @@ class TestAPI(base.TestCase):
self.assertTrue(mock_save.called)
self.assertEqual(consts.ERROR, container.status)
@mock.patch('zun.compute.rpcapi.API._cast')
@mock.patch.object(objects.ContainerAction, 'action_start')
@mock.patch('zun.compute.rpcapi.API.image_search')
@mock.patch('zun.compute.api.API._schedule_container')
@mock.patch.object(objects.Container, 'save')
def test_searching_image_exception(self, mock_save,
mock_schedule_container,
mock_image_search):
mock_image_search,
mock_start, mock_cast):
CONF.set_override('enable_image_validation', True, group="api")
container = self.container
container.status = consts.CREATING
@ -110,14 +113,12 @@ class TestAPI(base.TestCase):
'limits': {}}
mock_image_search.side_effect = exception.ZunException
self.assertRaises(exception.ZunException,
self.compute_api.container_create,
self.context, container,
None, None, None, False)
self.compute_api.container_create(
self.context, container, None, None, None, False)
self.assertTrue(mock_schedule_container.called)
self.assertTrue(mock_image_search.called)
self.assertTrue(mock_save.called)
self.assertEqual(consts.ERROR, container.status)
self.assertFalse(mock_save.called)
self.assertEqual(consts.CREATING, container.status)
@mock.patch('zun.compute.rpcapi.API._cast')
@mock.patch('zun.api.servicegroup.ServiceGroup.service_is_up')