]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Properly express conflicting options
authorZack Cerza <zack@cerza.org>
Wed, 9 Oct 2013 21:55:03 +0000 (16:55 -0500)
committerZack Cerza <zack@cerza.org>
Fri, 11 Oct 2013 00:09:35 +0000 (19:09 -0500)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
scripts/updatekeys.py
teuthology/lock.py

index 364ac40e92d8373fa239dff6a82f605bbb83abc8..986f7806daaa332fa89a67b818fdbd914e0a6c9a 100644 (file)
@@ -1,4 +1,5 @@
 import argparse
+import sys
 
 import teuthology.lock
 
@@ -12,29 +13,38 @@ def parse_args():
 Update any hostkeys that have changed. You can list specific machines
 to run on, or use -a to check all of them automatically.
 """)
-    parser.add_argument(
-        '-t', '--targets',
-        default=None,
-        help='input yaml containing targets to check',
-    )
-    parser.add_argument(
-        'machines',
-        metavar='MACHINES',
-        default=[],
-        nargs='*',
-        help='hosts to check for updated keys',
-    )
     parser.add_argument(
         '-v', '--verbose',
         action='store_true',
         default=False,
         help='be more verbose',
     )
-    parser.add_argument(
+    group = parser.add_mutually_exclusive_group()
+    group.add_argument(
+        '-t', '--targets',
+        default=None,
+        help='input yaml containing targets to check',
+    )
+    group.add_argument(
         '-a', '--all',
         action='store_true',
         default=False,
         help='update hostkeys of all machines in the db',
     )
+    group.add_argument(
+        'machines',
+        metavar='MACHINES',
+        default=[],
+        nargs='*',
+        help='hosts to check for updated keys',
+    )
+
+    args = parser.parse_args()
+
+    if not (args.all or args.targets or args.machines):
+        parser.print_usage()
+        print "{name}: error: You must specify machines to update".format(
+            name='teuthology-updatekeys')
+        sys.exit(2)
 
-    return parser.parse_args()
+    return args
index 79dd127c3bfcf9a134b00d5013e54499c7902c5f..97d923e27111497765e9cb072615c685b32fc8c9 100644 (file)
@@ -317,11 +317,6 @@ def updatekeys(ctx):
 
     teuthology.read_config(ctx)
 
-    msg = 'You must specify machines to update'
-    assert ctx.all or ctx.targets or ctx.machines, msg
-    if ctx.all:
-        assert not ctx.targets and not ctx.machines, \
-            'You can\'t specify machines with the --all option'
     machines = [canonicalize_hostname(m) for m in ctx.machines]
 
     if ctx.targets:
@@ -353,12 +348,7 @@ def keyscan_check(ctx, machines):
             _, machines[i] = machine.rsplit('@')
     args = ['ssh-keyscan']
     args.extend(machines)
-    p = subprocess.Popen(
-        args=args,
-        stdout=subprocess.PIPE,
-    )
-    out, _ = p.communicate()
-    # assert p.returncode == 0, 'ssh-keyscan failed'
+    out = subprocess.check_output(args)
     return (out, current_locks)