[MediaWiki-commits] [Gerrit] operations/puppet[production]: wmf-auto-reimage: add --conftool-value option

2017-12-06 Thread Volans (Code Review)
Volans has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/395662 )

Change subject: wmf-auto-reimage: add --conftool-value option
..


wmf-auto-reimage: add --conftool-value option

* The current parse of command line arguments allow the -c/--conftool
  option to accept an optional value to use to depool the host in
  conftool. Due to a limitation in Python argparse module, this can
  generate an error while parsing valid CLI options, see T181798.
* Convert the -c/--conftool option to be boolean and move the optional
  specification of a custom value for conftool to the new
  --conftool-value option, that defaults to 'inactive' as it is now.

Bug: T181798
Change-Id: I379bd619a1bebf7ecf8bdb456ce666293b1fadb7
---
M modules/profile/files/cumin/wmf_auto_reimage_host.py
M modules/profile/files/cumin/wmf_auto_reimage_lib.py
2 files changed, 16 insertions(+), 10 deletions(-)

Approvals:
  Muehlenhoff: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Volans: Looks good to me, approved



diff --git a/modules/profile/files/cumin/wmf_auto_reimage_host.py 
b/modules/profile/files/cumin/wmf_auto_reimage_host.py
index b8e2ad7..db43c16 100644
--- a/modules/profile/files/cumin/wmf_auto_reimage_host.py
+++ b/modules/profile/files/cumin/wmf_auto_reimage_host.py
@@ -105,8 +105,8 @@
 lib.icinga_downtime(args.host, user, args.phab_task_id)
 
 # Depool via conftool
-if args.conftool is not None and not args.new:
-previous = lib.conftool_depool(args.host, pooled=args.conftool)
+if args.conftool and not args.new:
+previous = lib.conftool_depool(args.host, pooled=args.conftool_value)
 lib.print_line('Waiting 3 minutes to let the host drain', 
host=args.host)
 time.sleep(180)
 
@@ -160,7 +160,7 @@
 lib.run_apache_fast_test(args.host)
 
 # The repool is *not* done automatically, the command to repool is printed 
and logged
-if args.conftool is not None:
+if args.conftool:
 lib.print_repool_message(previous, rename_from=rename_from, 
rename_to=args.rename)
 
 lib.print_line('Reimage completed', host=args.host)
diff --git a/modules/profile/files/cumin/wmf_auto_reimage_lib.py 
b/modules/profile/files/cumin/wmf_auto_reimage_lib.py
index 7a84f27..23ae16f 100644
--- a/modules/profile/files/cumin/wmf_auto_reimage_lib.py
+++ b/modules/profile/files/cumin/wmf_auto_reimage_lib.py
@@ -128,11 +128,16 @@
 help=('for first imaging of new hosts that are not in puppet yet and 
this is their first'
   'imaging. Skips some steps on old hosts, includes --no-verify'))
 parser.add_argument(
-'-c', '--conftool', nargs='?', const='inactive',
-help=("depool the host(s) via conftool with the 'inactive' value, if 
set. Optionally "
-  "a custom value can be specified to be used for conftool 
'set/pooled' update. "
-  "The host(s) will NOT be repooled automatically, but the repool 
commands will be "
-  "printed at the end. If --new is also set just print the pool 
message."))
+'-c', '--conftool', action='store_true',
+help=("Depool the host(s) via conftool with the value of the 
--conftool-value option. "
+  "If the --conftool-value option is not set, its default value of 
'inactive' will be "
+  "used. The host(s) will NOT be repooled automatically, but the 
repool commands will "
+  "be printed at the end. If --new is also set, it will just print 
the pool message "
+  "at the end."))
+parser.add_argument(
+'--conftool-value', default='inactive',
+help=("Value to pass to the 'set/pooled' command in conftool to depool 
the host(s), if "
+  "the -c/--conftool option is set. [default: inactive]"))
 parser.add_argument(
 '-a', '--apache', action='store_true',
 help='run apache-fast-test on the hosts after the reimage')
@@ -398,14 +403,15 @@
 command_args = ['wmf-auto-reimage-host']
 args_dict = vars(args)
 # Add boolean command line arguments
-for key in ('debug', 'no_reboot', 'no_verify', 'no_downtime', 'no_pxe', 
'new', 'apache'):
+for key in ('debug', 'no_reboot', 'no_verify', 'no_downtime', 'no_pxe', 
'new', 'apache',
+'conftool'):
 if args_dict[key]:
 command_args.append(get_option_from_name(key))
 
 # Add command line arguments with values
 # The --phab-task-id options is skipped because the main script already 
takes care
 # of upgrading Phabricator
-for key in ('conftool',):
+for key in ('conftool-value',):
 if args_dict[key] is not None:
 command_args.append(get_option_from_name(key))
 command_args.append(args_dict[key])

-- 
To view, visit https://gerrit.wikimedia.org/r/395662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings


[MediaWiki-commits] [Gerrit] operations/puppet[production]: wmf-auto-reimage: add --conftool-value option

2017-12-05 Thread Volans (Code Review)
Volans has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/395662 )

