From c5f812bf3f418ae6e81345ae4769d94728fc6d3a Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Tue, 15 Aug 2023 18:09:42 +0800 Subject: [PATCH] Fix wrong bool argument parsing in upgrade_image.py script (#9452) Approach What is the motivation for this PR? The upgrade_image.py script defined some bool type arguments. However, "action" is not specified while defining these arguments. The result is that if user pass in arguments like below, the argument will be still be evaluated to True as python by default casting string "False" to bool value True. ./upgrade_image.py --enable-fips Flase How did you do it? The fix is to take advantage of setuptools.distutils.util.strtobool. With tool, any values like below passed in to this type of arguments would be evaluated to integer 0: "n", "no", "No", "NO", "False", "false", "FALSE", "FaLsE", ... Any argument value like below would be evaluated to integer 1: "y", "yes", "Yes", "YES", "True", "true", "TRUE", "TrUe", ... Signed-off-by: Xin Wang co-authorized by: jianquanye@microsoft.com --- .azure-pipelines/upgrade_image.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.azure-pipelines/upgrade_image.py b/.azure-pipelines/upgrade_image.py index 76f76d922d..819b7eaef6 100755 --- a/.azure-pipelines/upgrade_image.py +++ b/.azure-pipelines/upgrade_image.py @@ -16,6 +16,8 @@ import requests import sys +from setuptools import distutils + _self_dir = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.realpath(os.path.join(_self_dir, "..")) if base_path not in sys.path: @@ -285,17 +287,17 @@ def main(args): parser.add_argument( "--always-power-cycle", - type=bool, + type=distutils.util.strtobool, dest="always_power_cycle", - default=False, + default=0, help="Always power cycle DUTs before upgrade." ) parser.add_argument( "--power-cycle-unreachable", - type=bool, + type=distutils.util.strtobool, dest="power_cycle_unreachable", - default=True, + default=1, help="Only power cycle unreachable DUTs." ) @@ -319,10 +321,10 @@ def main(args): parser.add_argument( "--enable-fips", - type=bool, + type=distutils.util.strtobool, dest="enable_fips", required=False, - default=False, + default=0, help="Enable FIPS." )