Skip to content

Commit e31b9bf

Browse files
Bugfix: Inventory - ValueError max() if either no devices or vms exist (#223)
1 parent a700b92 commit e31b9bf

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def query_string(value, separator="&"):
302302
return separator + query_key + "=" + str(value)
303303

304304
# Calculate how many queries we can do per API call to stay within max_url_length
305-
largest_value = str(max(query_values)) # values are always id ints
305+
largest_value = str(max(query_values, default=0)) # values are always id ints
306306
length_per_value = len(query_string(largest_value))
307307
chunk_size = math.floor((self.max_uri_length - len(api_url)) / length_per_value)
308308

tests/unit/inventory/test_data/get_resource_list_chunked/data.json

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
"api_url": "https://netbox:1234?limit=0",
44
"max_uri_length": 35,
55
"query_key": "key",
6-
"query_values": [1, 2, 3, 4],
6+
"query_values": [
7+
1,
8+
2,
9+
3,
10+
4
11+
],
712
"expected": [
813
"https://netbox:1234?limit=0&key=1",
914
"https://netbox:1234?limit=0&key=2",
@@ -15,7 +20,12 @@
1520
"api_url": "https://netbox:1234?limit=0",
1621
"max_uri_length": -5,
1722
"query_key": "key",
18-
"query_values": [1, 2, 3, 4],
23+
"query_values": [
24+
1,
25+
2,
26+
3,
27+
4
28+
],
1929
"expected": [
2030
"https://netbox:1234?limit=0&key=1",
2131
"https://netbox:1234?limit=0&key=2",
@@ -27,7 +37,12 @@
2737
"api_url": "https://netbox:1234?limit=0",
2838
"max_uri_length": 50,
2939
"query_key": "key",
30-
"query_values": [1, 2, 3000, 4],
40+
"query_values": [
41+
1,
42+
2,
43+
3000,
44+
4
45+
],
3146
"expected": [
3247
"https://netbox:1234?limit=0&key=1&key=2",
3348
"https://netbox:1234?limit=0&key=3000&key=4"
@@ -37,10 +52,22 @@
3752
"api_url": "https://netbox:1234",
3853
"max_uri_length": 42,
3954
"query_key": "key",
40-
"query_values": [1, 2, 3, 4],
55+
"query_values": [
56+
1,
57+
2,
58+
3,
59+
4
60+
],
4161
"expected": [
4262
"https://netbox:1234?key=1&key=2&key=3",
4363
"https://netbox:1234?key=4"
4464
]
65+
},
66+
{
67+
"api_url": "https://netbox:1234?limit=0",
68+
"max_uri_length": 4000,
69+
"query_key": "key",
70+
"query_values": [],
71+
"expected": []
4572
}
46-
]
73+
]

0 commit comments

Comments
 (0)