Skip to content

Commit

Permalink
Adding role to device interface model to close #383
Browse files Browse the repository at this point in the history
  • Loading branch information
tsm1th committed Oct 30, 2024
1 parent 93cced4 commit 674d973
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/modules/device_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- |
Expand Down Expand Up @@ -186,6 +192,7 @@
device: test100
name: GigabitEthernet25
enabled: false
role: Loopnetwork
type: 1000Base-t (1GE)
untagged_vlan:
name: Wireless
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/nautobot-populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
57 changes: 57 additions & 0 deletions tests/integration/targets/latest/tasks/device_interface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 674d973

Please sign in to comment.