From c4e35453fef4df0df14c5e68041a023df74913ef Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Thu, 5 Nov 2026 09:20:39 +0100 Subject: [PATCH] Made deploy show policy errors reported by cf-promises cf-agent runs cf-promises to validate the policy, and cf-promises writes errors like a duplicate bundle to stderr. Since only stdout was captured, these errors were silently dropped. Redirected stderr to stdout and extended the error pattern to also match the "file.cf:12:0: error:" format used by cf-promises. Signed-off-by: Victor Moene Co-Authored-By: Claude Opus 5.5 --- cf_remote/remote.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cf_remote/remote.py b/cf_remote/remote.py index 234bbf8..dae41ad 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -839,8 +839,11 @@ def deploy_masterfiles(host, tarball, *, connection=None, switch_user=None): "mv /var/cfengine/masterfiles /var/cfengine/masterfiles.delete", "mv masterfiles /var/cfengine/masterfiles", "rm -rf /var/cfengine/masterfiles.delete", - "{}cf-agent -Kf update.cf".format(cfagent_path), - "{}cf-agent -K".format(cfagent_path), + # cf-promises (run by cf-agent to validate the policy) writes policy + # errors, like a duplicate bundle, to stderr - and ssh_sudo() only + # returns stdout on success - so merge them to be able to show them. + "{}cf-agent -Kf update.cf 2>&1".format(cfagent_path), + "{}cf-agent -K 2>&1".format(cfagent_path), ] combined = " && ".join(commands) print("Running: '%s'" % combined) @@ -850,7 +853,9 @@ def deploy_masterfiles(host, tarball, *, connection=None, switch_user=None): log.error("Command failed, policy failed to deploy") return 1 - if re.search(r"(?m)^\s*error:", result): + # Matches both cf-agent's log lines (" error: ...") and the ones + # cf-promises prefixes with the location ("file.cf:12:0: error: ...") + if re.search(r"(?m)^(\s*|\S+:\d+:\d+: )error:", result): print(result) log.warning("cf-agent reported errors while running on '%s'" % host)