Merge "image_pull_policy does not work in glance driver"
This commit is contained in:
commit
2cd7ebc943
@ -60,27 +60,23 @@ class GlanceDriver(driver.ContainerImageDriver):
|
|||||||
# once metadata is stored in db then handle tags
|
# once metadata is stored in db then handle tags
|
||||||
image_loaded = False
|
image_loaded = False
|
||||||
image = self._search_image_on_host(context, repo)
|
image = self._search_image_on_host(context, repo)
|
||||||
if image:
|
|
||||||
image_path = image['path']
|
|
||||||
image_checksum = image['checksum']
|
|
||||||
md5sum = hashlib.md5()
|
|
||||||
with open(image_path, 'rb') as fd:
|
|
||||||
while True:
|
|
||||||
# read 10MB of data each time
|
|
||||||
data = fd.read(10 * 1024 * 1024)
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
md5sum.update(data)
|
|
||||||
md5sum = md5sum.hexdigest()
|
|
||||||
if md5sum == image_checksum:
|
|
||||||
image_loaded = True
|
|
||||||
return image, image_loaded
|
|
||||||
|
|
||||||
if not common_utils.should_pull_image(image_pull_policy, bool(image)):
|
if not common_utils.should_pull_image(image_pull_policy, bool(image)):
|
||||||
if image:
|
if image:
|
||||||
LOG.debug('Image %s present locally', repo)
|
image_path = image['path']
|
||||||
image_loaded = True
|
image_checksum = image['checksum']
|
||||||
return image, image_loaded
|
md5sum = hashlib.md5()
|
||||||
|
with open(image_path, 'rb') as fd:
|
||||||
|
while True:
|
||||||
|
# read 10MB of data each time
|
||||||
|
data = fd.read(10 * 1024 * 1024)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
md5sum.update(data)
|
||||||
|
md5sum = md5sum.hexdigest()
|
||||||
|
if md5sum == image_checksum:
|
||||||
|
image_loaded = True
|
||||||
|
return image, image_loaded
|
||||||
else:
|
else:
|
||||||
message = _('Image %s not present with pull policy of Never'
|
message = _('Image %s not present with pull policy of Never'
|
||||||
) % repo
|
) % repo
|
||||||
|
@ -52,12 +52,13 @@ class TestDriver(base.BaseTestCase):
|
|||||||
def test_pull_image_should_pull_no_image_present_locally(
|
def test_pull_image_should_pull_no_image_present_locally(
|
||||||
self, mock_should_pull_image, mock_search):
|
self, mock_should_pull_image, mock_search):
|
||||||
mock_should_pull_image.return_value = False
|
mock_should_pull_image.return_value = False
|
||||||
|
checksum = 'd41d8cd98f00b204e9800998ecf8427e'
|
||||||
mock_search.return_value = {'image': 'nginx', 'path': 'xyz',
|
mock_search.return_value = {'image': 'nginx', 'path': 'xyz',
|
||||||
'checksum': 'xxx'}
|
'checksum': checksum}
|
||||||
mock_open_file = mock.mock_open()
|
mock_open_file = mock.mock_open()
|
||||||
with mock.patch('zun.image.glance.driver.open', mock_open_file):
|
with mock.patch('zun.image.glance.driver.open', mock_open_file):
|
||||||
self.assertEqual(({'image': 'nginx', 'path': 'xyz',
|
self.assertEqual(({'image': 'nginx', 'path': 'xyz',
|
||||||
'checksum': 'xxx'}, True),
|
'checksum': checksum}, True),
|
||||||
self.driver.pull_image(None, 'nonexisting',
|
self.driver.pull_image(None, 'nonexisting',
|
||||||
'tag', 'never'))
|
'tag', 'never'))
|
||||||
mock_open_file.assert_any_call('xyz', 'rb')
|
mock_open_file.assert_any_call('xyz', 'rb')
|
||||||
@ -72,12 +73,9 @@ class TestDriver(base.BaseTestCase):
|
|||||||
mock_should_pull_image.return_value = True
|
mock_should_pull_image.return_value = True
|
||||||
mock_search.return_value = {'image': 'nginx', 'path': 'xyz',
|
mock_search.return_value = {'image': 'nginx', 'path': 'xyz',
|
||||||
'checksum': 'xxx'}
|
'checksum': 'xxx'}
|
||||||
mock_open_file = mock.mock_open()
|
mock_find_image.side_effect = Exception
|
||||||
with mock.patch('zun.image.glance.driver.open', mock_open_file):
|
self.assertRaises(exception.ZunException, self.driver.pull_image,
|
||||||
mock_find_image.side_effect = Exception
|
None, 'nonexisting', 'tag', 'always')
|
||||||
self.assertRaises(exception.ZunException, self.driver.pull_image,
|
|
||||||
None, 'nonexisting', 'tag', 'always')
|
|
||||||
mock_open_file.assert_any_call('xyz', 'rb')
|
|
||||||
|
|
||||||
@mock.patch.object(driver.GlanceDriver,
|
@mock.patch.object(driver.GlanceDriver,
|
||||||
'_search_image_on_host')
|
'_search_image_on_host')
|
||||||
@ -98,7 +96,6 @@ class TestDriver(base.BaseTestCase):
|
|||||||
mock_open_file = mock.mock_open()
|
mock_open_file = mock.mock_open()
|
||||||
with mock.patch('zun.image.glance.driver.open', mock_open_file):
|
with mock.patch('zun.image.glance.driver.open', mock_open_file):
|
||||||
ret = self.driver.pull_image(None, 'image', 'latest', 'always')
|
ret = self.driver.pull_image(None, 'image', 'latest', 'always')
|
||||||
mock_open_file.assert_any_call('xyz', 'rb')
|
|
||||||
mock_open_file.assert_any_call(out_path, 'wb')
|
mock_open_file.assert_any_call(out_path, 'wb')
|
||||||
self.assertTrue(mock_search_on_host.called)
|
self.assertTrue(mock_search_on_host.called)
|
||||||
self.assertTrue(mock_should_pull_image.called)
|
self.assertTrue(mock_should_pull_image.called)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user