Skip to content

Commit e0611c2

Browse files
authored
Fix namespace filter matching when there is a partial match (#838)
* Fix namespace filter Signed-off-by: Claudio Lorina <[email protected]> * Add tests for namespace filtering Signed-off-by: Claudio Lorina <[email protected]> Signed-off-by: Claudio Lorina <[email protected]>
1 parent a1dc3e3 commit e0611c2

File tree

2 files changed

+138
-2
lines changed

2 files changed

+138
-2
lines changed

suzieq/db/parquet/parquetdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ def check_ns_conds(ns_to_test: str, filter_list: List[str],
638638
if operator.and_ == op:
639639
res = True
640640
for filter_val in filter_list:
641-
res = op(res, bool(re.search(
642-
f'namespace={filter_val}', ns_to_test)))
641+
ns_to_test = ns_to_test.split('namespace=')[-1]
642+
res = op(res, bool(re.fullmatch(filter_val, ns_to_test)))
643643
return res
644644

645645
if not namespaces:

tests/integration/sqcmds/common-samples/common-errors.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,139 @@ tests:
44
data-directory: tests/data/parquet/
55
marks: topology summarize
66
output: '{}'
7+
- command: device show --namespace=ospf --format=json
8+
data-directory: tests/data/parquet/
9+
marks: device show
10+
output: '[]'
11+
- command: device show --namespace=ospf-ibgp --format=json
12+
data-directory: tests/data/parquet/
13+
marks: device show
14+
output: '[{"namespace": "ospf-ibgp", "hostname": "server103", "model": "vm", "version":
15+
"16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
16+
"address": "192.168.123.150", "bootupTimestamp": 1616680845.0, "timestamp": 1616681581595},
17+
{"namespace": "ospf-ibgp", "hostname": "server101", "model": "vm", "version":
18+
"16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
19+
"address": "192.168.123.184", "bootupTimestamp": 1616680816.0, "timestamp": 1616681581632},
20+
{"namespace": "ospf-ibgp", "hostname": "server104", "model": "vm", "version":
21+
"16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
22+
"address": "192.168.123.197", "bootupTimestamp": 1616680858.0, "timestamp": 1616681581652},
23+
{"namespace": "ospf-ibgp", "hostname": "edge01", "model": "vm", "version": "16.04.7
24+
LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive", "address":
25+
"192.168.123.180", "bootupTimestamp": 1616681014.0, "timestamp": 1616681581705},
26+
{"namespace": "ospf-ibgp", "hostname": "server102", "model": "vm", "version":
27+
"16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
28+
"address": "192.168.123.134", "bootupTimestamp": 1616680827.0, "timestamp": 1616681581705},
29+
{"namespace": "ospf-ibgp", "hostname": "exit01", "model": "VX", "version": "4.2.1",
30+
"vendor": "Cumulus", "architecture": "x86_64", "status": "alive", "address": "192.168.123.188",
31+
"bootupTimestamp": 1616681014.0, "timestamp": 1616681582726}, {"namespace": "ospf-ibgp",
32+
"hostname": "leaf02", "model": "VX", "version": "4.2.1", "vendor": "Cumulus",
33+
"architecture": "x86_64", "status": "alive", "address": "192.168.123.239", "bootupTimestamp":
34+
1616681016.0, "timestamp": 1616681582726}, {"namespace": "ospf-ibgp", "hostname":
35+
"leaf04", "model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture":
36+
"x86_64", "status": "alive", "address": "192.168.123.202", "bootupTimestamp":
37+
1616681014.0, "timestamp": 1616681582726}, {"namespace": "ospf-ibgp", "hostname":
38+
"leaf03", "model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture":
39+
"x86_64", "status": "alive", "address": "192.168.123.248", "bootupTimestamp":
40+
1616681014.0, "timestamp": 1616681582844}, {"namespace": "ospf-ibgp", "hostname":
41+
"spine01", "model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture":
42+
"x86_64", "status": "alive", "address": "192.168.123.135", "bootupTimestamp":
43+
1616681014.0, "timestamp": 1616681582844}, {"namespace": "ospf-ibgp", "hostname":
44+
"exit02", "model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture":
45+
"x86_64", "status": "alive", "address": "192.168.123.136", "bootupTimestamp":
46+
1616681015.0, "timestamp": 1616681582902}, {"namespace": "ospf-ibgp", "hostname":
47+
"spine02", "model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture":
48+
"x86_64", "status": "alive", "address": "192.168.123.16", "bootupTimestamp": 1616681014.0,
49+
"timestamp": 1616681582902}, {"namespace": "ospf-ibgp", "hostname": "leaf01",
50+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
51+
"status": "alive", "address": "192.168.123.30", "bootupTimestamp": 1616681014.0,
52+
"timestamp": 1616681582903}, {"namespace": "ospf-ibgp", "hostname": "internet",
53+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
54+
"status": "alive", "address": "192.168.123.237", "bootupTimestamp": 1616681016.0,
55+
"timestamp": 1616681582980}]'
56+
- command: device show --namespace=~^ospf-.* --format=json
57+
data-directory: tests/data/parquet/
58+
marks: device show
59+
output: '[{"namespace": "ospf-single", "hostname": "server102", "model": "vm", "version":
60+
"16.04.6 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
61+
"address": "10.255.2.68", "bootupTimestamp": 1616351835.0, "timestamp": 1616352402600},
62+
{"namespace": "ospf-single", "hostname": "server103", "model": "vm", "version":
63+
"16.04.6 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
64+
"address": "10.255.2.182", "bootupTimestamp": 1616351788.0, "timestamp": 1616352402601},
65+
{"namespace": "ospf-single", "hostname": "server101", "model": "vm", "version":
66+
"16.04.6 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
67+
"address": "10.255.2.78", "bootupTimestamp": 1616351831.0, "timestamp": 1616352402606},
68+
{"namespace": "ospf-single", "hostname": "server104", "model": "vm", "version":
69+
"16.04.6 LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive",
70+
"address": "10.255.2.219", "bootupTimestamp": 1616351815.0, "timestamp": 1616352402611},
71+
{"namespace": "ospf-single", "hostname": "edge01", "model": "vm", "version": "16.04.6
72+
LTS", "vendor": "Ubuntu", "architecture": "x86-64", "status": "alive", "address":
73+
"10.255.2.109", "bootupTimestamp": 1616351812.0, "timestamp": 1616352402798},
74+
{"namespace": "ospf-single", "hostname": "leaf01", "model": "VX", "version": "4.3.0",
75+
"vendor": "Cumulus", "architecture": "x86_64", "status": "alive", "address": "10.255.2.23",
76+
"bootupTimestamp": 1616351988.0, "timestamp": 1616352403833}, {"namespace": "ospf-single",
77+
"hostname": "spine02", "model": "VX", "version": "4.3.0", "vendor": "Cumulus",
78+
"architecture": "x86_64", "status": "alive", "address": "10.255.2.60", "bootupTimestamp":
79+
1616351988.0, "timestamp": 1616352403840}, {"namespace": "ospf-single", "hostname":
80+
"spine01", "model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture":
81+
"x86_64", "status": "alive", "address": "10.255.2.217", "bootupTimestamp": 1616351988.0,
82+
"timestamp": 1616352403840}, {"namespace": "ospf-single", "hostname": "internet",
83+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
84+
"status": "alive", "address": "10.255.2.239", "bootupTimestamp": 1616351807.0,
85+
"timestamp": 1616352403840}, {"namespace": "ospf-single", "hostname": "exit02",
86+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
87+
"status": "alive", "address": "10.255.2.41", "bootupTimestamp": 1616351989.0,
88+
"timestamp": 1616352403840}, {"namespace": "ospf-single", "hostname": "exit01",
89+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
90+
"status": "alive", "address": "10.255.2.88", "bootupTimestamp": 1616351989.0,
91+
"timestamp": 1616352403840}, {"namespace": "ospf-single", "hostname": "leaf02",
92+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
93+
"status": "alive", "address": "10.255.2.203", "bootupTimestamp": 1616351988.0,
94+
"timestamp": 1616352403841}, {"namespace": "ospf-single", "hostname": "leaf03",
95+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
96+
"status": "alive", "address": "10.255.2.254", "bootupTimestamp": 1616351988.0,
97+
"timestamp": 1616352403841}, {"namespace": "ospf-single", "hostname": "leaf04",
98+
"model": "VX", "version": "4.3.0", "vendor": "Cumulus", "architecture": "x86_64",
99+
"status": "alive", "address": "10.255.2.10", "bootupTimestamp": 1616351988.0,
100+
"timestamp": 1616352403841}, {"namespace": "ospf-ibgp", "hostname": "server103",
101+
"model": "vm", "version": "16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64",
102+
"status": "alive", "address": "192.168.123.150", "bootupTimestamp": 1616680845.0,
103+
"timestamp": 1616681581595}, {"namespace": "ospf-ibgp", "hostname": "server101",
104+
"model": "vm", "version": "16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64",
105+
"status": "alive", "address": "192.168.123.184", "bootupTimestamp": 1616680816.0,
106+
"timestamp": 1616681581632}, {"namespace": "ospf-ibgp", "hostname": "server104",
107+
"model": "vm", "version": "16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64",
108+
"status": "alive", "address": "192.168.123.197", "bootupTimestamp": 1616680858.0,
109+
"timestamp": 1616681581652}, {"namespace": "ospf-ibgp", "hostname": "edge01",
110+
"model": "vm", "version": "16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64",
111+
"status": "alive", "address": "192.168.123.180", "bootupTimestamp": 1616681014.0,
112+
"timestamp": 1616681581705}, {"namespace": "ospf-ibgp", "hostname": "server102",
113+
"model": "vm", "version": "16.04.7 LTS", "vendor": "Ubuntu", "architecture": "x86-64",
114+
"status": "alive", "address": "192.168.123.134", "bootupTimestamp": 1616680827.0,
115+
"timestamp": 1616681581705}, {"namespace": "ospf-ibgp", "hostname": "leaf04",
116+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
117+
"status": "alive", "address": "192.168.123.202", "bootupTimestamp": 1616681014.0,
118+
"timestamp": 1616681582726}, {"namespace": "ospf-ibgp", "hostname": "leaf02",
119+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
120+
"status": "alive", "address": "192.168.123.239", "bootupTimestamp": 1616681016.0,
121+
"timestamp": 1616681582726}, {"namespace": "ospf-ibgp", "hostname": "exit01",
122+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
123+
"status": "alive", "address": "192.168.123.188", "bootupTimestamp": 1616681014.0,
124+
"timestamp": 1616681582726}, {"namespace": "ospf-ibgp", "hostname": "leaf03",
125+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
126+
"status": "alive", "address": "192.168.123.248", "bootupTimestamp": 1616681014.0,
127+
"timestamp": 1616681582844}, {"namespace": "ospf-ibgp", "hostname": "spine01",
128+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
129+
"status": "alive", "address": "192.168.123.135", "bootupTimestamp": 1616681014.0,
130+
"timestamp": 1616681582844}, {"namespace": "ospf-ibgp", "hostname": "exit02",
131+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
132+
"status": "alive", "address": "192.168.123.136", "bootupTimestamp": 1616681015.0,
133+
"timestamp": 1616681582902}, {"namespace": "ospf-ibgp", "hostname": "spine02",
134+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
135+
"status": "alive", "address": "192.168.123.16", "bootupTimestamp": 1616681014.0,
136+
"timestamp": 1616681582902}, {"namespace": "ospf-ibgp", "hostname": "leaf01",
137+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
138+
"status": "alive", "address": "192.168.123.30", "bootupTimestamp": 1616681014.0,
139+
"timestamp": 1616681582903}, {"namespace": "ospf-ibgp", "hostname": "internet",
140+
"model": "VX", "version": "4.2.1", "vendor": "Cumulus", "architecture": "x86_64",
141+
"status": "alive", "address": "192.168.123.237", "bootupTimestamp": 1616681016.0,
142+
"timestamp": 1616681582980}]'

0 commit comments

Comments
 (0)