class ArvKeepdockerTestCase(unittest.TestCase, tutil.VersionChecker):
- def run_arv_keepdocker(self, args, err):
+ def run_arv_keepdocker(self, args, err, **kwargs):
sys.argv = ['arv-keepdocker'] + args
log_handler = logging.StreamHandler(err)
arv_keepdocker.logger.addHandler(log_handler)
try:
- return arv_keepdocker.main()
+ return arv_keepdocker.main(**kwargs)
finally:
arv_keepdocker.logger.removeHandler(log_handler)
self.run_arv_keepdocker(['--version'], sys.stderr)
self.assertVersionOutput(out, err)
+ @mock.patch('arvados.commands.keepdocker.list_images_in_arv',
+ return_value=[])
@mock.patch('arvados.commands.keepdocker.find_image_hashes',
return_value=['abc123'])
@mock.patch('arvados.commands.keepdocker.find_one_image_hash',
return_value='abc123')
- def test_image_format_compatibility(self, _1, _2):
+ def test_image_format_compatibility(self, _1, _2, _3):
old_id = hashlib.sha256(b'old').hexdigest()
new_id = 'sha256:'+hashlib.sha256(b'new').hexdigest()
for supported, img_id, expect_ok in [
self.run_arv_keepdocker(['repo:tag'], sys.stderr)
find_image_mock.assert_called_with('repo', 'tag')
+ def test_image_given_as_registry_repo_colon_tag(self):
with self.assertRaises(StopTest), \
mock.patch('arvados.commands.keepdocker.find_one_image_hash',
side_effect=StopTest) as find_image_mock:
self.run_arv_keepdocker(['myreg.example:8888/repo/img:tag'], sys.stderr)
find_image_mock.assert_called_with('myreg.example:8888/repo/img', 'tag')
+ with self.assertRaises(StopTest), \
+ mock.patch('arvados.commands.keepdocker.find_one_image_hash',
+ side_effect=StopTest) as find_image_mock:
+ self.run_arv_keepdocker(['registry.hub.docker.com:443/library/debian:bullseye-slim'], sys.stderr)
+ find_image_mock.assert_called_with('registry.hub.docker.com/library/debian', 'bullseye-slim')
+
def test_image_has_colons(self):
with self.assertRaises(StopTest), \
mock.patch('arvados.commands.keepdocker.find_one_image_hash',
self.run_arv_keepdocker(['[::1]/repo/img'], sys.stderr)
find_image_mock.assert_called_with('[::1]/repo/img', 'latest')
+ with self.assertRaises(StopTest), \
+ mock.patch('arvados.commands.keepdocker.find_one_image_hash',
+ side_effect=StopTest) as find_image_mock:
+ self.run_arv_keepdocker(['[::1]:8888/repo/img:tag'], sys.stderr)
+ find_image_mock.assert_called_with('[::1]:8888/repo/img', 'tag')
+
+ def test_list_images_with_host_and_port(self):
+ api = arvados.api('v1')
+ taglink = api.links().create(body={'link': {
+ 'link_class': 'docker_image_repo+tag',
+ 'name': 'registry.example:1234/repo:latest',
+ 'head_uuid': 'zzzzz-4zz18-1v45jub259sjjgb',
+ }}).execute()
+ try:
+ out = tutil.StringIO()
+ with self.assertRaises(SystemExit):
+ self.run_arv_keepdocker([], sys.stderr, stdout=out)
+ self.assertRegex(out.getvalue(), '\nregistry.example:1234/repo +latest ')
+ finally:
+ api.links().delete(uuid=taglink['uuid']).execute()
+
+ @mock.patch('arvados.commands.keepdocker.list_images_in_arv',
+ return_value=[])
@mock.patch('arvados.commands.keepdocker.find_image_hashes',
return_value=['abc123'])
@mock.patch('arvados.commands.keepdocker.find_one_image_hash',
return_value='abc123')
- def test_collection_property_update(self, _1, _2):
+ def test_collection_property_update(self, _1, _2, _3):
image_id = 'sha256:'+hashlib.sha256(b'image').hexdigest()
fakeDD = arvados.api('v1')._rootDesc
fakeDD['dockerImageFormats'] = ['v2']