Merge branch '17508-arvkeepdocker-fix'
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 1 Apr 2021 14:32:54 +0000 (11:32 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 1 Apr 2021 14:32:54 +0000 (11:32 -0300)
Closes #17508

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

sdk/python/arvados/commands/keepdocker.py
sdk/python/tests/test_arv_keepdocker.py

index 6673888ab5e3f98a39c46df8baf673c5a610df76..8eb9dd75a3ee783200831bc0d9da816863cd1568 100644 (file)
@@ -505,7 +505,11 @@ def main(arguments=None, stdout=sys.stdout, install_sig_handlers=True, api=None)
             put_args + ['--filename', outfile_name, image_file.name], stdout=stdout,
             install_sig_handlers=install_sig_handlers).strip()
 
-        api.collections().update(uuid=coll_uuid, body={"properties": {"docker-image-repo-tag": image_repo_tag}}).execute(num_retries=args.retries)
+        # Managed properties could be already set
+        coll_properties = api.collections().get(uuid=coll_uuid).execute(num_retries=args.retries).get('properties', {})
+        coll_properties.update({"docker-image-repo-tag": image_repo_tag})
+
+        api.collections().update(uuid=coll_uuid, body={"properties": coll_properties}).execute(num_retries=args.retries)
 
         # Read the image metadata and make Arvados links from it.
         image_file.seek(0)
index 695a0389dd8a81675ab3595bf232c7f7e2d48cb8..fd3a69cae4522cc5eee2bb8d59d1ac29a2208058 100644 (file)
@@ -4,6 +4,8 @@
 
 from __future__ import absolute_import
 import arvados
+import collections
+import copy
 import hashlib
 import mock
 import os
@@ -149,3 +151,46 @@ class ArvKeepdockerTestCase(unittest.TestCase, tutil.VersionChecker):
                         side_effect=StopTest) as find_image_mock:
             self.run_arv_keepdocker(['[::1]/repo/img'], sys.stderr)
         find_image_mock.assert_called_with('[::1]/repo/img', 'latest')
+
+    @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):
+        image_id = 'sha256:'+hashlib.sha256(b'image').hexdigest()
+        fakeDD = arvados.api('v1')._rootDesc
+        fakeDD['dockerImageFormats'] = ['v2']
+
+        err = tutil.StringIO()
+        out = tutil.StringIO()
+        File = collections.namedtuple('File', ['name'])
+        mocked_file = File(name='docker_image')
+        mocked_collection = {
+            'uuid': 'new-collection-uuid',
+            'properties': {
+                'responsible_person_uuid': 'person_uuid',
+            }
+        }
+
+        with tutil.redirected_streams(stdout=out), \
+             mock.patch('arvados.api') as api, \
+             mock.patch('arvados.commands.keepdocker.popen_docker',
+                        return_value=subprocess.Popen(
+                            ['echo', image_id],
+                            stdout=subprocess.PIPE)), \
+             mock.patch('arvados.commands.keepdocker.prep_image_file',
+                        return_value=(mocked_file, False)), \
+             mock.patch('arvados.commands.put.main',
+                        return_value='new-collection-uuid'), \
+             self.assertRaises(StopTest):
+
+            api()._rootDesc = fakeDD
+            api().collections().get().execute.return_value = copy.deepcopy(mocked_collection)
+            api().collections().update().execute.side_effect = StopTest
+            self.run_arv_keepdocker(['--force', 'testimage'], err)
+
+        updated_properties = mocked_collection['properties']
+        updated_properties.update({'docker-image-repo-tag': 'testimage:latest'})
+        api().collections().update.assert_called_with(
+            uuid=mocked_collection['uuid'],
+            body={'properties': updated_properties})