From ada69b4bb720fd46e43f9971616d561652727c33 Mon Sep 17 00:00:00 2001 From: Vasu Kulkarni Date: Thu, 24 Jan 2019 13:47:58 -0800 Subject: [PATCH] add new cli teuthology-reimage-fog to reimage FOG provisioned nodes without actually locking the nodes. Signed-off-by: Vasu Kulkarni --- scripts/reimage_fog.py | 22 ++++++++++++++++++++++ setup.py | 1 + teuthology/misc.py | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 scripts/reimage_fog.py diff --git a/scripts/reimage_fog.py b/scripts/reimage_fog.py new file mode 100644 index 000000000..0d260f59d --- /dev/null +++ b/scripts/reimage_fog.py @@ -0,0 +1,22 @@ +import docopt + +from teuthology.misc import reimage_fog +import sys + +doc = """ +usage: teuthology-reimage-fog -h + teuthology-reimage-fog --nodes node1,node2 --os-type distro --os-version version + +Reimage nodes using FOG without locking the nodes + +standard arguments: + -h, --help Show this help message and exit + --nodes node1,node2 List of nodes to reimage + --os-type Distribution type eg: rhel, ubuntu + --os-version OS version eg: 7.6, 16.04 etc +""" + + +def main(argv=sys.argv[1:]): + args = docopt.docopt(doc, argv=argv) + reimage_fog(args) diff --git a/setup.py b/setup.py index 2553028b5..b5dd3170c 100644 --- a/setup.py +++ b/setup.py @@ -116,6 +116,7 @@ setup( 'teuthology-prune-logs = scripts.prune_logs:main', 'teuthology-describe-tests = scripts.describe_tests:main', 'teuthology-gencov = scripts.gencov:main', + 'teuthology-reimage-fog = scripts.reimage_fog:main' ], }, diff --git a/teuthology/misc.py b/teuthology/misc.py index 346f174eb..67312f056 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -20,6 +20,8 @@ import yaml import json import re import pprint +import parallel + from netaddr.strategy.ipv4 import valid_str as _is_ipv4 from netaddr.strategy.ipv6 import valid_str as _is_ipv6 @@ -1387,6 +1389,21 @@ def is_in_dict(searchkey, searchval, d): return searchval == val +def reimage_fog(args): + """ + Reimage FOG nodes with options specified + """ + machines = args['--nodes'] + nodes = machines.rstrip(',').split(',') + ctx = argparse.Namespace() + ctx.os_type = args['--os-type'] + ctx.os_version = args['--os-version'] + from teuthology.provision import reimage + with parallel() as p: + for node in nodes: + p.spawn(reimage, ctx, node) + + def sh(command, log_limit=1024): """ Run the shell command and return the output in ascii (stderr and -- 2.47.3