Skip to content

Commit 694505e

Browse files
richbibbyclaude
andcommitted
Address Copilot review feedback for rack_type and airflow features
Fixes NetBox 4.0 compatibility issues by adding version gates to prevent AttributeError when rack_types endpoint is accessed on older NetBox versions. Adds missing airflow idempotency tests and corrects example documentation to match test data. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent cb7e093 commit 694505e

File tree

6 files changed

+75
-20
lines changed

6 files changed

+75
-20
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"racks": {},
7474
"rack_groups": {},
7575
"rack_roles": {},
76-
"rack_types": {},
76+
"rack_types": {"introduced": "4.1"},
7777
"rear_ports": {},
7878
"rear-ports": {},
7979
"rear_port_templates": {},

plugins/modules/netbox_rack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
site: Test Site
245245
location: Test Location
246246
airflow: front-to-rear
247-
rack_type: Standard 42U Rack
247+
rack_type: Standard 42U
248248
state: present
249249
250250
- name: Delete rack within netbox

tests/integration/netbox-deploy.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,25 @@ def make_netbox_calls(endpoint, payload):
280280
rack_roles = [{"name": "Test Rack Role", "slug": "test-rack-role", "color": "4287f5"}]
281281
created_rack_roles = make_netbox_calls(nb.dcim.rack_roles, rack_roles)
282282

283-
# Create Rack Types
284-
rack_types = [
285-
{
286-
"manufacturer": cisco_manu.id,
287-
"model": "Standard 42U",
288-
"slug": "standard-42u",
289-
"form_factor": "4-post-frame",
290-
"u_height": 42,
291-
},
292-
{
293-
"manufacturer": cisco_manu.id,
294-
"model": "Standard 48U",
295-
"slug": "standard-48u",
296-
"form_factor": "4-post-cabinet",
297-
"u_height": 48,
298-
},
299-
]
300-
created_rack_types = make_netbox_calls(nb.dcim.rack_types, rack_types)
283+
# Create Rack Types (NetBox 4.1+)
284+
if nb_version >= version.parse("4.1"):
285+
rack_types = [
286+
{
287+
"manufacturer": cisco_manu.id,
288+
"model": "Standard 42U",
289+
"slug": "standard-42u",
290+
"form_factor": "4-post-frame",
291+
"u_height": 42,
292+
},
293+
{
294+
"manufacturer": cisco_manu.id,
295+
"model": "Standard 48U",
296+
"slug": "standard-48u",
297+
"form_factor": "4-post-cabinet",
298+
"u_height": 48,
299+
},
300+
]
301+
created_rack_types = make_netbox_calls(nb.dcim.rack_types, rack_types)
301302

302303
# Create Racks
303304
racks = [

tests/integration/targets/v4.1/tasks/netbox_rack.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@
246246
- test_nine['rack']['airflow'] == "front-to-rear"
247247
- test_nine['msg'] == "rack Test Rack Airflow created"
248248

249+
- name: 9a - Create duplicate rack with airflow (idempotency)
250+
netbox.netbox.netbox_rack:
251+
netbox_url: http://localhost:32768
252+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
253+
data:
254+
name: Test Rack Airflow
255+
site: Test Site
256+
airflow: front-to-rear
257+
state: present
258+
register: test_nine_a
259+
260+
- name: 9a - ASSERT
261+
ansible.builtin.assert:
262+
that:
263+
- test_nine_a is not changed
264+
- test_nine_a['rack']['airflow'] == "front-to-rear"
265+
- test_nine_a['msg'] == "rack Test Rack Airflow already exists"
266+
249267
- name: 10 - Update rack airflow
250268
netbox.netbox.netbox_rack:
251269
netbox_url: http://localhost:32768

tests/integration/targets/v4.2/tasks/netbox_rack.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@
246246
- test_nine['rack']['airflow'] == "front-to-rear"
247247
- test_nine['msg'] == "rack Test Rack Airflow created"
248248

249+
- name: 9a - Create duplicate rack with airflow (idempotency)
250+
netbox.netbox.netbox_rack:
251+
netbox_url: http://localhost:32768
252+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
253+
data:
254+
name: Test Rack Airflow
255+
site: Test Site
256+
airflow: front-to-rear
257+
state: present
258+
register: test_nine_a
259+
260+
- name: 9a - ASSERT
261+
ansible.builtin.assert:
262+
that:
263+
- test_nine_a is not changed
264+
- test_nine_a['rack']['airflow'] == "front-to-rear"
265+
- test_nine_a['msg'] == "rack Test Rack Airflow already exists"
266+
249267
- name: 10 - Update rack airflow
250268
netbox.netbox.netbox_rack:
251269
netbox_url: http://localhost:32768

tests/integration/targets/v4.3/tasks/netbox_rack.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@
246246
- test_nine['rack']['airflow'] == "front-to-rear"
247247
- test_nine['msg'] == "rack Test Rack Airflow created"
248248

249+
- name: 9a - Create duplicate rack with airflow (idempotency)
250+
netbox.netbox.netbox_rack:
251+
netbox_url: http://localhost:32768
252+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
253+
data:
254+
name: Test Rack Airflow
255+
site: Test Site
256+
airflow: front-to-rear
257+
state: present
258+
register: test_nine_a
259+
260+
- name: 9a - ASSERT
261+
ansible.builtin.assert:
262+
that:
263+
- test_nine_a is not changed
264+
- test_nine_a['rack']['airflow'] == "front-to-rear"
265+
- test_nine_a['msg'] == "rack Test Rack Airflow already exists"
266+
249267
- name: 10 - Update rack airflow
250268
netbox.netbox.netbox_rack:
251269
netbox_url: http://localhost:32768

0 commit comments

Comments
 (0)