MCPcopy
hub / github.com/ktbyers/netmiko / test_session_log_bytesio

Function test_session_log_bytesio

tests/test_netmiko_session_log.py:245–271  ·  view source on GitHub ↗

Verify session_log matches expected content, but when channel writes are also logged.

(device_slog_test_name, commands, expected_responses)

Source from the content-addressed store, hash-verified

243
244
245def test_session_log_bytesio(device_slog_test_name, commands, expected_responses):
246 """Verify session_log matches expected content, but when channel writes are also logged."""
247 device_slog = device_slog_test_name[0]
248 test_name = device_slog_test_name[1]
249
250 s_log = io.BytesIO()
251
252 # The netmiko connection has not been established yet.
253 device_slog["session_log"] = s_log
254 device_slog["session_log_file_mode"] = "write"
255 device_slog["session_log_record_writes"] = True
256
257 conn = ConnectHandler(**device_slog)
258 command = commands["basic"]
259 session_action(conn, command)
260 conn.disconnect()
261
262 compare_file = expected_responses["compare_log"]
263 compare_file = add_test_name_to_file_name(compare_file, test_name)
264
265 with open(compare_file, "rb") as f:
266 compare_contents = filter_bare_prompts(f.read(), conn.base_prompt)
267 compare_log_md5 = calc_md5(contents=compare_contents)
268
269 log_content = filter_bare_prompts(s_log.getvalue(), conn.base_prompt)
270 session_log_md5 = calc_md5(contents=log_content)
271 assert session_log_md5 == compare_log_md5
272
273
274def test_session_log_no_log(device_slog_test_name):

Callers

nothing calls this directly

Calls 6

ConnectHandlerFunction · 0.90
session_actionFunction · 0.85
filter_bare_promptsFunction · 0.85
calc_md5Function · 0.85
disconnectMethod · 0.80

Tested by

no test coverage detected