Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zulip-puppet-apply: Factor out the --noop returncode logic.
Alex Vandiverc91725bfb5e3
diff --git a/scripts/zulip-puppet-apply b/scripts/zulip-puppet-applyindex d0b9de3622e..4a5be9b4e33 100755--- a/scripts/zulip-puppet-apply+++ b/scripts/zulip-puppet-apply@@ -6,6 +6,7 @@ import reimport subprocessimport sysimport tempfile+from typing import Listimport yaml@@ -68,22 +69,30 @@ if (distro_info["ID"], distro_info["VERSION_ID"]) in [("ubuntu", "20.04")]:if (distro_info["ID"], distro_info["VERSION_ID"]) in [("ubuntu", "22.04")]:puppet_env["RUBYOPT"] = "-r " + os.path.join(scripts_path, "lib", "ruby3hack.rb")-if not args.noop and not args.force:- # --noop does not work with --detailed-exitcodes; see https://tickets.puppetlabs.com/browse/PUP-686++def noop_would_change(puppet_cmd: List[str]) -> bool:+ # --noop does not work with --detailed-exitcodes; see+ # https://tickets.puppetlabs.com/browse/PUP-686try:lastrun_file = tempfile.NamedTemporaryFile()subprocess.check_call(- [*puppet_cmd, "--noop", "--show_diff", "--lastrunfile", lastrun_file.name],+ # puppet_cmd may already contain --noop, but it is safe to+ # supply twice+ [*puppet_cmd, "--noop", "--lastrunfile", lastrun_file.name],env=puppet_env,)with open(lastrun_file.name) as lastrun:lastrun_data = yaml.safe_load(lastrun)- if lastrun_data.get("resources", {}).get("out_of_sync", 0) == 0:- sys.exit(0)+ return lastrun_data.get("resources", {}).get("out_of_sync", 0) != 0finally:lastrun_file.close()++if not args.noop and not args.force:+ if not noop_would_change([*puppet_cmd, "--show_diff"]):+ sys.exit(0)+do_apply = Nonewhile do_apply != "y":sys.stdout.write("Apply changes? [y/N] ")