diff --git a/nornir_netbox/plugins/inventory/netbox.py b/nornir_netbox/plugins/inventory/netbox.py index e93910a..3290973 100644 --- a/nornir_netbox/plugins/inventory/netbox.py +++ b/nornir_netbox/plugins/inventory/netbox.py @@ -86,13 +86,20 @@ def load(self) -> Inventory: data["site"] = device.get("site", {}).get("slug") data["role"] = device.get("device_role", {}).get("slug") data["model"] = device.get("device_type", {}).get("slug") - if device.get("platform"): - platform = device.get("platform", {}).get("slug") + platform = ( + device["platform"]["slug"] + if isinstance(device["platform"], dict) + else device["platform"] + ) else: data["site"] = device.get("site", {}).get("name") data["role"] = device.get("device_role") data["model"] = device.get("device_type") - platform = device.get("platform") + platform = ( + device["platform"]["name"] + if isinstance(device["platform"], dict) + else device["platform"] + ) hostname = None if device.get("primary_ip"): @@ -190,10 +197,16 @@ def load(self) -> Inventory: if device.get("name") is not None: hostname = device["name"] + platform = ( + device["platform"]["name"] + if isinstance(device["platform"], dict) + else device["platform"] + ) + host = Host( name=device.get("name") or str(device.get("id")), hostname=hostname, - platform=device.get("platform"), + platform=platform, data=data, ) diff --git a/tests/NBInventory/2.3.5/expected.json b/tests/NBInventory/2.3.5/expected.json new file mode 100644 index 0000000..b788df7 --- /dev/null +++ b/tests/NBInventory/2.3.5/expected.json @@ -0,0 +1,94 @@ +{ + "hosts": { + "1-Core": { + "name": "1-Core", + "port": null, + "hostname": "10.0.1.1", + "username": null, + "password": null, + "platform": "junos", + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "mx480" + }, + "connection_options": { + }, + "groups": [] + }, + "2-Distribution": { + "name": "2-Distribution", + "port": null, + "hostname": "172.16.2.1", + "username": null, + "password": null, + "platform": null, + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "ex4550-32f" + }, + "connection_options": { + }, + "groups": [] + }, + "3-Access": { + "name": "3-Access", + "port": null, + "hostname": "192.168.3.1", + "username": null, + "password": null, + "platform": "ios", + "data": { + "user_defined": 1, + "serial": "", + "vendor": "Cisco", + "asset_tag": null, + "site": "san-jose-ca", + "role": "sw", + "model": "3650-48tq-l" + }, + "connection_options": { + }, + "groups": [] + }, + "4": { + "name": "4", + "port": null, + "hostname": "10.0.1.4", + "username": null, + "password": null, + "platform": "junos", + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "mx480" + }, + "connection_options": { + }, + "groups": [] + } + }, + "groups": { + }, + "defaults": { + "port": null, + "hostname": null, + "username": null, + "password": null, + "platform": null, + "data": { + }, + "connection_options": { + } + } +} diff --git a/tests/NBInventory/2.8.9/expected.json b/tests/NBInventory/2.8.9/expected.json new file mode 100644 index 0000000..b788df7 --- /dev/null +++ b/tests/NBInventory/2.8.9/expected.json @@ -0,0 +1,94 @@ +{ + "hosts": { + "1-Core": { + "name": "1-Core", + "port": null, + "hostname": "10.0.1.1", + "username": null, + "password": null, + "platform": "junos", + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "mx480" + }, + "connection_options": { + }, + "groups": [] + }, + "2-Distribution": { + "name": "2-Distribution", + "port": null, + "hostname": "172.16.2.1", + "username": null, + "password": null, + "platform": null, + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "ex4550-32f" + }, + "connection_options": { + }, + "groups": [] + }, + "3-Access": { + "name": "3-Access", + "port": null, + "hostname": "192.168.3.1", + "username": null, + "password": null, + "platform": "ios", + "data": { + "user_defined": 1, + "serial": "", + "vendor": "Cisco", + "asset_tag": null, + "site": "san-jose-ca", + "role": "sw", + "model": "3650-48tq-l" + }, + "connection_options": { + }, + "groups": [] + }, + "4": { + "name": "4", + "port": null, + "hostname": "10.0.1.4", + "username": null, + "password": null, + "platform": "junos", + "data": { + "serial": "", + "vendor": "Juniper", + "asset_tag": null, + "site": "sunnyvale-ca", + "role": "rt", + "model": "mx480" + }, + "connection_options": { + }, + "groups": [] + } + }, + "groups": { + }, + "defaults": { + "port": null, + "hostname": null, + "username": null, + "password": null, + "platform": null, + "data": { + }, + "connection_options": { + } + } +} diff --git a/tests/NBInventory/expected.json b/tests/NBInventory/expected.json deleted file mode 100644 index 7dac888..0000000 --- a/tests/NBInventory/expected.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "hosts": { - "1-Core": { - "name": "1-Core", - "port": null, - "hostname": "10.0.1.1", - "username": null, - "password": null, - "platform": null, - "data": { - "serial": "", - "vendor": "Juniper", - "asset_tag": null, - "site": "sunnyvale-ca", - "role": "rt", - "model": "mx480" - }, - "connection_options": {}, - "groups": [] - }, - "2-Distribution": { - "name": "2-Distribution", - "port": null, - "hostname": "172.16.2.1", - "username": null, - "password": null, - "platform": null, - "data": { - "serial": "", - "vendor": "Juniper", - "asset_tag": null, - "site": "sunnyvale-ca", - "role": "rt", - "model": "ex4550-32f" - }, - "connection_options": {}, - "groups": [] - }, - "3-Access": { - "name": "3-Access", - "port": null, - "hostname": "192.168.3.1", - "username": null, - "password": null, - "platform": null, - "data": { - "user_defined": 1, - "serial": "", - "vendor": "Cisco", - "asset_tag": null, - "site": "san-jose-ca", - "role": "sw", - "model": "3650-48tq-l" - }, - "connection_options": {}, - "groups": [] - }, - "4": { - "name": "4", - "port": null, - "hostname": "10.0.1.4", - "username": null, - "password": null, - "platform": null, - "data": { - "serial": "", - "vendor": "Juniper", - "asset_tag": null, - "site": "sunnyvale-ca", - "role": "rt", - "model": "mx480" - }, - "connection_options": {}, - "groups": [] - } - }, - "groups": {}, - "defaults": { - "port": null, - "hostname": null, - "username": null, - "password": null, - "platform": null, - "data": {}, - "connection_options": {} - } -} diff --git a/tests/NetBoxInventory2/expected.json b/tests/NetBoxInventory2/2.3.5/expected.json similarity index 98% rename from tests/NetBoxInventory2/expected.json rename to tests/NetBoxInventory2/2.3.5/expected.json index d6b029d..4176c21 100644 --- a/tests/NetBoxInventory2/expected.json +++ b/tests/NetBoxInventory2/2.3.5/expected.json @@ -24,7 +24,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { @@ -65,7 +65,7 @@ }, "name":"1-Core", "hostname": "10.0.1.1", - "platform": null, + "platform": "junos", "port": null, "username": null, "password": null, @@ -168,7 +168,7 @@ "slug": "sw" }, "tenant": null, - "platform": null, + "platform": "ios", "serial": "", "asset_tag": null, "site": { @@ -211,7 +211,7 @@ }, "name":"3-Access", "hostname": "192.168.3.1", - "platform": null, + "platform": "ios", "port": null, "username": null, "password": null, @@ -242,7 +242,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { @@ -283,7 +283,7 @@ }, "name":"4", "hostname": "10.0.1.4", - "platform": null, + "platform": "junos", "port": null, "username": null, "password": null, diff --git a/tests/NetboxInventory2/expected.json b/tests/NetBoxInventory2/2.8.9/expected.json similarity index 94% rename from tests/NetboxInventory2/expected.json rename to tests/NetBoxInventory2/2.8.9/expected.json index d6b029d..cff9be3 100644 --- a/tests/NetboxInventory2/expected.json +++ b/tests/NetBoxInventory2/2.8.9/expected.json @@ -24,8 +24,13 @@ "slug": "rt" }, "tenant": null, - "platform": null, - "serial": "", + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", "asset_tag": null, "site": { "id": 3, @@ -65,7 +70,7 @@ }, "name":"1-Core", "hostname": "10.0.1.1", - "platform": null, + "platform": "junos", "port": null, "username": null, "password": null, @@ -168,8 +173,13 @@ "slug": "sw" }, "tenant": null, - "platform": null, - "serial": "", + "platform": { + "id": 2, + "url": "http://localhost:8080/api/dcim/platforms/2/", + "name": "ios", + "slug": "ios" + }, + "serial": "", "asset_tag": null, "site": { "id": 2, @@ -211,7 +221,7 @@ }, "name":"3-Access", "hostname": "192.168.3.1", - "platform": null, + "platform": "ios", "port": null, "username": null, "password": null, @@ -242,9 +252,14 @@ "slug": "rt" }, "tenant": null, - "platform": null, - "serial": "", - "asset_tag": null, + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", + "asset_tag": null, "site": { "id": 3, "url": "http://localhost:8080/api/dcim/sites/3/", @@ -283,7 +298,7 @@ }, "name":"4", "hostname": "10.0.1.4", - "platform": null, + "platform": "junos", "port": null, "username": null, "password": null, diff --git a/tests/mocked/devices-0.json b/tests/mocked/2.3.5/devices-0.json similarity index 98% rename from tests/mocked/devices-0.json rename to tests/mocked/2.3.5/devices-0.json index 27ed082..e8f1dc2 100644 --- a/tests/mocked/devices-0.json +++ b/tests/mocked/2.3.5/devices-0.json @@ -26,7 +26,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { diff --git a/tests/mocked/devices-1.json b/tests/mocked/2.3.5/devices-1.json similarity index 100% rename from tests/mocked/devices-1.json rename to tests/mocked/2.3.5/devices-1.json diff --git a/tests/mocked/devices-2.json b/tests/mocked/2.3.5/devices-2.json similarity index 98% rename from tests/mocked/devices-2.json rename to tests/mocked/2.3.5/devices-2.json index 48abec4..205a6eb 100644 --- a/tests/mocked/devices-2.json +++ b/tests/mocked/2.3.5/devices-2.json @@ -26,7 +26,7 @@ "slug": "sw" }, "tenant": null, - "platform": null, + "platform": "ios", "serial": "", "asset_tag": null, "site": { @@ -88,7 +88,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { diff --git a/tests/mocked/devices.json b/tests/mocked/2.3.5/devices.json similarity index 98% rename from tests/mocked/devices.json rename to tests/mocked/2.3.5/devices.json index 5399ab5..68ff341 100644 --- a/tests/mocked/devices.json +++ b/tests/mocked/2.3.5/devices.json @@ -26,7 +26,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { @@ -150,7 +150,7 @@ "slug": "sw" }, "tenant": null, - "platform": null, + "platform": "ios", "serial": "", "asset_tag": null, "site": { @@ -212,7 +212,7 @@ "slug": "rt" }, "tenant": null, - "platform": null, + "platform": "junos", "serial": "", "asset_tag": null, "site": { diff --git a/tests/mocked/2.8.9/devices-0.json b/tests/mocked/2.8.9/devices-0.json new file mode 100644 index 0000000..e804b96 --- /dev/null +++ b/tests/mocked/2.8.9/devices-0.json @@ -0,0 +1,74 @@ +{ + "count": 1, + "next": "http://localhost:8080/api/dcim/devices/?limit=0&offset=1", + "previous": null, + "results": [ + { + "id": 1, + "name": "1-Core", + "display_name": "1-Core", + "device_type": { + "id": 11, + "url": "http://localhost:8080/api/dcim/device-types/11/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "MX480", + "slug": "mx480" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/1/", + "family": 4, + "address": "10.0.1.1/32" + }, + "primary_ip4": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/1/", + "family": 4, + "address": "10.0.1.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": {}, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.742412Z" + } + ] +} diff --git a/tests/mocked/2.8.9/devices-1.json b/tests/mocked/2.8.9/devices-1.json new file mode 100644 index 0000000..e5a3de5 --- /dev/null +++ b/tests/mocked/2.8.9/devices-1.json @@ -0,0 +1,69 @@ +{ + "count": 1, + "next": "http://localhost:8080/api/dcim/devices/?limit=0&offset=2", + "previous": "http://localhost:8080/api/dcim/devices/?limit=0&offset=0", + "results": [ + { + "id": 2, + "name": "2-Distribution", + "display_name": "2-Distribution", + "device_type": { + "id": 9, + "url": "http://localhost:8080/api/dcim/device-types/9/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "EX4550-32F", + "slug": "ex4550-32f" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": null, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 2, + "url": "http://localhost:8080/api/ipam/ip-addresses/2/", + "family": 4, + "address": "172.16.2.1/32" + }, + "primary_ip4": { + "id": 2, + "url": "http://localhost:8080/api/ipam/ip-addresses/2/", + "family": 4, + "address": "172.16.2.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": {}, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.802934Z" + } + ] +} diff --git a/tests/mocked/2.8.9/devices-2.json b/tests/mocked/2.8.9/devices-2.json new file mode 100644 index 0000000..7331d95 --- /dev/null +++ b/tests/mocked/2.8.9/devices-2.json @@ -0,0 +1,141 @@ +{ + "count": 2, + "next": null, + "previous": "http://localhost:8080/api/dcim/devices/?limit=0&offset=1", + "results": [ + { + "id": 3, + "name": "3-Access", + "display_name": "3-Access", + "device_type": { + "id": 2, + "url": "http://localhost:8080/api/dcim/device-types/2/", + "manufacturer": { + "id": 2, + "url": "http://localhost:8080/api/dcim/manufacturers/2/", + "name": "Cisco", + "slug": "cisco" + }, + "model": "3650-48TQ-L", + "slug": "3650-48tq-l" + }, + "device_role": { + "id": 2, + "url": "http://localhost:8080/api/dcim/device-roles/2/", + "name": "Switch", + "slug": "sw" + }, + "tenant": null, + "platform": { + "id": 2, + "url": "http://localhost:8080/api/dcim/platforms/2/", + "name": "ios", + "slug": "ios" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 2, + "url": "http://localhost:8080/api/dcim/sites/2/", + "name": "San Jose, CA", + "slug": "san-jose-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 3, + "url": "http://localhost:8080/api/ipam/ip-addresses/3/", + "family": 4, + "address": "192.168.3.1/32" + }, + "primary_ip4": { + "id": 3, + "url": "http://localhost:8080/api/ipam/ip-addresses/3/", + "family": 4, + "address": "192.168.3.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": {"user_defined": 1}, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.866133Z" + }, + { + "id": 4, + "name": null, + "display_name": "MX480", + "device_type": { + "id": 11, + "url": "http://localhost:8080/api/dcim/device-types/11/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "MX480", + "slug": "mx480" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 4, + "url": "http://localhost:8080/api/ipam/ip-addresses/4/", + "family": 4, + "address": "10.0.1.4/32" + }, + "primary_ip4": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/4/", + "family": 4, + "address": "10.0.1.4/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": {}, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.742412Z" + } + ] +} diff --git a/tests/mocked/2.8.9/devices.json b/tests/mocked/2.8.9/devices.json new file mode 100644 index 0000000..f083c16 --- /dev/null +++ b/tests/mocked/2.8.9/devices.json @@ -0,0 +1,275 @@ +{ + "count": 4, + "next": null, + "previous": null, + "results": [ + { + "id": 1, + "name": "1-Core", + "display_name": "1-Core", + "device_type": { + "id": 11, + "url": "http://localhost:8080/api/dcim/device-types/11/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "MX480", + "slug": "mx480" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/1/", + "family": 4, + "address": "10.0.1.1/32" + }, + "primary_ip4": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/1/", + "family": 4, + "address": "10.0.1.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": { + }, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.742412Z" + }, + { + "id": 2, + "name": "2-Distribution", + "display_name": "2-Distribution", + "device_type": { + "id": 9, + "url": "http://localhost:8080/api/dcim/device-types/9/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "EX4550-32F", + "slug": "ex4550-32f" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": null, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 2, + "url": "http://localhost:8080/api/ipam/ip-addresses/2/", + "family": 4, + "address": "172.16.2.1/32" + }, + "primary_ip4": { + "id": 2, + "url": "http://localhost:8080/api/ipam/ip-addresses/2/", + "family": 4, + "address": "172.16.2.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": { + }, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.802934Z" + }, + { + "id": 3, + "name": "3-Access", + "display_name": "3-Access", + "device_type": { + "id": 2, + "url": "http://localhost:8080/api/dcim/device-types/2/", + "manufacturer": { + "id": 2, + "url": "http://localhost:8080/api/dcim/manufacturers/2/", + "name": "Cisco", + "slug": "cisco" + }, + "model": "3650-48TQ-L", + "slug": "3650-48tq-l" + }, + "device_role": { + "id": 2, + "url": "http://localhost:8080/api/dcim/device-roles/2/", + "name": "Switch", + "slug": "sw" + }, + "tenant": null, + "platform": { + "id": 2, + "url": "http://localhost:8080/api/dcim/platforms/2/", + "name": "ios", + "slug": "ios" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 2, + "url": "http://localhost:8080/api/dcim/sites/2/", + "name": "San Jose, CA", + "slug": "san-jose-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 3, + "url": "http://localhost:8080/api/ipam/ip-addresses/3/", + "family": 4, + "address": "192.168.3.1/32" + }, + "primary_ip4": { + "id": 3, + "url": "http://localhost:8080/api/ipam/ip-addresses/3/", + "family": 4, + "address": "192.168.3.1/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": { + "user_defined": 1 + }, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.866133Z" + }, + { + "id": 4, + "name": null, + "display_name": "MX480", + "device_type": { + "id": 11, + "url": "http://localhost:8080/api/dcim/device-types/11/", + "manufacturer": { + "id": 3, + "url": "http://localhost:8080/api/dcim/manufacturers/3/", + "name": "Juniper", + "slug": "juniper" + }, + "model": "MX480", + "slug": "mx480" + }, + "device_role": { + "id": 1, + "url": "http://localhost:8080/api/dcim/device-roles/1/", + "name": "Router", + "slug": "rt" + }, + "tenant": null, + "platform": { + "id": 1, + "url": "http://localhost:8080/api/dcim/platforms/1/", + "name": "junos", + "slug": "junos" + }, + "serial": "", + "asset_tag": null, + "site": { + "id": 3, + "url": "http://localhost:8080/api/dcim/sites/3/", + "name": "Sunnyvale, CA", + "slug": "sunnyvale-ca" + }, + "rack": null, + "position": null, + "face": null, + "parent_device": null, + "status": { + "value": 1, + "label": "Active" + }, + "primary_ip": { + "id": 4, + "url": "http://localhost:8080/api/ipam/ip-addresses/4/", + "family": 4, + "address": "10.0.1.4/32" + }, + "primary_ip4": { + "id": 1, + "url": "http://localhost:8080/api/ipam/ip-addresses/4/", + "family": 4, + "address": "10.0.1.4/32" + }, + "primary_ip6": null, + "cluster": null, + "virtual_chassis": null, + "vc_position": null, + "vc_priority": null, + "comments": "", + "custom_fields": { + }, + "created": "2018-07-12", + "last_updated": "2018-07-12T11:53:54.742412Z" + } + ] +} diff --git a/tests/test_netbox.py b/tests/test_netbox.py index 9818270..20babab 100644 --- a/tests/test_netbox.py +++ b/tests/test_netbox.py @@ -9,11 +9,12 @@ BASE_PATH = os.path.dirname(__file__) +VERSIONS = ["2.3.5", "2.8.9"] -def get_inv(requests_mock, plugin, pagination, **kwargs): +def get_inv(requests_mock, plugin, pagination, version, **kwargs): if not pagination: - with open(f"{BASE_PATH}/mocked/devices.json", "r") as f: + with open(f"{BASE_PATH}/mocked/{version}/devices.json", "r") as f: requests_mock.get( "http://localhost:8080/api/dcim/devices/?limit=0", json=json.load(f), @@ -21,7 +22,7 @@ def get_inv(requests_mock, plugin, pagination, **kwargs): ) else: for offset in range(3): - with open(f"{BASE_PATH}/mocked/devices-{offset}.json", "r") as f: + with open(f"{BASE_PATH}/mocked/{version}/devices-{offset}.json", "r") as f: url = "http://localhost:8080/api/dcim/devices/?limit=0" requests_mock.get( f"{url}&offset={offset}" if offset else url, @@ -34,15 +35,21 @@ def get_inv(requests_mock, plugin, pagination, **kwargs): class TestNBInventory(object): plugin = NBInventory - def test_inventory(self, requests_mock): - inv = get_inv(requests_mock, self.plugin, False) - with open(f"{BASE_PATH}/{self.plugin.__name__}/expected.json", "r") as f: + @pytest.mark.parametrize("version", VERSIONS) + def test_inventory(self, requests_mock, version): + inv = get_inv(requests_mock, self.plugin, False, version) + with open( + f"{BASE_PATH}/{self.plugin.__name__}/{version}/expected.json", "r" + ) as f: expected = json.load(f) assert expected == inv.dict() - def test_inventory_pagination(self, requests_mock): - inv = get_inv(requests_mock, self.plugin, False) - with open(f"{BASE_PATH}/{self.plugin.__name__}/expected.json", "r") as f: + @pytest.mark.parametrize("version", VERSIONS) + def test_inventory_pagination(self, requests_mock, version): + inv = get_inv(requests_mock, self.plugin, False, version) + with open( + f"{BASE_PATH}/{self.plugin.__name__}/{version}/expected.json", "r" + ) as f: expected = json.load(f) assert expected == inv.dict()