From: Zack Cerza Date: Wed, 9 Oct 2013 21:55:03 +0000 (-0500) Subject: Properly express conflicting options X-Git-Tag: 1.1.0~1811 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=098389da82ace88a69a729a1d75c3dddb949243a;p=teuthology.git Properly express conflicting options Signed-off-by: Zack Cerza --- diff --git a/scripts/updatekeys.py b/scripts/updatekeys.py index 364ac40e9..986f7806d 100644 --- a/scripts/updatekeys.py +++ b/scripts/updatekeys.py @@ -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 diff --git a/teuthology/lock.py b/teuthology/lock.py index 79dd127c3..97d923e27 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -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)