Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding role to device interface model to close #383 #433

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")
53 changes: 53 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,56 @@
- 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: 15 - 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\"' )}}"
wireless: "{{ lookup('networktocode.nautobot.lookup', 'vlans', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Wireless') }}"

- name: "15 - Create device interface with role"
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"
type: "1000Base-T (1GE)"
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"
state: present
register: test_fifteen

- name: "15 - ASSERT"
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'] == "The interface that will cause the outage"
- test_fifteen['interface']['mode'] == "tagged"
- test_fifteen['interface']['untagged_vlan'] == wireless['key']
- test_fifteen['interface']['tagged_vlans']|length == 2
- test_fifteen['interface']['role'] == device_interface_role['key']
- test_fifteen['msg'] == "interface GigabitEthernet15 created"