diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5f9fe7b..13f195dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,9 @@ jobs: - python-version: "3.8" nautobot-version: "1.3" ansible-release: "2.12" + - python-version: "3.8" + nautobot-version: "1.4" + ansible-release: "2.12" env: INVOKE_NAUTOBOT_ANSIBLE_PYTHON_VER: "${{ matrix.python-version }}" INVOKE_NAUTOBOT_ANSIBLE_NAUTOBOT_VER: "${{ matrix.nautobot-version }}" @@ -80,7 +83,7 @@ jobs: run: "poetry remove ansible-base" - name: "Add ansible-core" if: "${{ matrix.ansible-release == '2.11' }}" - run: "poetry add ansible-core@^2.11" + run: "poetry add ansible-core@~2.11" - name: "Install poetry" if: "${{ matrix.ansible-release == '2.9' }}" run: "pip install poetry" @@ -89,7 +92,7 @@ jobs: run: "poetry remove ansible-base" - name: "Add Ansible 2.9" if: "${{ matrix.ansible-release == '2.9' }}" - run: "poetry add ansible@^2.9" + run: "poetry add ansible@~2.9" - name: "Install poetry" if: "${{ matrix.ansible-release == '2.12' }}" run: "pip install poetry" @@ -98,7 +101,7 @@ jobs: run: "poetry remove ansible-base" - name: "Add Ansible 2.12" if: "${{ matrix.ansible-release == '2.12' }}" - run: "poetry add ansible-core@^2.12 --python ^${{ matrix.python-version }}" + run: "poetry add ansible-core@~2.12 --python ^${{ matrix.python-version }}" - name: "Start containers" run: "invoke start" - name: "Tests" diff --git a/Dockerfile b/Dockerfile index 503ac8f1..b85c6e3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,7 +79,7 @@ RUN ansible-galaxy collection install community.general RUN ansible-galaxy collection build --output-path ./dist/ . # Install built library -RUN ansible-galaxy collection install ./dist/networktocode*.tar.gz +RUN ansible-galaxy collection install ./dist/networktocode*.tar.gz -p ${ANSIBLE_COLLECTIONS_PATH} # Switch to the collection path for tests WORKDIR ${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/networktocode/nautobot @@ -100,6 +100,8 @@ FROM unittests AS integration ARG ANSIBLE_INTEGRATION_ARGS ENV ANSIBLE_INTEGRATION_ARGS=${ANSIBLE_INTEGRATION_ARGS} +ARG NAUTOBOT_VER +ENV NAUTOBOT_VER=${NAUTOBOT_VER} # Integration test entrypoint ENTRYPOINT ${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/networktocode/nautobot/tests/integration/entrypoint.sh diff --git a/development/docker-compose.yml b/development/docker-compose.yml index 3e9f911c..fcbdf949 100644 --- a/development/docker-compose.yml +++ b/development/docker-compose.yml @@ -27,6 +27,6 @@ services: image: "redis:6-alpine" command: - "sh" - - "-c" # this is to evaluate the $REDIS_PASSWORD from the env - - "redis-server --appendonly yes --requirepass $$REDIS_PASSWORD" ## $$ because of docker-compose - env_file: "./dev.env" \ No newline at end of file + - "-c" # this is to evaluate the $REDIS_PASSWORD from the env + - "redis-server --appendonly yes --requirepass $$REDIS_PASSWORD" ## $$ because of docker-compose + env_file: "./dev.env" diff --git a/docker-compose.yml b/docker-compose.yml index c384b9a1..a6eb009a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ x-service: ANSIBLE_INTEGRATION_ARGS: ${ANSIBLE_INTEGRATION_ARGS:-} ANSIBLE_SANITY_ARGS: ${ANSIBLE_SANITY_ARGS:-} ANSIBLE_UNIT_ARGS: ${ANSIBLE_UNIT_ARGS:-} + NAUTOBOT_VER: ${INVOKE_NAUTOBOT_ANSIBLE_NAUTOBOT_VER:-} services: unit: diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index 56a71f15..49ccf817 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -284,14 +284,14 @@ "device_role": set(["slug"]), "device_type": set(["slug"]), "front_port": set(["name", "device", "rear_port"]), - "front_port_template": set(["name", "device_type", "rear_port"]), + "front_port_template": set(["name", "device_type", "rear_port_template"]), "installed_device": set(["name"]), "interface": set(["name", "device", "virtual_machine"]), "interface_template": set(["name", "device_type"]), "inventory_item": set(["name", "device"]), - "ip_address": set(["address", "vrf", "device", "interface", "assigned_object"]), - "ip_addresses": set(["address", "vrf", "device", "interface", "assigned_object"]), - "ipaddresses": set(["address", "vrf", "device", "interface", "assigned_object"]), + "ip_address": set(["address", "vrf", "device", "interface", "vminterface"]), + "ip_addresses": set(["address", "vrf", "device", "interface", "vminterface"]), + "ipaddresses": set(["address", "vrf", "device", "interface", "vminterface"]), "lag": set(["name"]), "manufacturer": set(["slug"]), "master": set(["name"]), @@ -337,7 +337,7 @@ "vrf": set(["name", "tenant"]), } -QUERY_PARAMS_IDS = set(["circuit", "cluster", "device", "group", "interface", "rir", "vrf", "site", "tenant", "type", "virtual_machine"]) +QUERY_PARAMS_IDS = set(["circuit", "cluster", "device", "group", "interface", "rir", "vrf", "site", "tenant", "type", "virtual_machine", "vminterface"]) REQUIRED_ID_FIND = { "cables": set(["status", "type", "length_unit"]), @@ -713,7 +713,7 @@ def _build_query_params(self, parent, module_data, user_query_params=None, child else: query_dict.update({"device": module_data["device"]}) - elif parent == "ip_address" and "assigned_object" in matches and module_data.get("assigned_object_type"): + elif parent == "ip_address" and module_data.get("assigned_object_type"): if module_data["assigned_object_type"] == "virtualization.vminterface": query_dict.update({"vminterface_id": module_data.get("assigned_object_id")}) elif module_data["assigned_object_type"] == "dcim.interface": diff --git a/tests/integration/entrypoint.sh b/tests/integration/entrypoint.sh index 997e167b..d42c82f3 100755 --- a/tests/integration/entrypoint.sh +++ b/tests/integration/entrypoint.sh @@ -32,7 +32,11 @@ function main { echo "# Running..." # shellcheck disable=SC2086 - ansible-test integration $ANSIBLE_INTEGRATION_ARGS --coverage --python "$PYTHON_VERSION" inventory "$@" + if [[ "${NAUTOBOT_VER:-}" == "1.4" ]]; then + ansible-test integration $ANSIBLE_INTEGRATION_ARGS --coverage --python "$PYTHON_VERSION" inventory-1.4 "$@" + else + ansible-test integration $ANSIBLE_INTEGRATION_ARGS --coverage --python "$PYTHON_VERSION" inventory "$@" + fi ansible-test integration $ANSIBLE_INTEGRATION_ARGS --coverage --python "$PYTHON_VERSION" regression-latest "$@" ansible-test integration $ANSIBLE_INTEGRATION_ARGS --coverage --python "$PYTHON_VERSION" latest "$@" ansible-test coverage report diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 49ab7671..f0d7b57a 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -294,11 +294,11 @@ def make_nautobot_calls(endpoint, payload): created_ip_addresses = make_nautobot_calls(nb.ipam.ip_addresses, ip_addresses) # Grab first two IPs -ip1 = nb.ipam.ip_addresses.get(address="172.16.180.1/24", assigned_object_id=test100_gi1.id) -ip2 = nb.ipam.ip_addresses.get(address="2001::1:1/64", assigned_object_id=test100_gi2.id) +ip1 = nb.ipam.ip_addresses.get(address="172.16.180.1/24", interface_id=test100_gi1.id) +ip2 = nb.ipam.ip_addresses.get(address="2001::1:1/64", interface_id=test100_gi2.id) # Assign Primary IP -nexus_eth1_ip = nb.ipam.ip_addresses.get(address="172.16.180.11/24", assigned_object_id=nexus_eth1.id) +nexus_eth1_ip = nb.ipam.ip_addresses.get(address="172.16.180.11/24", interface_id=nexus_eth1.id) nexus.update({"primary_ip4": nexus_eth1_ip}) # Create RIRs diff --git a/tests/integration/targets/inventory-1.4/.gitignore b/tests/integration/targets/inventory-1.4/.gitignore new file mode 100644 index 00000000..df76504d --- /dev/null +++ b/tests/integration/targets/inventory-1.4/.gitignore @@ -0,0 +1 @@ +runme_config \ No newline at end of file diff --git a/tests/integration/targets/inventory-1.4/aliases b/tests/integration/targets/inventory-1.4/aliases new file mode 100644 index 00000000..a3a2089b --- /dev/null +++ b/tests/integration/targets/inventory-1.4/aliases @@ -0,0 +1 @@ +# https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/integration-aliases.html diff --git a/tests/integration/targets/inventory-1.4/compare_inventory_json.py b/tests/integration/targets/inventory-1.4/compare_inventory_json.py new file mode 100755 index 00000000..6cd9f4f2 --- /dev/null +++ b/tests/integration/targets/inventory-1.4/compare_inventory_json.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python + +# Inspired by community.aws collection script_inventory_ec2 test +# https://github.com/ansible-collections/community.aws/blob/master/tests/integration/targets/script_inventory_ec2/inventory_diff.py + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import sys +import json +import argparse +from jsondiff import diff +from operator import itemgetter + +# Nautobot includes "created" and "last_updated" times on objects. These end up in the interfaces objects that are included verbatim from the Nautobot API. +# "url" may be different if local tests use a different host/port +# Remove these from files saved in git as test data +KEYS_REMOVE = frozenset(["created", "id", "last_updated", "rack_id", "url", "notes_url"]) + +# Ignore these when performing diffs as they will be different for each test run +KEYS_IGNORE = frozenset() + + +def all_keys_to_ignore(): + keys = KEYS_REMOVE.union(KEYS_IGNORE) + + return keys + + +# Assume the object will not be recursive, as it originally came from JSON +def remove_keys(obj, keys): + + if isinstance(obj, dict): + keys_to_remove = keys.intersection(obj.keys()) + for key in keys_to_remove: + del obj[key] + + for (key, value) in obj.items(): + remove_keys(value, keys) + + elif isinstance(obj, list): + # Iterate over temporary copy, as we may remove items + for item in obj[:]: + if isinstance(item, str) and item in keys: + # List contains a string that we want to remove + # eg. a group name in list of groups + obj.remove(item) + remove_keys(item, keys) + + +def sort_hostvar_arrays(obj): + meta = obj.get("_meta") + if not meta: + return + + hostvars = meta.get("hostvars") + if not hostvars: + return + + for hostname, host in hostvars.items(): + interfaces = host.get("interfaces") + if interfaces: + host["interfaces"] = sorted(interfaces, key=itemgetter("name")) + + services = host.get("services") + if services: + host["services"] = sorted(services, key=itemgetter("name")) + + +def read_json(filename): + with open(filename, "r") as f: + return json.loads(f.read()) + + +def write_json(filename, data): + with open(filename, "w") as f: + json.dump(data, f, indent=4) + + +def main(): + parser = argparse.ArgumentParser(description="Diff Ansible inventory JSON output") + parser.add_argument( + "filename_a", + metavar="ORIGINAL.json", + type=str, + help="Original json to test against", + ) + parser.add_argument( + "filename_b", + metavar="NEW.json", + type=str, + help="Newly generated json to compare against original", + ) + parser.add_argument( + "--write", + action="store_true", + help=( + "When comparing files, various keys are removed. " + "This option will not compare the files, and instead writes ORIGINAL.json to NEW.json after removing these keys. " + "This is used to clean the test json files before saving to the git repo. " + "For example, this removes dates. " + ), + ) + parser.add_argument( + "--nautobot-version", + metavar="VERSION", + type=str, + help=( + "Apply comparison specific to Nautobot version. " + "For example, rack_groups arrays will only contain a single item in v2.7, so are ignored in the comparison." + ), + ) + + args = parser.parse_args() + + data_a = read_json(args.filename_a) + + if args.write: + # When writing test data, only remove "remove_keys" that will change on every git commit. + # This makes diffs more easily readable to ensure changes to test data look correct. + remove_keys(data_a, KEYS_REMOVE) + sort_hostvar_arrays(data_a) + write_json(args.filename_b, data_a) + + else: + data_b = read_json(args.filename_b) + + # Ignore keys that we don't want to diff, in addition to the ones removed that change on every commit + keys = all_keys_to_ignore() + remove_keys(data_a, keys) + remove_keys(data_b, keys) + + sort_hostvar_arrays(data_a) + sort_hostvar_arrays(data_b) + + # Perform the diff + # syntax='symmetric' will produce output that prints both the before and after as "$insert" and "$delete" + # marshal=True removes any special types, allowing to be dumped as json + result = diff(data_a, data_b, marshal=True, syntax="symmetric") + + if result: + # Dictionary is not empty - print differences + print(json.dumps(result, sort_keys=True, indent=4)) + sys.exit(1) + else: + # Success, no differences + sys.exit(0) + + +if __name__ == "__main__": + main() diff --git a/tests/integration/targets/inventory-1.4/files/test-inventory.json b/tests/integration/targets/inventory-1.4/files/test-inventory.json new file mode 100644 index 00000000..ba7a7884 --- /dev/null +++ b/tests/integration/targets/inventory-1.4/files/test-inventory.json @@ -0,0 +1,1093 @@ +{ + "_meta": { + "hostvars": { + "R1-Device": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "manufacturer": "cisco", + "rack": "Test Rack Site 2", + "rack_groups": [], + "rack_role": "test-rack-role", + "regions": [], + "role": "core-switch", + "services": [], + "site": "test-site2", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "Test Nexus One": { + "ansible_host": "172.16.180.11", + "config_context": {}, + "custom_fields": {}, + "device_type": "nexus-parent", + "dns_name": "nexus.example.com", + "interfaces": [ + { + "bridge": null, + "cable": null, + "cable_peer": null, + "cable_peer_type": null, + "connected_endpoint": null, + "connected_endpoint_reachable": null, + "connected_endpoint_type": null, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus Child One", + "id": "826c7412-355a-428a-aa0c-5f8de7e52278", + "name": "Test Nexus Child One", + "url": "http://nautobot:8000/api/dcim/devices/826c7412-355a-428a-aa0c-5f8de7e52278/" + }, + "display": "Ethernet2/1", + "enabled": true, + "id": "fd6c659e-ef94-46f1-8abd-cbf37dba2489", + "ip_addresses": [ + { + "address": "172.16.180.12/24", + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "display": "172.16.180.12/24", + "dns_name": "nexus.example.com", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": "189c61fc-a377-42e9-9741-624937e47831", + "last_updated": "2022-08-28T23:33:11.884357Z", + "nat_inside": null, + "nat_outside": null, + "notes_url": "http://nautobot:8000/api/ipam/ip-addresses/189c61fc-a377-42e9-9741-624937e47831/notes/", + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "url": "http://nautobot:8000/api/ipam/ip-addresses/189c61fc-a377-42e9-9741-624937e47831/", + "vrf": null + } + ], + "label": "", + "lag": null, + "mac_address": null, + "mgmt_only": false, + "mode": null, + "mtu": null, + "name": "Ethernet2/1", + "notes_url": "http://nautobot:8000/api/dcim/interfaces/fd6c659e-ef94-46f1-8abd-cbf37dba2489/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "url": "http://nautobot:8000/api/dcim/interfaces/fd6c659e-ef94-46f1-8abd-cbf37dba2489/" + }, + { + "bridge": null, + "cable": null, + "cable_peer": null, + "cable_peer_type": null, + "connected_endpoint": null, + "connected_endpoint_reachable": null, + "connected_endpoint_type": null, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": "c24cb495-e40c-4d37-94e5-4d8295e57a5d", + "name": "Test Nexus One", + "url": "http://nautobot:8000/api/dcim/devices/c24cb495-e40c-4d37-94e5-4d8295e57a5d/" + }, + "display": "Ethernet1/1", + "enabled": true, + "id": "cd26d821-d853-42e9-a7ff-5673685dd8ca", + "ip_addresses": [ + { + "address": "172.16.180.11/24", + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "display": "172.16.180.11/24", + "dns_name": "nexus.example.com", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": "e5c6bb9b-3def-4ec4-ab17-24e37a171474", + "last_updated": "2022-08-28T23:33:11.855930Z", + "nat_inside": null, + "nat_outside": null, + "notes_url": "http://nautobot:8000/api/ipam/ip-addresses/e5c6bb9b-3def-4ec4-ab17-24e37a171474/notes/", + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "url": "http://nautobot:8000/api/ipam/ip-addresses/e5c6bb9b-3def-4ec4-ab17-24e37a171474/", + "vrf": null + } + ], + "label": "", + "lag": null, + "mac_address": null, + "mgmt_only": false, + "mode": null, + "mtu": null, + "name": "Ethernet1/1", + "notes_url": "http://nautobot:8000/api/dcim/interfaces/cd26d821-d853-42e9-a7ff-5673685dd8ca/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "url": "http://nautobot:8000/api/dcim/interfaces/cd26d821-d853-42e9-a7ff-5673685dd8ca/" + } + ], + "is_virtual": false, + "manufacturer": "cisco", + "primary_ip4": "172.16.180.11", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": "c24cb495-e40c-4d37-94e5-4d8295e57a5d", + "name": "Test Nexus One", + "url": "http://nautobot:8000/api/dcim/devices/c24cb495-e40c-4d37-94e5-4d8295e57a5d/" + }, + "display": "telnet (TCP/23)", + "id": "48bde449-b83e-4ba6-873d-7ad148244c65", + "ipaddresses": [], + "last_updated": "2022-08-28T23:33:24.456719Z", + "name": "telnet", + "notes_url": "http://nautobot:8000/api/ipam/services/48bde449-b83e-4ba6-873d-7ad148244c65/notes/", + "ports": [ + 23 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "url": "http://nautobot:8000/api/ipam/services/48bde449-b83e-4ba6-873d-7ad148244c65/", + "virtual_machine": null + } + ], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "Test VM With Spaces": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": "0267a81f-5d99-46bc-a185-18b5eb844af7", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/0267a81f-5d99-46bc-a185-18b5eb844af7/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/0267a81f-5d99-46bc-a185-18b5eb844af7/", + "virtual_machine": { + "display": "Test VM With Spaces", + "id": "f27d1706-c951-41b8-bcdb-d14ebba937a8", + "name": "Test VM With Spaces", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/f27d1706-c951-41b8-bcdb-d14ebba937a8/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": "68c14c1b-f74e-485c-9efb-fd84424ca49b", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/68c14c1b-f74e-485c-9efb-fd84424ca49b/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/68c14c1b-f74e-485c-9efb-fd84424ca49b/", + "virtual_machine": { + "display": "Test VM With Spaces", + "id": "f27d1706-c951-41b8-bcdb-d14ebba937a8", + "name": "Test VM With Spaces", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/f27d1706-c951-41b8-bcdb-d14ebba937a8/" + } + } + ], + "is_virtual": true, + "regions": [], + "services": [ + { + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "device": null, + "display": "ssh (TCP/22)", + "id": "50c766b7-5b72-464f-afbc-559578da01b2", + "ipaddresses": [], + "last_updated": "2022-08-28T23:33:24.486357Z", + "name": "ssh", + "notes_url": "http://nautobot:8000/api/ipam/services/50c766b7-5b72-464f-afbc-559578da01b2/notes/", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "url": "http://nautobot:8000/api/ipam/services/50c766b7-5b72-464f-afbc-559578da01b2/", + "virtual_machine": { + "display": "Test VM With Spaces", + "id": "f27d1706-c951-41b8-bcdb-d14ebba937a8", + "name": "Test VM With Spaces", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/f27d1706-c951-41b8-bcdb-d14ebba937a8/" + } + } + ], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "TestDeviceR1": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "manufacturer": "cisco", + "rack": "Test Rack", + "rack_groups": [ + "test-rack-group", + "parent-rack-group" + ], + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test100": { + "config_context": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [ + { + "bridge": null, + "cable": null, + "cable_peer": null, + "cable_peer_type": null, + "connected_endpoint": null, + "connected_endpoint_reachable": null, + "connected_endpoint_type": null, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100", + "id": "b4c68cb5-55aa-4227-98c5-ca6b25131f08", + "name": "test100", + "url": "http://nautobot:8000/api/dcim/devices/b4c68cb5-55aa-4227-98c5-ca6b25131f08/" + }, + "display": "GigabitEthernet1", + "enabled": true, + "id": "544a82b1-9eb9-4c01-aea1-f4688add868a", + "ip_addresses": [ + { + "address": "172.16.180.1/24", + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "display": "172.16.180.1/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": "dc329d10-8339-4364-acb3-e915fe3cca64", + "last_updated": "2022-08-28T23:33:11.795106Z", + "nat_inside": null, + "nat_outside": null, + "notes_url": "http://nautobot:8000/api/ipam/ip-addresses/dc329d10-8339-4364-acb3-e915fe3cca64/notes/", + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "url": "http://nautobot:8000/api/ipam/ip-addresses/dc329d10-8339-4364-acb3-e915fe3cca64/", + "vrf": null + } + ], + "label": "", + "lag": null, + "mac_address": null, + "mgmt_only": false, + "mode": null, + "mtu": null, + "name": "GigabitEthernet1", + "notes_url": "http://nautobot:8000/api/dcim/interfaces/544a82b1-9eb9-4c01-aea1-f4688add868a/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "url": "http://nautobot:8000/api/dcim/interfaces/544a82b1-9eb9-4c01-aea1-f4688add868a/" + }, + { + "bridge": null, + "cable": null, + "cable_peer": null, + "cable_peer_type": null, + "connected_endpoint": null, + "connected_endpoint_reachable": null, + "connected_endpoint_type": null, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100", + "id": "b4c68cb5-55aa-4227-98c5-ca6b25131f08", + "name": "test100", + "url": "http://nautobot:8000/api/dcim/devices/b4c68cb5-55aa-4227-98c5-ca6b25131f08/" + }, + "display": "GigabitEthernet2", + "enabled": true, + "id": "6c10dbed-bf8a-4a57-982f-c599b4282d17", + "ip_addresses": [ + { + "address": "2001::1:1/64", + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "display": "2001::1:1/64", + "dns_name": "", + "family": { + "label": "IPv6", + "value": 6 + }, + "id": "237072d8-c4c6-480d-9ec1-7afd4078953b", + "last_updated": "2022-08-28T23:33:11.826990Z", + "nat_inside": null, + "nat_outside": null, + "notes_url": "http://nautobot:8000/api/ipam/ip-addresses/237072d8-c4c6-480d-9ec1-7afd4078953b/notes/", + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "url": "http://nautobot:8000/api/ipam/ip-addresses/237072d8-c4c6-480d-9ec1-7afd4078953b/", + "vrf": null + } + ], + "label": "", + "lag": null, + "mac_address": null, + "mgmt_only": false, + "mode": null, + "mtu": null, + "name": "GigabitEthernet2", + "notes_url": "http://nautobot:8000/api/dcim/interfaces/6c10dbed-bf8a-4a57-982f-c599b4282d17/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "url": "http://nautobot:8000/api/dcim/interfaces/6c10dbed-bf8a-4a57-982f-c599b4282d17/" + } + ], + "is_virtual": false, + "local_context_data": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "manufacturer": "cisco", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100", + "id": "b4c68cb5-55aa-4227-98c5-ca6b25131f08", + "name": "test100", + "url": "http://nautobot:8000/api/dcim/devices/b4c68cb5-55aa-4227-98c5-ca6b25131f08/" + }, + "display": "ssh (TCP/22)", + "id": "9e15c6e8-5d6f-4e8b-a0c7-648b8a4f59e5", + "ipaddresses": [], + "last_updated": "2022-08-28T23:33:24.351724Z", + "name": "ssh", + "notes_url": "http://nautobot:8000/api/ipam/services/9e15c6e8-5d6f-4e8b-a0c7-648b8a4f59e5/notes/", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "url": "http://nautobot:8000/api/ipam/services/9e15c6e8-5d6f-4e8b-a0c7-648b8a4f59e5/", + "virtual_machine": null + }, + { + "created": "2022-08-28", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100", + "id": "b4c68cb5-55aa-4227-98c5-ca6b25131f08", + "name": "test100", + "url": "http://nautobot:8000/api/dcim/devices/b4c68cb5-55aa-4227-98c5-ca6b25131f08/" + }, + "display": "http (TCP/80)", + "id": "77753d00-67f6-45a9-b925-0670a77e588e", + "ipaddresses": [ + { + "address": "2001::1:1/64", + "display": "2001::1:1/64", + "family": 6, + "id": "237072d8-c4c6-480d-9ec1-7afd4078953b", + "url": "http://nautobot:8000/api/ipam/ip-addresses/237072d8-c4c6-480d-9ec1-7afd4078953b/" + }, + { + "address": "172.16.180.1/24", + "display": "172.16.180.1/24", + "family": 4, + "id": "dc329d10-8339-4364-acb3-e915fe3cca64", + "url": "http://nautobot:8000/api/ipam/ip-addresses/dc329d10-8339-4364-acb3-e915fe3cca64/" + } + ], + "last_updated": "2022-08-28T23:33:24.387974Z", + "name": "http", + "notes_url": "http://nautobot:8000/api/ipam/services/77753d00-67f6-45a9-b925-0670a77e588e/notes/", + "ports": [ + 80 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "url": "http://nautobot:8000/api/ipam/services/77753d00-67f6-45a9-b925-0670a77e588e/", + "virtual_machine": null + } + ], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": "test-tenant", + "tenant_group": "test-tenant-group" + }, + "test100-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": "d4599190-22b6-4a45-b4fe-8b5d8aa703e4", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/d4599190-22b6-4a45-b4fe-8b5d8aa703e4/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/d4599190-22b6-4a45-b4fe-8b5d8aa703e4/", + "virtual_machine": { + "display": "test100-vm", + "id": "e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93", + "name": "test100-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": "63f64464-d41d-4096-acab-5ff6836d8835", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/63f64464-d41d-4096-acab-5ff6836d8835/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/63f64464-d41d-4096-acab-5ff6836d8835/", + "virtual_machine": { + "display": "test100-vm", + "id": "e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93", + "name": "test100-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": "3b7b8f11-e385-43db-8623-0f0cc0074915", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/3b7b8f11-e385-43db-8623-0f0cc0074915/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/3b7b8f11-e385-43db-8623-0f0cc0074915/", + "virtual_machine": { + "display": "test100-vm", + "id": "e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93", + "name": "test100-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": "748b1ca3-c44d-4a06-8ca9-ebb9cc381991", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/748b1ca3-c44d-4a06-8ca9-ebb9cc381991/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/748b1ca3-c44d-4a06-8ca9-ebb9cc381991/", + "virtual_machine": { + "display": "test100-vm", + "id": "e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93", + "name": "test100-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": "98448048-9bff-4743-a906-5c9ea00f35da", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/98448048-9bff-4743-a906-5c9ea00f35da/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/98448048-9bff-4743-a906-5c9ea00f35da/", + "virtual_machine": { + "display": "test100-vm", + "id": "e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93", + "name": "test100-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/e8c5ca06-b80f-4ef4-b3c1-24f28a74ad93/" + } + } + ], + "is_virtual": true, + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test101-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": "8fe7f17c-ab17-423b-a754-f1c152cd2224", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/8fe7f17c-ab17-423b-a754-f1c152cd2224/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/8fe7f17c-ab17-423b-a754-f1c152cd2224/", + "virtual_machine": { + "display": "test101-vm", + "id": "13d6b3d1-9a9c-448b-b4dd-7aa22459da3b", + "name": "test101-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/13d6b3d1-9a9c-448b-b4dd-7aa22459da3b/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": "62daab82-fafb-4391-8ca1-87ebf484d9cc", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/62daab82-fafb-4391-8ca1-87ebf484d9cc/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/62daab82-fafb-4391-8ca1-87ebf484d9cc/", + "virtual_machine": { + "display": "test101-vm", + "id": "13d6b3d1-9a9c-448b-b4dd-7aa22459da3b", + "name": "test101-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/13d6b3d1-9a9c-448b-b4dd-7aa22459da3b/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": "b33b7a3c-8789-436a-8306-4412da75fe33", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/b33b7a3c-8789-436a-8306-4412da75fe33/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/b33b7a3c-8789-436a-8306-4412da75fe33/", + "virtual_machine": { + "display": "test101-vm", + "id": "13d6b3d1-9a9c-448b-b4dd-7aa22459da3b", + "name": "test101-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/13d6b3d1-9a9c-448b-b4dd-7aa22459da3b/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": "5f4bc783-bfa1-4d4c-aa3b-b50f0d411dcc", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/5f4bc783-bfa1-4d4c-aa3b-b50f0d411dcc/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/5f4bc783-bfa1-4d4c-aa3b-b50f0d411dcc/", + "virtual_machine": { + "display": "test101-vm", + "id": "13d6b3d1-9a9c-448b-b4dd-7aa22459da3b", + "name": "test101-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/13d6b3d1-9a9c-448b-b4dd-7aa22459da3b/" + } + }, + { + "bridge": null, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": "fef883f1-ef61-433f-a15c-97ee8777deea", + "ip_addresses": [], + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "notes_url": "http://nautobot:8000/api/virtualization/interfaces/fef883f1-ef61-433f-a15c-97ee8777deea/notes/", + "parent_interface": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "url": "http://nautobot:8000/api/virtualization/interfaces/fef883f1-ef61-433f-a15c-97ee8777deea/", + "virtual_machine": { + "display": "test101-vm", + "id": "13d6b3d1-9a9c-448b-b4dd-7aa22459da3b", + "name": "test101-vm", + "url": "http://nautobot:8000/api/virtualization/virtual-machines/13d6b3d1-9a9c-448b-b4dd-7aa22459da3b/" + } + } + ], + "is_virtual": true, + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test102-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test103-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test104-vm": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "regions": [], + "services": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + } + } + }, + "all": { + "children": [ + "cluster_Test_Cluster", + "cluster_Test_Cluster_2", + "cluster_group_test_cluster_group", + "cluster_type_test_cluster_type", + "device_type_cisco_test", + "device_type_nexus_parent", + "is_virtual", + "manufacturer_cisco", + "rack_Test_Rack", + "rack_Test_Rack_Site_2", + "rack_group_parent_rack_group", + "rack_group_test_rack_group", + "rack_role_test_rack_role", + "region_other_region", + "region_parent_region", + "role_core_switch", + "service_http", + "service_ssh", + "service_telnet", + "site_test_site2", + "status_active", + "tenant_test_tenant", + "ungrouped" + ] + }, + "cluster_Test_Cluster": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_Test_Cluster_2": { + "hosts": [ + "Test VM With Spaces", + "test104-vm" + ] + }, + "cluster_group_test_cluster_group": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_type_test_cluster_type": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "device_type_cisco_test": { + "hosts": [ + "R1-Device", + "TestDeviceR1", + "test100" + ] + }, + "device_type_nexus_parent": { + "hosts": [ + "Test Nexus One" + ] + }, + "is_virtual": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "manufacturer_cisco": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "rack_Test_Rack": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_Test_Rack_Site_2": { + "hosts": [ + "R1-Device" + ] + }, + "rack_group_parent_rack_group": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_group_test_rack_group": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_role_test_rack_role": { + "hosts": [ + "R1-Device" + ] + }, + "region_parent_region": { + "children": [ + "region_test_region" + ] + }, + "region_test_region": { + "children": [ + "site_test_site" + ] + }, + "role_core_switch": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "service_http": { + "hosts": [ + "test100" + ] + }, + "service_ssh": { + "hosts": [ + "Test VM With Spaces", + "test100" + ] + }, + "service_telnet": { + "hosts": [ + "Test Nexus One" + ] + }, + "site_test_site": { + "hosts": [ + "Test Nexus One", + "TestDeviceR1", + "test100", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "site_test_site2": { + "hosts": [ + "R1-Device" + ] + }, + "status_active": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "Test VM With Spaces", + "TestDeviceR1", + "test100", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "tenant_test_tenant": { + "hosts": [ + "test100" + ] + } +} \ No newline at end of file diff --git a/tests/integration/targets/inventory-1.4/files/test-inventory.yml b/tests/integration/targets/inventory-1.4/files/test-inventory.yml new file mode 100644 index 00000000..4954836f --- /dev/null +++ b/tests/integration/targets/inventory-1.4/files/test-inventory.yml @@ -0,0 +1,28 @@ +plugin: networktocode.nautobot.inventory +api_endpoint: "http://nautobot:8000" +token: "0123456789abcdef0123456789abcdef01234567" +validate_certs: False + +config_context: True +plurals: False +interfaces: True +services: True + +group_by: + - site + - tenant + - rack + - rack_group + - rack_role + - tag + - role + - device_type + - manufacturer + - platform + - region + - cluster + - cluster_group + - cluster_type + - is_virtual + - services + - status diff --git a/tests/integration/targets/inventory-1.4/runme.sh b/tests/integration/targets/inventory-1.4/runme.sh new file mode 100755 index 00000000..ad146d6f --- /dev/null +++ b/tests/integration/targets/inventory-1.4/runme.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -o xtrace # Print commands as they're run +set -o errexit # abort on nonzero exitstatus +set -o nounset # abort on unbound variable +set -o pipefail # don't hide errors within pipes + +# Directory of this script +SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}" )" +RUNME_CONFIG="$SCRIPT_DIR/runme_config" +INVENTORIES_DIR="$SCRIPT_DIR/files" + +# Load runme_config, if exists - the only way to pass environment when run through ansible-test +if [[ -f "$RUNME_CONFIG" ]] +then + source "$RUNME_CONFIG" +fi + +declare -a COMPARE_OPTIONS # empty array + +# OUTPUT_DIR is set by ansible-test +# OUTPUT_INVENTORY_JSON is only set if running hacking/update_test_inventories.sh to update the test diff data +if [[ -n "${OUTPUT_INVENTORY_JSON:-}" ]] +then + OUTPUT_DIR="$OUTPUT_INVENTORY_JSON" + + # Clean up JSON fields we don't want to store and compare against in tests (creation times, etc.) + COMPARE_OPTIONS+=(--write) +fi + +echo OUTPUT_DIR="$OUTPUT_DIR" + +inventory () { + if [[ -n "${OUTPUT_INVENTORY_JSON:-}" ]] + then + # Running for the purpose of updating test data + ansible-inventory "$@" + else + # Running inside ansible-test + # Run through python.py just to make sure we've definitely got the coverage environment set up + # Just running ansible-inventory directly may not actually find the right one in PATH + python.py "$(command -v ansible-inventory)" "$@" + fi +} + + +RESULT=0 + +for INVENTORY in "$INVENTORIES_DIR"/*.yml +do + NAME="$(basename "$INVENTORY")" + NAME_WITHOUT_EXTENSION="${NAME%.yml}" + + OUTPUT_JSON="$OUTPUT_DIR/$NAME_WITHOUT_EXTENSION.json" + inventory -vvvv --list --inventory "$INVENTORY" --output="$OUTPUT_JSON" + + # Compare the output + if ! "$SCRIPT_DIR/compare_inventory_json.py" "${COMPARE_OPTIONS[@]}" "$INVENTORIES_DIR/$NAME_WITHOUT_EXTENSION.json" "$OUTPUT_JSON" + then + # Returned non-zero status + RESULT=1 + fi + +done + +exit $RESULT diff --git a/tests/integration/targets/inventory-1.4/runme_config.template b/tests/integration/targets/inventory-1.4/runme_config.template new file mode 100644 index 00000000..7865d774 --- /dev/null +++ b/tests/integration/targets/inventory-1.4/runme_config.template @@ -0,0 +1,6 @@ +# runme_config is source'd by runme.sh to set environment variables used to modify the test against different versions of Nautobot. +# .travis.yml uses render_config.sh to generate it from runme_config.template +# There is no other way to pass environment variables to a runme.sh integration test. +# (integration_config.yml files are only helpful to ansible yaml-based tests) + +export PYNAUTOBOT_VERSION=${VERSION} diff --git a/tests/integration/targets/latest/tasks/ip_address.yml b/tests/integration/targets/latest/tasks/ip_address.yml index b53b4afe..8a417546 100644 --- a/tests/integration/targets/latest/tasks/ip_address.yml +++ b/tests/integration/targets/latest/tasks/ip_address.yml @@ -134,7 +134,7 @@ - set_fact: tag_schnozzberry: "{{ lookup('networktocode.nautobot.lookup', 'tags', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=schnozzberry') }}" - vrf: '{{ lookup(''networktocode.nautobot.lookup'', ''vrfs'', api_endpoint=nautobot_url, token=nautobot_token, api_filter=''"name=Test VRF"'') }}' + vrf: '{{ lookup(''networktocode.nautobot.lookup'', ''vrfs'', api_endpoint=nautobot_url, token=nautobot_token, api_filter=''name="Test VRF"'') }}' tenant: "{{ lookup('networktocode.nautobot.lookup', 'tenants', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=test-tenant') }}" - name: "7 - ASSERT" diff --git a/tests/integration/targets/latest/tasks/prefix.yml b/tests/integration/targets/latest/tasks/prefix.yml index 36bd0c8f..e28ee36b 100644 --- a/tests/integration/targets/latest/tasks/prefix.yml +++ b/tests/integration/targets/latest/tasks/prefix.yml @@ -8,7 +8,7 @@ test_site: "{{ lookup('networktocode.nautobot.lookup', 'sites', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=test-site') }}" tenant: "{{ lookup('networktocode.nautobot.lookup', 'tenants', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=test-tenant') }}" tag_schnozzberry: "{{ lookup('networktocode.nautobot.lookup', 'tags', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=schnozzberry') }}" - vrf: '{{ lookup(''networktocode.nautobot.lookup'', ''vrfs'', api_endpoint=nautobot_url, token=nautobot_token, api_filter=''"name=Test VRF"'') }}' + vrf: '{{ lookup(''networktocode.nautobot.lookup'', ''vrfs'', api_endpoint=nautobot_url, token=nautobot_token, api_filter=''name="Test VRF"'') }}' vlan_group: "{{ lookup('networktocode.nautobot.lookup', 'vlan-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=test-vlan-group') }}" - name: "1 - Create prefix within Nautobot with only required information"