Skip to content

Commit dde7ea3

Browse files
committed
SNMP: add e2e diagnostic dump for test_e2e_v1_with_apc_ups_profile
When the assertion fails (currently failing in CI on every SNMP PR with "Needed at least 1 candidates for 'snmp.device.reachable', got 0"), dump: - docker ps state - snmpsim container logs (tail 40) - snmpsim mount sources/destinations - whether apc_ups fixture is present + first lines of args_list.txt - a direct snmpget probe against the snmpsim container Diagnostic only, no test-logic change. Helps narrow whether the daemon isn't routing the community, the fixture isn't mounted, or the agent isn't reaching the daemon.
1 parent 611a2c1 commit dde7ea3

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

snmp/tests/test_e2e_core.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,46 @@ def test_e2e_v1_with_apc_ups_profile(dd_agent_check):
2222
'community_string': 'apc_ups',
2323
}
2424
)
25-
assert_apc_ups_metrics(dd_agent_check, config)
25+
try:
26+
assert_apc_ups_metrics(dd_agent_check, config)
27+
except AssertionError:
28+
_dump_snmp_e2e_diagnostics(instance, community='apc_ups')
29+
raise
30+
31+
32+
def _dump_snmp_e2e_diagnostics(instance, community):
33+
"""Print everything we'd need to triage 'got 0 candidates' failures.
34+
35+
Triggers only when an assertion has already failed; keeps the test signal
36+
intact while making CI logs self-explanatory for env flakes.
37+
"""
38+
import subprocess
39+
40+
def _run(cmd, label):
41+
print('\n----- DEBUG: {} -----'.format(label), flush=True)
42+
print('$ {}'.format(' '.join(cmd)), flush=True)
43+
try:
44+
out = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
45+
print('exit={}\nstdout:\n{}\nstderr:\n{}'.format(out.returncode, out.stdout, out.stderr), flush=True)
46+
except Exception as exc:
47+
print('error: {}'.format(exc), flush=True)
48+
49+
print('\n========== SNMP E2E DIAGNOSTICS ==========', flush=True)
50+
print('instance: ip={} port={} community={}'.format(
51+
instance.get('ip_address'), instance.get('port'), community), flush=True)
52+
53+
_run(['docker', 'ps', '-a', '--format', '{{.Names}}\t{{.Image}}\t{{.Status}}'], 'docker ps')
54+
_run(['docker', 'logs', '--tail', '40', SNMP_CONTAINER_NAME], 'snmpsim logs (tail 40)')
55+
_run(['docker', 'inspect', SNMP_CONTAINER_NAME,
56+
'--format', '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{println}}{{end}}'],
57+
'snmpsim mounts')
58+
_run(['docker', 'exec', SNMP_CONTAINER_NAME, 'sh', '-c',
59+
'ls /usr/snmpsim/data/ | wc -l; ls /usr/snmpsim/data/apc_ups* 2>&1; head -5 /usr/snmpsim/data/args_list.txt 2>&1'],
60+
'snmpsim data dir + apc_ups fixture + args_list.txt head')
61+
_run(['docker', 'exec', SNMP_CONTAINER_NAME, 'sh', '-c',
62+
'snmpget -v1 -c apc_ups 127.0.0.1:1161 1.3.6.1.2.1.1.1.0 2>&1 || true'],
63+
'snmpget apc_ups sysDescr from inside snmpsim container')
64+
print('========== END SNMP E2E DIAGNOSTICS ==========\n', flush=True)
2665

2766

2867
def test_e2e_core_v3_no_auth_no_priv(dd_agent_check):

0 commit comments

Comments
 (0)