import argparse
+import sys
import teuthology.lock
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
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:
_, 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)