Change subject: wmf-auto-reimage: add --conftool-value option
..

wmf-auto-reimage: add --conftool-value option

* The current parse of command line arguments allow the -c/--conftool
  option to accept an optional value to use to depool the host in
  conftool. Due to a limitation in Python argparse module, this can
  generate an error while parsing valid CLI options, see T181798.
* Convert the -c/--conftool option to be boolean and move the optional
  specification of a custom value for conftool to the new
  --conftool-value option, that defaults to 'inactive' as it is now.

Bug: T181798
Change-Id: I379bd619a1bebf7ecf8bdb456ce666293b1fadb7
---
M modules/profile/files/cumin/wmf_auto_reimage_host.py
M modules/profile/files/cumin/wmf_auto_reimage_lib.py
2 files changed, 15 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/62/395662/1

diff --git a/modules/profile/files/cumin/wmf_auto_reimage_host.py 
b/modules/profile/files/cumin/wmf_auto_reimage_host.py
index b8e2ad7..db43c16 100644
--- a/modules/profile/files/cumin/wmf_auto_reimage_host.py
+++ b/modules/profile/files/cumin/wmf_auto_reimage_host.py
@@ -105,8 +105,8 @@
 lib.icinga_downtime(args.host, user, args.phab_task_id)
 
 # Depool via conftool
-if args.conftool is not None and not args.new:
-previous = lib.conftool_depool(args.host, pooled=args.conftool)
+if args.conftool and not args.new:
+previous = lib.conftool_depool(args.host, pooled=args.conftool_value)
 lib.print_line('Waiting 3 minutes to let the host drain', 
host=args.host)
 time.sleep(180)
 
@@ -160,7 +160,7 @@
 lib.run_apache_fast_test(args.host)
 
 # The repool is *not* done automatically, the command to repool is printed 
and logged
-if args.conftool is not None:
+if args.conftool:
 lib.print_repool_message(previous, rename_from=rename_from, 
rename_to=args.rename)
 
 lib.print_line('Reimage completed', host=args.host)
diff --git a/modules/profile/files/cumin/wmf_auto_reimage_lib.py 
b/modules/profile/files/cumin/wmf_auto_reimage_lib.py
index 7a84f27..20b2a21 100644
--- a/modules/profile/files/cumin/wmf_auto_reimage_lib.py
+++ b/modules/profile/files/cumin/wmf_auto_reimage_lib.py
@@ -128,11 +128,15 @@
 help=('for first imaging of new hosts that are not in puppet yet and 
this is their first'
   'imaging. Skips some steps on old hosts, includes --no-verify'))
 parser.add_argument(
-'-c', '--conftool', nargs='?', const='inactive',
-help=("depool the host(s) via conftool with the 'inactive' value, if 
set. Optionally "
-  "a custom value can be specified to be used for conftool 
'set/pooled' update. "
-  "The host(s) will NOT be repooled automatically, but the repool 
commands will be "
-  "printed at the end. If --new is also set just print the pool 
message."))
+'-c', '--conftool', action='store_true',
+help=('Depool the host(s) via conftool with the value of the 
--conftool-value option. '
+  'The host(s) will NOT be repooled automatically, but the repool 
commands will be '
+  'printed at the end. If --new is also set, it will just print 
the pool message at '
+  'the end.'))
+parser.add_argument(
+'--conftool-value', default='inactive',
+help=("Value to pass to the 'set/pooled' command in conftool to depool 
the host(s), if "
+  "the -c/--conftool option is set. [default: inactive]"))
 parser.add_argument(
 '-a', '--apache', action='store_true',
 help='run apache-fast-test on the hosts after the reimage')
@@ -398,14 +402,15 @@
 command_args = ['wmf-auto-reimage-host']
 args_dict = vars(args)
 # Add boolean command line arguments
-for key in ('debug', 'no_reboot', 'no_verify', 'no_downtime', 'no_pxe', 
'new', 'apache'):
+for key in ('debug', 'no_reboot', 'no_verify', 'no_downtime', 'no_pxe', 
'new', 'apache',
+'conftool'):
 if args_dict[key]:
 command_args.append(get_option_from_name(key))
 
 # Add command line arguments with values
 # The --phab-task-id options is skipped because the main script already 
takes care
 # of upgrading Phabricator
-for key in ('conftool',):
+for key in ('conftool-value',):
 if args_dict[key] is not None:
 command_args.append(get_option_from_name(key))
 command_args.append(args_dict[key])

-- 
To view, visit https://gerrit.wikimedia.org/r/395662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I379bd619a1bebf7ecf8bdb456ce666293b1fadb7
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production