From ef40721949b331b51bdc86ab4e6582bf9f5ee402 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 5 Jun 2023 17:48:48 -0600 Subject: [PATCH] Py3.8 updates --- salt/modules/win_servermanager.py | 2 +- salt/modules/win_wusa.py | 16 +++--- salt/states/win_dism.py | 63 +++++++++++---------- salt/utils/win_pwsh.py | 4 +- tests/pytests/unit/modules/test_win_wusa.py | 4 +- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/salt/modules/win_servermanager.py b/salt/modules/win_servermanager.py index 81e8e8e5044..ab714b30e37 100644 --- a/salt/modules/win_servermanager.py +++ b/salt/modules/win_servermanager.py @@ -194,7 +194,7 @@ def install(feature, recurse=False, restart=False, source=None, exclude=None): shlex.quote(feature), management_tools, "-IncludeAllSubFeature" if recurse else "", - "" if source is None else "-Source {}".format(source), + "" if source is None else f"-Source {source}", ) out = salt.utils.win_pwsh.run_dict(cmd) diff --git a/salt/modules/win_wusa.py b/salt/modules/win_wusa.py index f0c06edddb3..1a25fed3fa6 100644 --- a/salt/modules/win_wusa.py +++ b/salt/modules/win_wusa.py @@ -57,7 +57,7 @@ def is_installed(name): """ return ( __salt__["cmd.retcode"]( - cmd="Get-HotFix -Id {}".format(name), + cmd=f"Get-HotFix -Id {name}", shell="powershell", ignore_retcode=True, ) @@ -105,17 +105,17 @@ def install(path, restart=False): # Check the ret_code file_name = os.path.basename(path) errors = { - 2359302: "{} is already installed".format(file_name), + 2359302: f"{file_name} is already installed", 3010: ( - "{} correctly installed but server reboot is needed to complete" - " installation".format(file_name) + f"{file_name} correctly installed but server reboot is needed to " + f"complete installation" ), 87: "Unknown error", } if ret_code in errors: raise CommandExecutionError(errors[ret_code], ret_code) elif ret_code: - raise CommandExecutionError("Unknown error: {}".format(ret_code)) + raise CommandExecutionError(f"Unknown error: {ret_code}") return True @@ -170,14 +170,14 @@ def uninstall(path, restart=False): # If you pass /quiet and specify /kb, you'll always get retcode 87 if there # is an error. Use the actual file to get a more descriptive error errors = { - -2145116156: "{} does not support uninstall".format(kb), - 2359303: "{} not installed".format(kb), + -2145116156: f"{kb} does not support uninstall", + 2359303: f"{kb} not installed", 87: "Unknown error. Try specifying an .msu file", } if ret_code in errors: raise CommandExecutionError(errors[ret_code], ret_code) elif ret_code: - raise CommandExecutionError("Unknown error: {}".format(ret_code)) + raise CommandExecutionError(f"Unknown error: {ret_code}") return True diff --git a/salt/states/win_dism.py b/salt/states/win_dism.py index 3acdbe23b2c..e6958e467bd 100644 --- a/salt/states/win_dism.py +++ b/salt/states/win_dism.py @@ -74,11 +74,11 @@ def capability_installed( old = __salt__["dism.installed_capabilities"]() if name in old: - ret["comment"] = "The capability {} is already installed".format(name) + ret["comment"] = f"The capability {name} is already installed" return ret if __opts__["test"]: - ret["changes"]["capability"] = "{} will be installed".format(name) + ret["changes"]["capability"] = f"{name} will be installed" ret["result"] = None return ret @@ -86,14 +86,14 @@ def capability_installed( status = __salt__["dism.add_capability"](name, source, limit_access, image, restart) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to install {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to install {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_capabilities"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Installed {}".format(name) + ret["comment"] = f"Installed {name}" ret["changes"] = status ret["changes"]["capability"] = changes @@ -133,11 +133,11 @@ def capability_removed(name, image=None, restart=False): old = __salt__["dism.installed_capabilities"]() if name not in old: - ret["comment"] = "The capability {} is already removed".format(name) + ret["comment"] = f"The capability {name} is already removed" return ret if __opts__["test"]: - ret["changes"]["capability"] = "{} will be removed".format(name) + ret["changes"]["capability"] = f"{name} will be removed" ret["result"] = None return ret @@ -145,14 +145,14 @@ def capability_removed(name, image=None, restart=False): status = __salt__["dism.remove_capability"](name, image, restart) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to remove {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to remove {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_capabilities"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Removed {}".format(name) + ret["comment"] = f"Removed {name}" ret["changes"] = status ret["changes"]["capability"] = changes @@ -214,11 +214,11 @@ def feature_installed( old = __salt__["dism.installed_features"]() if name in old: - ret["comment"] = "The feature {} is already installed".format(name) + ret["comment"] = f"The feature {name} is already installed" return ret if __opts__["test"]: - ret["changes"]["feature"] = "{} will be installed".format(name) + ret["changes"]["feature"] = f"{name} will be installed" ret["result"] = None return ret @@ -228,14 +228,14 @@ def feature_installed( ) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to install {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to install {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_features"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Installed {}".format(name) + ret["comment"] = f"Installed {name}" ret["changes"] = status ret["changes"]["feature"] = changes @@ -280,11 +280,11 @@ def feature_removed(name, remove_payload=False, image=None, restart=False): old = __salt__["dism.installed_features"]() if name not in old: - ret["comment"] = "The feature {} is already removed".format(name) + ret["comment"] = f"The feature {name} is already removed" return ret if __opts__["test"]: - ret["changes"]["feature"] = "{} will be removed".format(name) + ret["changes"]["feature"] = f"{name} will be removed" ret["result"] = None return ret @@ -292,14 +292,14 @@ def feature_removed(name, remove_payload=False, image=None, restart=False): status = __salt__["dism.remove_feature"](name, remove_payload, image, restart) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to remove {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to remove {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_features"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Removed {}".format(name) + ret["comment"] = f"Removed {name}" ret["changes"] = status ret["changes"]["feature"] = changes @@ -348,7 +348,7 @@ def package_installed( ret["result"] = None else: ret["result"] = False - ret["comment"] = "Package path {} does not exist".format(name) + ret["comment"] = f"Package path {name} does not exist" return ret old = __salt__["dism.installed_packages"]() @@ -357,13 +357,14 @@ def package_installed( package_info = __salt__["dism.package_info"](name) if package_info["Package Identity"] in old: - ret["comment"] = "The package {} is already installed: {}".format( - name, package_info["Package Identity"] + ret["comment"] = ( + f"The package {name} is already installed: " + f'{package_info["Package Identity"]}' ) return ret if __opts__["test"]: - ret["changes"]["package"] = "{} will be installed".format(name) + ret["changes"]["package"] = f"{name} will be installed" ret["result"] = None return ret @@ -373,14 +374,14 @@ def package_installed( ) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to install {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to install {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_packages"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Installed {}".format(name) + ret["comment"] = f"Installed {name}" ret["changes"] = status ret["changes"]["package"] = changes @@ -508,7 +509,7 @@ def package_removed(name, image=None, restart=False): ret["result"] = None else: ret["result"] = False - ret["comment"] = "Package path {} does not exist".format(name) + ret["comment"] = f"Package path {name} does not exist" return ret old = __salt__["dism.installed_packages"]() @@ -522,11 +523,11 @@ def package_removed(name, image=None, restart=False): "Package Identity" not in package_info or package_info["Package Identity"] not in old ): - ret["comment"] = "The package {} is already removed".format(name) + ret["comment"] = f"The package {name} is already removed" return ret if __opts__["test"]: - ret["changes"]["package"] = "{} will be removed".format(name) + ret["changes"]["package"] = f"{name} will be removed" ret["result"] = None return ret @@ -534,14 +535,14 @@ def package_removed(name, image=None, restart=False): status = __salt__["dism.remove_package"](name, image, restart) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to remove {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to remove {name}: {status["stdout"]}' ret["result"] = False new = __salt__["dism.installed_packages"]() changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Removed {}".format(name) + ret["comment"] = f"Removed {name}" ret["changes"] = status ret["changes"]["package"] = changes @@ -587,11 +588,11 @@ def kb_removed(name, image=None, restart=False): # If pkg_name is None, the package is not installed if pkg_name is None: - ret["comment"] = "{} is not installed".format(name) + ret["comment"] = f"{name} is not installed" return ret if __opts__["test"]: - ret["changes"]["package"] = "{} will be removed".format(name) + ret["changes"]["package"] = f"{name} will be removed" ret["result"] = None return ret @@ -602,7 +603,7 @@ def kb_removed(name, image=None, restart=False): status = __salt__["dism.remove_kb"](kb=name, image=image, restart=restart) if status["retcode"] not in [0, 1641, 3010]: - ret["comment"] = "Failed to remove {}: {}".format(name, status["stdout"]) + ret["comment"] = f'Failed to remove {name}: {status["stdout"]}' ret["result"] = False return ret @@ -610,7 +611,7 @@ def kb_removed(name, image=None, restart=False): changes = salt.utils.data.compare_lists(old, new) if changes: - ret["comment"] = "Removed {}".format(name) + ret["comment"] = f"Removed {name}" ret["changes"] = status ret["changes"]["package"] = changes diff --git a/salt/utils/win_pwsh.py b/salt/utils/win_pwsh.py index b0e76d2aacf..7e6e659f91f 100644 --- a/salt/utils/win_pwsh.py +++ b/salt/utils/win_pwsh.py @@ -49,9 +49,7 @@ def run_dict(cmd, cwd=None): if "retcode" not in ret or ret["retcode"] != 0: # run_all logs an error to log.error, fail hard back to the user - raise CommandExecutionError( - "Issue executing PowerShell {}".format(cmd), info=ret - ) + raise CommandExecutionError(f"Issue executing PowerShell cmd", info=ret) # Sometimes Powershell returns an empty string, which isn't valid JSON if ret["stdout"] == "": diff --git a/tests/pytests/unit/modules/test_win_wusa.py b/tests/pytests/unit/modules/test_win_wusa.py index 926a99f9fec..e68cb61cd07 100644 --- a/tests/pytests/unit/modules/test_win_wusa.py +++ b/tests/pytests/unit/modules/test_win_wusa.py @@ -163,7 +163,7 @@ def test_uninstall_kb(): "wusa.exe", "/uninstall", "/quiet", - "/kb:{}".format(kb[2:]), + f"/kb:{kb[2:]}", "/norestart", ], ignore_retcode=True, @@ -217,7 +217,7 @@ def test_uninstall_already_uninstalled(): "wusa.exe", "/uninstall", "/quiet", - "/kb:{}".format(kb[2:]), + f"/kb:{kb[2:]}", "/norestart", ], ignore_retcode=True,