diff --git a/plugins/modules/vm_interface.py b/plugins/modules/vm_interface.py index 3b1dfc64..088000ed 100644 --- a/plugins/modules/vm_interface.py +++ b/plugins/modules/vm_interface.py @@ -85,6 +85,12 @@ required: false type: raw version_added: "3.0.0" + role: + description: + - The role of the interface + required: false + type: raw + version_added: "5.3.0" """ EXAMPLES = r""" @@ -125,6 +131,7 @@ - name: VoIP location: "{{ test_location['key'] }}" mtu: 1600 + role: Server mode: Tagged state: present @@ -184,6 +191,7 @@ def main(): mode=dict(required=False, type="raw"), untagged_vlan=dict(required=False, type="raw"), tagged_vlans=dict(required=False, type="raw"), + role=dict(required=False, type="raw"), ) ) diff --git a/tests/integration/nautobot-populate.py b/tests/integration/nautobot-populate.py index edfc44f8..7e50da51 100755 --- a/tests/integration/nautobot-populate.py +++ b/tests/integration/nautobot-populate.py @@ -257,10 +257,10 @@ def make_nautobot_calls(endpoint, payload): device_roles.append({"name": "Test Controller Role", "color": "e91e65", "vm_role": False, "content_types": ["dcim.controller"]}) created_device_roles = make_nautobot_calls(nb.extras.roles, device_roles) + # Device role variables to be used later on core_switch = nb.extras.roles.get(name="Core Switch") - # Create Rack Groups rack_groups = [ {"name": "Parent Rack Group", "location": location_child.id}, @@ -620,6 +620,15 @@ def make_nautobot_calls(endpoint, payload): contacts = [{"name": "My Contact"}, {"name": "My Contact 2"}] created_contacts = make_nautobot_calls(nb.extras.contacts, contacts) +############### +# v2.3+ items # +############### +if nautobot_version >= version.parse("2.3"): + # Create role for virtual machine interfaces + vm_interface_roles = [ + {"name": "Test VM Interface Role", "color": "aa1409", "vm_role": False, "content_types": ["virtualization.vminterface"]}, + ] + created_vm_interface_roles = make_nautobot_calls(nb.extras.roles, vm_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.yml b/tests/integration/targets/latest/tasks/device.yml index 90cf59bf..400c0f53 100644 --- a/tests/integration/targets/latest/tasks/device.yml +++ b/tests/integration/targets/latest/tasks/device.yml @@ -11,7 +11,6 @@ role: "{{ lookup('networktocode.nautobot.lookup', 'roles', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Core Switch\"') }}" vc1: "{{ lookup('networktocode.nautobot.lookup', 'virtual-chassis', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=VC1') }}" staged: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Staged') }}" - active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" device_redundancy_group: "{{ lookup('networktocode.nautobot.lookup', 'device-redundancy-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Device Redundancy Group\"') }}" - name: "1 - Device with required information" diff --git a/tests/integration/targets/latest/tasks/device_redundancy_group.yml b/tests/integration/targets/latest/tasks/device_redundancy_group.yml index 68546b29..29f5cdf2 100644 --- a/tests/integration/targets/latest/tasks/device_redundancy_group.yml +++ b/tests/integration/targets/latest/tasks/device_redundancy_group.yml @@ -5,7 +5,6 @@ ## ## - set_fact: - active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" secrets_group: "{{ lookup('networktocode.nautobot.lookup', 'secrets-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test Secrets Group\"') }}" - name: "1 - Create device redundancy group within Nautobot with only required information" diff --git a/tests/integration/targets/latest/tasks/location.yml b/tests/integration/targets/latest/tasks/location.yml index 4b6650ae..c291458e 100644 --- a/tests/integration/targets/latest/tasks/location.yml +++ b/tests/integration/targets/latest/tasks/location.yml @@ -7,7 +7,6 @@ - set_fact: parent_location_type: "{{ lookup('networktocode.nautobot.lookup', 'location-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Parent Location Type\"') }}" child_location_type: "{{ lookup('networktocode.nautobot.lookup', 'location-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Child Location Type\"') }}" - active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" - name: "1 - Create location within Nautobot with only required information" networktocode.nautobot.location: diff --git a/tests/integration/targets/latest/tasks/main.yml b/tests/integration/targets/latest/tasks/main.yml index 4c532edc..86ff4f33 100644 --- a/tests/integration/targets/latest/tasks/main.yml +++ b/tests/integration/targets/latest/tasks/main.yml @@ -1,4 +1,10 @@ --- +- name: "Set facts used in multiple tests." + set_fact: + active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" + tags: + - always + # Lookup tests should run first so items created by other tests don't influence the results - name: "PYNAUTOBOT_LOOKUP TESTS" include_tasks: diff --git a/tests/integration/targets/latest/tasks/plugin_bgp_asn.yml b/tests/integration/targets/latest/tasks/plugin_bgp_asn.yml index 6e0edb0e..f26707f3 100644 --- a/tests/integration/targets/latest/tasks/plugin_bgp_asn.yml +++ b/tests/integration/targets/latest/tasks/plugin_bgp_asn.yml @@ -5,7 +5,6 @@ ## ## - set_fact: - active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" planned: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Planned') }}" - name: "BGP ASN 1: Creation" diff --git a/tests/integration/targets/latest/tasks/prefix.yml b/tests/integration/targets/latest/tasks/prefix.yml index 9e15d4ce..2882fd9d 100644 --- a/tests/integration/targets/latest/tasks/prefix.yml +++ b/tests/integration/targets/latest/tasks/prefix.yml @@ -10,7 +10,6 @@ tag_schnozzberry: "{{ lookup('networktocode.nautobot.lookup', 'tags', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Schnozzberry') }}" vlan_group: "{{ lookup('networktocode.nautobot.lookup', 'vlan-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test Vlan Group\"') }}" reserved: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Reserved') }}" - active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}" global_namespace: "{{ lookup('networktocode.nautobot.lookup', 'namespaces', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Global') }}" private_namespace: "{{ lookup('networktocode.nautobot.lookup', 'namespaces', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Private') }}" diff --git a/tests/integration/targets/latest/tasks/vm_interface.yml b/tests/integration/targets/latest/tasks/vm_interface.yml index 7ecc7776..77ccb007 100644 --- a/tests/integration/targets/latest/tasks/vm_interface.yml +++ b/tests/integration/targets/latest/tasks/vm_interface.yml @@ -161,3 +161,60 @@ - test_five['interface']['tagged_vlans']|length == 2 - test_five['interface']['tags'][0] == tag_schnozzberry['key'] - test_five['msg'] == "interface Eth0 updated" + +- name: "NAUTOBOT 2.3+ TESTS" + when: + - "nautobot_version is version('2.3', '>=')" + block: + - name: SET ADDITIONAL FACTS + set_fact: + vm_interface_role: "{{ lookup('networktocode.nautobot.lookup', 'roles', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test VM Interface Role\"' )}}" + + - name: "PYNAUTOBOT_VM_INTERFACE 10: Created" + networktocode.nautobot.vm_interface: + url: "{{ nautobot_url }}" + token: "{{ nautobot_token }}" + virtual_machine: "test100-vm" + name: "Eth101" + enabled: false + mtu: 9000 + mac_address: "00:00:00:AA:AA:01" + description: "Updated test100-vm" + mode: Tagged + role: "Test VM Interface Role" + 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_ten + + - debug: + msg: "{{ test_ten }}" + + - name: "PYNAUTOBOT_VM_INTERFACE 10: ASSERT - Created" + assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['interface']['name'] == "Eth101" + - test_ten['interface']['status'] == active['key'] + - test_ten['interface']['virtual_machine'] == vm100['key'] + - test_ten['interface']['enabled'] == false + - test_ten['interface']['mtu'] == 9000 + - test_ten['interface']['mac_address'] == "00:00:00:AA:AA:01" + - test_ten['interface']['description'] == "Updated test100-vm" + - test_ten['interface']['mode'] == "tagged" + - test_ten['interface']['untagged_vlan'] == wireless['key'] + - test_ten['interface']['tagged_vlans']|length == 2 + - test_ten['interface']['tags'][0] == tag_schnozzberry['key'] + - test_ten['interface']['role'] == vm_interface_role['key'] + - test_ten['msg'] == "interface Eth101 created"