Skip to content

Commit b23e006

Browse files
committed
refactor: log-to-syslog in debug_flags will log internal trace msgs to syslog [citest_skip]
If you set __network_debug_flags=log-to-syslog then the internal trace messages which are returned by the module will also be logged to syslog. This is useful for when the network role hangs and times out and is killed before those messages can be returned. The trace messages printed to syslog can help debug problems. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 1f5c1a4 commit b23e006

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

library/network_connections.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,8 @@ def log(
18221822
raise AssertionError("idx {0} is less than -1".format(idx))
18231823
self._log_idx += 1
18241824
self.run_results[idx]["log"].append((severity, msg, self._log_idx))
1825+
if "log-to-syslog" in self.module.params["__debug_flags"]:
1826+
self.module.log("%s: %s: %s" % (LogLevel.fmt(severity), idx, msg))
18251827
if severity == LogLevel.ERROR:
18261828
if force_fail or not ignore_errors:
18271829
self.fail_json(
@@ -2019,13 +2021,17 @@ def log_fatal(self, idx, msg, warn_traceback=False):
20192021
)
20202022

20212023
def log(self, idx, severity, msg, warn_traceback=False, force_fail=False):
2024+
if len(self.connections) > idx:
2025+
ignore_errors = self.connection_ignore_errors(self.connections[idx])
2026+
else:
2027+
ignore_errors = self._ignore_errors
20222028
self.run_env.log(
20232029
self.connections,
20242030
idx,
20252031
severity,
20262032
msg,
20272033
is_changed=self.is_changed_modified_system,
2028-
ignore_errors=self.connection_ignore_errors(self.connections[idx]),
2034+
ignore_errors=ignore_errors,
20292035
warn_traceback=warn_traceback,
20302036
force_fail=force_fail,
20312037
)
@@ -2125,7 +2131,9 @@ def run(self):
21252131
self.run_prepare()
21262132
while self.check_mode_next() != CheckMode.DONE:
21272133
if self.check_mode == CheckMode.REAL_RUN:
2134+
self.log(0, LogLevel.INFO, "Starting transaction")
21282135
self.start_transaction()
2136+
self.log(0, LogLevel.INFO, "Started transaction")
21292137

21302138
# Reasoning for this order:
21312139
# For down/up profiles might need to be present, so do this first
@@ -2146,11 +2154,15 @@ def run(self):
21462154
self.run_action_down(idx)
21472155
except Exception as error:
21482156
if self.check_mode == CheckMode.REAL_RUN:
2157+
self.log(idx, LogLevel.INFO, "Rolling back transaction")
21492158
self.rollback_transaction(idx, action, error)
2159+
self.log(0, LogLevel.INFO, "Rolled back transaction")
21502160
raise
21512161

21522162
if self.check_mode == CheckMode.REAL_RUN:
2163+
self.log(0, LogLevel.INFO, "Finishing transaction")
21532164
self.finish_transaction()
2165+
self.log(0, LogLevel.INFO, "Finished transaction")
21542166

21552167
def run_prepare(self):
21562168
for idx, connection in enumerate(self.connections):
@@ -2912,6 +2924,7 @@ def main():
29122924
changed=(cmd is not None and cmd.is_changed_modified_system),
29132925
warn_traceback=not isinstance(e, MyError),
29142926
)
2927+
cmd.log(0, LogLevel.INFO, "Exiting")
29152928
run_env_ansible.exit_json(
29162929
connections, changed=(cmd is not None and cmd.is_changed_modified_system)
29172930
)

tests/playbooks/tests_route_device.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
the output device is logged for initscripts provider
132132
assert:
133133
that:
134-
- __network_connections_result.stderr is search("\[003\]
135-
<warn> .0, state.None persistent_state.present,
134+
- __network_connections_result.stderr is search("<warn> .0,
135+
state.None persistent_state.present,
136136
'{{ interface1 }}'. The connection {{ interface1 }} does not
137137
specify an interface name. Therefore, the route to
138138
198.58.10.64/26 will be configured without the output device

0 commit comments

Comments
 (0)