Skip to content

Commit

Permalink
Fix wrong bool argument parsing in upgrade_image.py script (#9452) (#…
Browse files Browse the repository at this point in the history
…9455)




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", ...

co-authorized by: jianquanye@microsoft.com
  • Loading branch information
mssonicbld authored Aug 16, 2023
1 parent bb9105d commit 80a5ab1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions .azure-pipelines/upgrade_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."
)

Expand All @@ -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."
)

Expand Down

0 comments on commit 80a5ab1

Please sign in to comment.