Skip to content

Commit 8c8b09c

Browse files
author
Anthony House
committed
Add tests with filters
1 parent e5593cf commit 8c8b09c

File tree

12 files changed

+504
-57
lines changed

12 files changed

+504
-57
lines changed

suzieq/poller/controller/source/nautobot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def parse_inventory(self, inventory_list: list) -> Dict:
175175
ipv6 = device.primary_ip6.address if device.primary_ip6 else None
176176
hostname = device.name
177177
site_name = device.location.name
178-
if self._namespace == "nautobot-location-name":
178+
if self._namespace == "group-by-location":
179179
namespace = site_name
180180
else:
181181
namespace = self._namespace

tests/unit/poller/controller/sources/nautobot/fixtures.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
}
2222

23-
RESP1 = {
23+
BASE = {
2424
"circuits": "http://localhost:8080/api/circuits/",
2525
"dcim": "http://localhost:8080/api/dcim/",
2626
"extras": "http://localhost:8080/api/extras/",
@@ -33,7 +33,7 @@
3333
"virtualization": "http://localhost:8080/api/virtualization/"
3434
}
3535

36-
RESP2 = {'count': 3,
36+
ALL_DEVICES = {'count': 3,
3737
'next': None,
3838
'previous': None,
3939
'results': [{'id': '9dacbca0-6f98-47f8-adcb-b501a0ff7769',
@@ -103,7 +103,7 @@
103103
'custom_fields': {},
104104
'parent_bay': None}]}
105105

106-
RESP3 = {'id': '83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1',
106+
DEVICE_1_IP = {'id': '83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1',
107107
'object_type': 'ipam.ipaddress',
108108
'display': '172.100.100.10/24',
109109
'url': 'http://localhost:8080/api/ipam/ip-addresses/83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1/',
@@ -135,7 +135,7 @@
135135
'url': 'http://localhost:8080/api/dcim/interfaces/74747faa-8068-4bf9-beac-624873012131/'}],
136136
'vm_interfaces': []}
137137

138-
RESP4 = {'id': 'e3c17e29-89de-49ef-809e-7540a309548d',
138+
DEVICE_1_LOCATION = {'id': 'e3c17e29-89de-49ef-809e-7540a309548d',
139139
'object_type': 'dcim.location',
140140
'display': 'North America → Site1 = Chicago, IL, CH1-EQ-COLO1',
141141
'url': 'http://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/',
@@ -176,13 +176,16 @@
176176
'notes_url': 'http://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/notes/',
177177
'custom_fields': {'remedy_id': None}}
178178

179-
TEST_URLS = {
180-
"http://127.0.0.1:8080/api/": RESP1,
181-
"http://127.0.0.1:8080/api/dcim/devices/": RESP2,
182-
"http://localhost:8080/api/ipam/ip-addresses/83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1/": RESP3,
183-
"http://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/": RESP4,
184-
"https://127.0.0.1:8080/api/": RESP1,
185-
"https://127.0.0.1:8080/api/dcim/devices/": RESP2,
186-
"https://localhost:8080/api/ipam/ip-addresses/83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1/": RESP3,
187-
"https://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/": RESP4,
179+
TEST1_URLS = {
180+
"http://127.0.0.1:8080/api/": BASE,
181+
"http://127.0.0.1:8080/api/dcim/devices/": ALL_DEVICES,
182+
"http://localhost:8080/api/ipam/ip-addresses/83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1/": DEVICE_1_IP,
183+
"http://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/": DEVICE_1_LOCATION,
184+
}
185+
186+
TEST2_URLS = {
187+
"https://127.0.0.1:8080/api/": BASE,
188+
"https://127.0.0.1:8080/api/dcim/devices/": ALL_DEVICES,
189+
"http://localhost:8080/api/ipam/ip-addresses/83dbe0a9-cc69-4a71-9d7e-ebe9dc5b85e1/": DEVICE_1_IP,
190+
"http://localhost:8080/api/dcim/locations/e3c17e29-89de-49ef-809e-7540a309548d/": DEVICE_1_LOCATION,
188191
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"count": 2,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": "158451e2-7dc1-492c-b69b-f29341ebd8f8",
8+
"object_type": "dcim.device",
9+
"display": "ang01-edge-01",
10+
"url": "https://127.0.0.1:8080/api/dcim/devices/158451e2-7dc1-492c-b69b-f29341ebd8f8/",
11+
"natural_slug": "ang01-edge-01_nautobot-baseball-stadiums_ang01_united-states_americas_1584",
12+
"face": { "value": "front", "label": "Front" },
13+
"local_config_context_data": null,
14+
"local_config_context_data_owner_object_id": null,
15+
"name": "ang01-edge-01",
16+
"serial": "",
17+
"asset_tag": null,
18+
"position": 40,
19+
"device_redundancy_group_priority": null,
20+
"vc_position": null,
21+
"vc_priority": null,
22+
"comments": "",
23+
"local_config_context_schema": null,
24+
"local_config_context_data_owner_content_type": null,
25+
"device_type": {
26+
"id": "e3fc837a-2474-4a94-b099-bd90a2d39468",
27+
"object_type": "dcim.devicetype",
28+
"url": "https://127.0.0.1:8080/api/dcim/device-types/e3fc837a-2474-4a94-b099-bd90a2d39468/"
29+
},
30+
"status": {
31+
"id": "9f38bab4-4b47-4e77-b50c-fda62817b2db",
32+
"object_type": "extras.status",
33+
"url": "https://127.0.0.1:8080/api/extras/statuses/9f38bab4-4b47-4e77-b50c-fda62817b2db/"
34+
},
35+
"role": {
36+
"id": "8adc71b7-f439-42bf-b1af-4d0f20f76907",
37+
"object_type": "extras.role",
38+
"url": "https://127.0.0.1:8080/api/extras/roles/8adc71b7-f439-42bf-b1af-4d0f20f76907/"
39+
},
40+
"tenant": {
41+
"id": "16c1e4e6-fe62-4947-92ba-f410c2b71295",
42+
"object_type": "tenancy.tenant",
43+
"url": "https://127.0.0.1:8080/api/tenancy/tenants/16c1e4e6-fe62-4947-92ba-f410c2b71295/"
44+
},
45+
"platform": {
46+
"id": "f48fd9e2-45c5-4c2f-aa54-28964edb3e1e",
47+
"object_type": "dcim.platform",
48+
"url": "https://127.0.0.1:8080/api/dcim/platforms/f48fd9e2-45c5-4c2f-aa54-28964edb3e1e/"
49+
},
50+
"location": {
51+
"id": "279b30b2-7aee-45be-8086-9d151ce22799",
52+
"object_type": "dcim.location",
53+
"url": "https://127.0.0.1:8080/api/dcim/locations/279b30b2-7aee-45be-8086-9d151ce22799/"
54+
},
55+
"rack": {
56+
"id": "7a79f421-556b-4ea1-a359-eb9c71d923f8",
57+
"object_type": "dcim.rack",
58+
"url": "https://127.0.0.1:8080/api/dcim/racks/7a79f421-556b-4ea1-a359-eb9c71d923f8/"
59+
},
60+
"primary_ip4": {
61+
"id": "fe06d6c1-b233-4499-b5e9-f36af5a72dc3",
62+
"object_type": "ipam.ipaddress",
63+
"url": "https://127.0.0.1:8080/api/ipam/ip-addresses/fe06d6c1-b233-4499-b5e9-f36af5a72dc3/"
64+
},
65+
"primary_ip6": null,
66+
"cluster": null,
67+
"virtual_chassis": null,
68+
"device_redundancy_group": null,
69+
"software_version": null,
70+
"secrets_group": null,
71+
"controller_managed_device_group": null,
72+
"software_image_files": [],
73+
"created": "2023-09-21T00:00:00Z",
74+
"last_updated": "2023-09-21T19:50:28.137319Z",
75+
"tags": [],
76+
"notes_url": "https://127.0.0.1:8080/api/dcim/devices/158451e2-7dc1-492c-b69b-f29341ebd8f8/notes/",
77+
"custom_fields": {},
78+
"parent_bay": null
79+
},
80+
{
81+
"id": "23e698fe-9102-498e-ac6b-84616aad8437",
82+
"object_type": "dcim.device",
83+
"display": "azd01-leaf-07",
84+
"url": "https://127.0.0.1:8080/api/dcim/devices/23e698fe-9102-498e-ac6b-84616aad8437/",
85+
"natural_slug": "azd01-leaf-07_nautobot-baseball-stadiums_azd01_united-states_americas_23e6",
86+
"face": { "value": "front", "label": "Front" },
87+
"local_config_context_data": null,
88+
"local_config_context_data_owner_object_id": null,
89+
"name": "azd01-leaf-07",
90+
"serial": "",
91+
"asset_tag": null,
92+
"position": 44,
93+
"device_redundancy_group_priority": null,
94+
"vc_position": null,
95+
"vc_priority": null,
96+
"comments": "",
97+
"local_config_context_schema": null,
98+
"local_config_context_data_owner_content_type": null,
99+
"device_type": {
100+
"id": "74cf95a8-4233-46b9-a740-fba4f5dc88d3",
101+
"object_type": "dcim.devicetype",
102+
"url": "https://127.0.0.1:8080/api/dcim/device-types/74cf95a8-4233-46b9-a740-fba4f5dc88d3/"
103+
},
104+
"status": {
105+
"id": "9f38bab4-4b47-4e77-b50c-fda62817b2db",
106+
"object_type": "extras.status",
107+
"url": "https://127.0.0.1:8080/api/extras/statuses/9f38bab4-4b47-4e77-b50c-fda62817b2db/"
108+
},
109+
"role": {
110+
"id": "869267d8-7d75-4bd3-8a9e-5e6adcf200f6",
111+
"object_type": "extras.role",
112+
"url": "https://127.0.0.1:8080/api/extras/roles/869267d8-7d75-4bd3-8a9e-5e6adcf200f6/"
113+
},
114+
"tenant": {
115+
"id": "16c1e4e6-fe62-4947-92ba-f410c2b71295",
116+
"object_type": "tenancy.tenant",
117+
"url": "https://127.0.0.1:8080/api/tenancy/tenants/16c1e4e6-fe62-4947-92ba-f410c2b71295/"
118+
},
119+
"platform": {
120+
"id": "f48fd9e2-45c5-4c2f-aa54-28964edb3e1e",
121+
"object_type": "dcim.platform",
122+
"url": "https://127.0.0.1:8080/api/dcim/platforms/f48fd9e2-45c5-4c2f-aa54-28964edb3e1e/"
123+
},
124+
"location": {
125+
"id": "f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6",
126+
"object_type": "dcim.location",
127+
"url": "https://127.0.0.1:8080/api/dcim/locations/f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/"
128+
},
129+
"rack": {
130+
"id": "f16ef563-b764-4dcd-9940-d498c67b60a4",
131+
"object_type": "dcim.rack",
132+
"url": "https://127.0.0.1:8080/api/dcim/racks/f16ef563-b764-4dcd-9940-d498c67b60a4/"
133+
},
134+
"primary_ip4": {
135+
"id": "94f6cbb7-2897-4b9e-91ef-573f9c0b44d8",
136+
"object_type": "ipam.ipaddress",
137+
"url": "https://127.0.0.1:8080/api/ipam/ip-addresses/94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/"
138+
},
139+
"primary_ip6": null,
140+
"cluster": null,
141+
"virtual_chassis": null,
142+
"device_redundancy_group": null,
143+
"software_version": null,
144+
"secrets_group": null,
145+
"controller_managed_device_group": null,
146+
"software_image_files": [],
147+
"created": "2023-09-21T00:00:00Z",
148+
"last_updated": "2023-09-21T19:50:42.066475Z",
149+
"tags": [],
150+
"notes_url": "https://127.0.0.1:8080/api/dcim/devices/23e698fe-9102-498e-ac6b-84616aad8437/notes/",
151+
"custom_fields": {},
152+
"parent_bay": null
153+
}
154+
]
155+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"ANG01.10.31.128.1.22": {
3+
"address": "10.31.128.1",
4+
"devtype": null,
5+
"enable_password": null,
6+
"hostname": "ang01-edge-01",
7+
"ignore_known_hosts": false,
8+
"jump_host": null,
9+
"jump_host_key_file": null,
10+
"namespace": "ANG01",
11+
"passphrase": null,
12+
"password": "password",
13+
"per_cmd_auth": true,
14+
"port": 22,
15+
"retries_on_auth_fail": 0,
16+
"slow_host": false,
17+
"ssh_keyfile": null,
18+
"transport": "ssh",
19+
"username": "username"
20+
},
21+
"AZD01.10.33.128.9.22": {
22+
"address": "10.33.128.9",
23+
"devtype": null,
24+
"enable_password": null,
25+
"hostname": "azd01-leaf-07",
26+
"ignore_known_hosts": false,
27+
"jump_host": null,
28+
"jump_host_key_file": null,
29+
"namespace": "AZD01",
30+
"passphrase": null,
31+
"password": "password",
32+
"per_cmd_auth": true,
33+
"port": 22,
34+
"retries_on_auth_fail": 0,
35+
"slow_host": false,
36+
"ssh_keyfile": null,
37+
"transport": "ssh",
38+
"username": "username"
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"nautobot-ns.10.31.128.1.22": {
3+
"address": "10.31.128.1",
4+
"devtype": null,
5+
"enable_password": null,
6+
"hostname": "ang01-edge-01",
7+
"ignore_known_hosts": false,
8+
"jump_host": null,
9+
"jump_host_key_file": null,
10+
"namespace": "nautobot-ns",
11+
"passphrase": null,
12+
"password": "password",
13+
"per_cmd_auth": true,
14+
"port": 22,
15+
"retries_on_auth_fail": 0,
16+
"slow_host": false,
17+
"ssh_keyfile": null,
18+
"transport": "ssh",
19+
"username": "username"
20+
},
21+
"nautobot-ns.10.33.128.9.22": {
22+
"address": "10.33.128.9",
23+
"devtype": null,
24+
"enable_password": null,
25+
"hostname": "azd01-leaf-07",
26+
"ignore_known_hosts": false,
27+
"jump_host": null,
28+
"jump_host_key_file": null,
29+
"namespace": "nautobot-ns",
30+
"passphrase": null,
31+
"password": "password",
32+
"per_cmd_auth": true,
33+
"port": 22,
34+
"retries_on_auth_fail": 0,
35+
"slow_host": false,
36+
"ssh_keyfile": null,
37+
"transport": "ssh",
38+
"username": "username"
39+
}
40+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"count": 1,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": "23e698fe-9102-498e-ac6b-84616aad8437",
8+
"object_type": "dcim.device",
9+
"display": "azd01-leaf-07",
10+
"url": "https://127.0.0.1:8080/api/dcim/devices/23e698fe-9102-498e-ac6b-84616aad8437/",
11+
"natural_slug": "azd01-leaf-07_nautobot-baseball-stadiums_azd01_united-states_americas_23e6",
12+
"face": { "value": "front", "label": "Front" },
13+
"local_config_context_data": null,
14+
"local_config_context_data_owner_object_id": null,
15+
"name": "azd01-leaf-07",
16+
"serial": "",
17+
"asset_tag": null,
18+
"position": 44,
19+
"device_redundancy_group_priority": null,
20+
"vc_position": null,
21+
"vc_priority": null,
22+
"comments": "",
23+
"local_config_context_schema": null,
24+
"local_config_context_data_owner_content_type": null,
25+
"device_type": {
26+
"id": "74cf95a8-4233-46b9-a740-fba4f5dc88d3",
27+
"object_type": "dcim.devicetype",
28+
"url": "https://127.0.0.1:8080/api/dcim/device-types/74cf95a8-4233-46b9-a740-fba4f5dc88d3/"
29+
},
30+
"status": {
31+
"id": "9f38bab4-4b47-4e77-b50c-fda62817b2db",
32+
"object_type": "extras.status",
33+
"url": "https://127.0.0.1:8080/api/extras/statuses/9f38bab4-4b47-4e77-b50c-fda62817b2db/"
34+
},
35+
"role": {
36+
"id": "869267d8-7d75-4bd3-8a9e-5e6adcf200f6",
37+
"object_type": "extras.role",
38+
"url": "https://127.0.0.1:8080/api/extras/roles/869267d8-7d75-4bd3-8a9e-5e6adcf200f6/"
39+
},
40+
"tenant": {
41+
"id": "16c1e4e6-fe62-4947-92ba-f410c2b71295",
42+
"object_type": "tenancy.tenant",
43+
"url": "https://127.0.0.1:8080/api/tenancy/tenants/16c1e4e6-fe62-4947-92ba-f410c2b71295/"
44+
},
45+
"platform": {
46+
"id": "f48fd9e2-45c5-4c2f-aa54-28964edb3e1e",
47+
"object_type": "dcim.platform",
48+
"url": "https://127.0.0.1:8080/api/dcim/platforms/f48fd9e2-45c5-4c2f-aa54-28964edb3e1e/"
49+
},
50+
"location": {
51+
"id": "f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6",
52+
"object_type": "dcim.location",
53+
"url": "https://127.0.0.1:8080/api/dcim/locations/f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/"
54+
},
55+
"rack": {
56+
"id": "f16ef563-b764-4dcd-9940-d498c67b60a4",
57+
"object_type": "dcim.rack",
58+
"url": "https://127.0.0.1:8080/api/dcim/racks/f16ef563-b764-4dcd-9940-d498c67b60a4/"
59+
},
60+
"primary_ip4": {
61+
"id": "94f6cbb7-2897-4b9e-91ef-573f9c0b44d8",
62+
"object_type": "ipam.ipaddress",
63+
"url": "https://127.0.0.1:8080/api/ipam/ip-addresses/94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/"
64+
},
65+
"primary_ip6": null,
66+
"cluster": null,
67+
"virtual_chassis": null,
68+
"device_redundancy_group": null,
69+
"software_version": null,
70+
"secrets_group": null,
71+
"controller_managed_device_group": null,
72+
"software_image_files": [],
73+
"created": "2023-09-21T00:00:00Z",
74+
"last_updated": "2024-04-08T09:34:31.297519Z",
75+
"tags": [],
76+
"notes_url": "https://127.0.0.1:8080/api/dcim/devices/23e698fe-9102-498e-ac6b-84616aad8437/notes/",
77+
"custom_fields": { "test_id": null },
78+
"parent_bay": null
79+
}
80+
]
81+
}

0 commit comments

Comments
 (0)