[ARVADOS] created: 36e23b3761e43231789df66dc441727c000a2ffc

Git user git at public.curoverse.com
Fri Sep 29 14:21:42 EDT 2017


        at  36e23b3761e43231789df66dc441727c000a2ffc (commit)


commit 36e23b3761e43231789df66dc441727c000a2ffc
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Fri Sep 29 14:20:54 2017 -0400

    8333: Support "arv keep docker repo:tag" syntax.
    
    "arv keep docker repo tag" still works, too.
    
    "arv keep docker repo:tag tag" is an error.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/python/arvados/commands/keepdocker.py b/sdk/python/arvados/commands/keepdocker.py
index 2c1ec73..4486959 100644
--- a/sdk/python/arvados/commands/keepdocker.py
+++ b/sdk/python/arvados/commands/keepdocker.py
@@ -62,10 +62,10 @@ _group.add_argument(
 
 keepdocker_parser.add_argument(
     'image', nargs='?',
-    help="Docker image to upload, as a repository name or hash")
+    help="Docker image to upload: repo, repo:tag, or hash")
 keepdocker_parser.add_argument(
-    'tag', nargs='?', default='latest',
-    help="Tag of the Docker image to upload (default 'latest')")
+    'tag', nargs='?',
+    help="Tag of the Docker image to upload (default 'latest'), if image is given as an untagged repo name")
 
 # Combine keepdocker options listed above with run_opts options of arv-put.
 # The options inherited from arv-put include --name, --project-uuid,
@@ -358,6 +358,16 @@ def main(arguments=None, stdout=sys.stdout):
                 raise
         sys.exit(0)
 
+    if ':' in args.image:
+        if args.tag is not None:
+            logger.error(
+                "image %r already includes a tag, cannot add tag argument %r",
+                args.image, args.tag)
+            sys.exit(1)
+        args.image, args.tag = args.image.split(':', 1)
+    elif args.tag is None:
+        args.tag = 'latest'
+
     # Pull the image if requested, unless the image is specified as a hash
     # that we already have.
     if args.pull and not find_image_hashes(args.image):
diff --git a/sdk/python/tests/test_arv_keepdocker.py b/sdk/python/tests/test_arv_keepdocker.py
index 36b4954..bf22860 100644
--- a/sdk/python/tests/test_arv_keepdocker.py
+++ b/sdk/python/tests/test_arv_keepdocker.py
@@ -33,8 +33,11 @@ class ArvKeepdockerTestCase(unittest.TestCase, tutil.VersionChecker):
             arv_keepdocker.logger.removeHandler(log_handler)
 
     def test_unsupported_arg(self):
-        with self.assertRaises(SystemExit):
+        out = tutil.StringIO()
+        with tutil.redirected_streams(stdout=out, stderr=out), \
+             self.assertRaises(SystemExit):
             self.run_arv_keepdocker(['-x=unknown'], sys.stderr)
+        self.assertRegex(out.getvalue(), 'unrecognized arguments')
 
     def test_version_argument(self):
         with tutil.redirected_streams(
@@ -114,3 +117,16 @@ class ArvKeepdockerTestCase(unittest.TestCase, tutil.VersionChecker):
             self.run_arv_keepdocker(
                 ['--force', '--force-image-format', 'testimage'], err)
         self.assertRegex(err.getvalue(), "forcing incompatible image")
+
+    def test_tag_given_twice(self):
+        with tutil.redirected_streams(stdout=tutil.StringIO, stderr=tutil.StringIO) as (out, err):
+            with self.assertRaises(SystemExit):
+                self.run_arv_keepdocker(['myrepo:mytag', 'extratag'], sys.stderr)
+            self.assertRegex(err.getvalue(), "cannot add tag argument 'extratag'")
+
+    def test_image_given_as_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(['repo:tag'], sys.stderr)
+        find_image_mock.assert_called_with('repo', 'tag')

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list