From 674d973f63d06bc332c067b800d0314e653b692b Mon Sep 17 00:00:00 2001 From: Travis Smith <141754521+tsm1th@users.noreply.github.com> Date: Wed, 30 Oct 2024 03:57:40 +0000 Subject: [PATCH] Adding role to device interface model to close #383 --- plugins/modules/device_interface.py | 8 +++ tests/integration/nautobot-populate.py | 6 ++ .../targets/latest/tasks/device_interface.yml | 57 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/plugins/modules/device_interface.py b/plugins/modules/device_interface.py index 17bc6227..40f1fffd 100644 --- a/plugins/modules/device_interface.py +++ b/plugins/modules/device_interface.py @@ -49,6 +49,12 @@ required: false type: str version_added: "3.0.0" + role: + description: + - The role of the interface + required: false + type: raw + version_added: "5.4.0" type: description: - | @@ -186,6 +192,7 @@ device: test100 name: GigabitEthernet25 enabled: false + role: Loopnetwork type: 1000Base-t (1GE) untagged_vlan: name: Wireless @@ -275,6 +282,7 @@ def main(): status=dict(required=False, type="raw"), name=dict(required=True, type="str"), label=dict(required=False, type="str"), + role=dict(required=False, type="raw"), type=dict(required=False, type="str"), enabled=dict(required=False, type="bool"), lag=dict(required=False, type="raw"), diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index 51efed61..7ddef537 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -642,5 +642,11 @@ def make_nautobot_calls(endpoint, payload): ] created_vm_interface_roles = make_nautobot_calls(nb.extras.roles, vm_interface_roles) + # Create role for device interfaces + device_interface_roles = [ + {"name": "Loop the Network", "color": "111111", "vm_role": False, "content_types": ["dcim.interface"]}, + ] + created_device_interface_roles = make_nautobot_calls(nb.extras.roles, device_interface_roles) + if ERRORS: sys.exit("Errors have occurred when creating objects, and should have been printed out. Check previous output.") diff --git a/tests/integration/targets/latest/tasks/device_interface.yml b/tests/integration/targets/latest/tasks/device_interface.yml index 01b9e6c3..12d81e6c 100644 --- a/tests/integration/targets/latest/tasks/device_interface.yml +++ b/tests/integration/targets/latest/tasks/device_interface.yml @@ -368,3 +368,60 @@ - test_fourteen['interface']['name'] == "Bridge1" - test_fourteen['interface']['device'] == test100['key'] - test_fourteen['interface']['bridge'] == test_twelve['interface']['id'] + +- name: "NAUTOBOT 2.3+ TESTS" + when: + - "nautobot_version is version('2.3', '>=')" + block: + - name: SET ADDITIONAL FACTS + set_fact: + device_interface_role: "{{ lookup('networktocode.nautobot.lookup', 'roles', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Loop the Network\"' )}}" + + - name: "PYNAUTOBOT_DEVICE_INTERFACE 15: Created" + networktocode.nautobot.device_interface: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + device: test100 + name: GigabitEthernet15 + enabled: false + mtu: 9000 + mac_address: "69:69:69:69:69:69" + description: "The interface that will cause the outage" + mode: Tagged + role: "Loop the Network" + status: "Active" + untagged_vlan: + name: Wireless + location: "Child Test Location" + tagged_vlans: + - name: Data + location: "Child Test Location" + - name: VoIP + location: "Child Test Location" + tags: + - "Schnozzberry" + state: present + register: test_fifteen + + - debug: + msg: "{{ test_fifteen }}" + + - name: "PYNAUTOBOT_DEVICE_INTERFACE 15: ASSERT - Created" + assert: + that: + - test_fifteen is changed + - test_fifteen['diff']['before']['state'] == "absent" + - test_fifteen['diff']['after']['state'] == "present" + - test_fifteen['interface']['name'] == "GigabitEthernet15" + - test_fifteen['interface']['status'] == active['key'] + - test_fifteen['interface']['device'] == test100['key'] + - test_fifteen['interface']['enabled'] == false + - test_fifteen['interface']['mtu'] == 9000 + - test_fifteen['interface']['mac_address'] == "69:69:69:69:69:69" + - test_fifteen['interface']['description'] == "Updated test100" + - test_fifteen['interface']['mode'] == "tagged" + - test_fifteen['interface']['untagged_vlan'] == wireless['key'] + - test_fifteen['interface']['tagged_vlans']|length == 2 + - test_fifteen['interface']['tags'][0] == tag_schnozzberry['key'] + - test_fifteen['interface']['role'] == device_interface_role['key'] + - test_fifteen['msg'] == "interface GigabitEthernet15 created"