Skip to content

Commit

Permalink
Fixes module bay template device/module type identification
Browse files Browse the repository at this point in the history
  • Loading branch information
joewesch committed Jan 22, 2025
1 parent 6de24ff commit 4312f9c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
"master": set(["name"]),
"metadata_choice": set(["value", "metadata_type"]),
"metadata_type": set(["name"]),
"module_bay_template": set(["name"]),
"module_bay_template": set(["name", "device_type", "module_type"]),
"module_bay": set(["name", "parent_device", "parent_module"]),
"module_type": set(["model"]),
"module": set(["module_type", "parent_module_bay", "location"]),
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/nautobot-populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def make_nautobot_calls(endpoint, payload):
# Create Device Types
device_types = [
{"model": "Cisco Test", "manufacturer": cisco_manu.id},
{"model": "Cisco Test 2", "manufacturer": cisco_manu.id},
{"model": "Arista Test", "manufacturer": arista_manu.id},
{
"model": "Nexus Parent",
Expand Down Expand Up @@ -702,8 +703,11 @@ def make_nautobot_calls(endpoint, payload):
cloud_networks = [{"name": "CiscoCloudNetwork", "cloud_resource_type": "CiscoCloudNetworkType", "cloud_account": "CiscoCloudAccount"}]
created_cloud_networks = make_nautobot_calls(nb.cloud.cloud_networks, cloud_networks)

# Create a module type
power_outlet_module_types = [{"manufacturer": "Cisco", "model": "HooverMaxProModel60"}]
# Create module types
power_outlet_module_types = [
{"manufacturer": "Cisco", "model": "HooverMaxProModel60"},
{"manufacturer": "Cisco", "model": "HooverMaxProModel61"},
]
created_power_outlet_module_types = make_nautobot_calls(nb.dcim.module_types, power_outlet_module_types)

# Create a module bay
Expand Down
80 changes: 80 additions & 0 deletions tests/integration/targets/latest/tasks/module_bay_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
##
- set_fact:
test_module_type: "{{ lookup('networktocode.nautobot.lookup', 'module-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='model=\"HooverMaxProModel60\"') }}"
test_module_type_2: "{{ lookup('networktocode.nautobot.lookup', 'module-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='model=\"HooverMaxProModel61\"') }}"
test_device_type: "{{ lookup('networktocode.nautobot.lookup', 'device-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='model=\"Cisco Test\"') }}"
test_device_type_2: "{{ lookup('networktocode.nautobot.lookup', 'device-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='model=\"Cisco Test 2\"') }}"

- name: "1 - Create module bay template with minimum information"
networktocode.nautobot.module_bay_template:
Expand Down Expand Up @@ -44,6 +46,42 @@
- test_two['module_bay_template']['module_type'] == test_module_type['key']
- test_two['msg'] == "module_bay_template Edward Galbraith already exists"

# Regression testing issue #486
- name: "2.1 - Create module bay template with second module type"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
module_type: HooverMaxProModel61
name: Edward Galbraith
state: present
register: test_two_one

- name: "2.1 - ASSERT"
assert:
that:
- test_two_one is changed
- test_two_one['module_bay_template']['name'] == "Edward Galbraith"
- test_two_one['module_bay_template']['module_type'] == test_module_type_2['key']
- test_two_one['msg'] == "module_bay_template Edward Galbraith created"

# Regression testing issue #486
- name: "2.2 - Create module bay template with second module type idempotent"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
module_type: HooverMaxProModel61
name: Edward Galbraith
state: present
register: test_two_two

- name: "2.2 - ASSERT"
assert:
that:
- not test_two_two['changed']
- test_two_two['module_bay_template']['name'] == "Edward Galbraith"
- test_two_two['module_bay_template']['module_type'] == test_module_type_2['key']
- test_two_two['msg'] == "module_bay_template Edward Galbraith already exists"

- name: "3 - Update module bay template"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
Expand Down Expand Up @@ -135,6 +173,48 @@
- test_six['module_bay_template']['device_type'] == test_device_type['key']
- test_six['msg'] == "module_bay_template Test1234 already exists"

# Regression testing issue #486
- name: "6.1 - Create module bay template with second device type"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: Cisco Test 2
name: Test1234
label: test1234
position: "42"
description: Cisco Test Module Bay
state: present
register: test_six_one

- name: "6.1 - ASSERT"
assert:
that:
- test_six_one is changed
- test_six_one['module_bay_template']['name'] == "Test1234"
- test_six_one['module_bay_template']['device_type'] == test_device_type_2['key']
- test_six_one['msg'] == "module_bay_template Test1234 created"

# Regression testing issue #486
- name: "6.2 - Create module bay template with second device type idempotent"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: Cisco Test 2
name: Test1234
label: test1234
position: "42"
description: Cisco Test Module Bay
state: present
register: test_six_two

- name: "6.2 - ASSERT"
assert:
that:
- not test_six_two['changed']
- test_six_two['module_bay_template']['name'] == "Test1234"
- test_six_two['module_bay_template']['device_type'] == test_device_type_2['key']
- test_six_two['msg'] == "module_bay_template Test1234 already exists"

- name: "7 - Delete"
networktocode.nautobot.module_bay_template:
url: "{{ nautobot_url }}"
Expand Down

0 comments on commit 4312f9c

Please sign in to comment.