Skip to content

Commit 3df9506

Browse files
Modules: Fixed user_query_params to pass before module_data is considered when build query_params (#389)
1 parent d7b3258 commit 3df9506

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,11 @@ def _build_query_params(
653653
value = module_data.get(match)
654654
query_dict.update({match: value})
655655

656-
if parent == "lag":
656+
if user_query_params:
657+
# This is to skip any potential changes using module_data when the user
658+
# provides user_query_params
659+
pass
660+
elif parent == "lag":
657661
if not child:
658662
query_dict["name"] = module_data["lag"]
659663
intf_type = self._fetch_choice_value(

tests/integration/targets/latest/tasks/netbox_ip_address.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
- test_eight['msg'] == "ip_address 10.10.1.30/16 created"
172172
- test_eight['ip_address']['address'] == "10.10.1.30/16"
173173
- test_eight['ip_address']['family'] == 4
174-
- test_eight['ip_address']['nat_inside'] == 10
174+
- test_eight['ip_address']['nat_inside'] == 11
175175
- test_eight['ip_address']['vrf'] == 1
176176

177177
- name: "9 - Create IP address on GigabitEthernet2 - test100 - State: present"

tests/integration/targets/regression-latest/tasks/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,38 @@
159159
- test_seven is changed
160160
- test_seven["diff"]["after"]["asset_tag"] == "Null"
161161
- test_seven["device"]["asset_tag"] == "Null"
162+
163+
- name: Add ip address to netbox and don't assign it to a device (Issue 372)
164+
netbox.netbox.netbox_ip_address:
165+
netbox_url: "http://localhost:32768"
166+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
167+
data:
168+
address: 10.255.255.1/24
169+
query_params:
170+
- address
171+
- vrf
172+
state: present
173+
174+
- name: Update same ip address to attach to a device interface (Issue 372)
175+
netbox.netbox.netbox_ip_address:
176+
netbox_url: "http://localhost:32768"
177+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
178+
data:
179+
address: 10.255.255.1/24
180+
assigned_object:
181+
device: test100
182+
name: GigabitEthernet1
183+
query_params:
184+
- address
185+
- vrf
186+
state: present
187+
register: query_params_372
188+
189+
- name: Assert ip address was updated and added to device interface
190+
assert:
191+
that:
192+
- query_params_372 is changed
193+
- query_params_372['msg'] == 'ip_address 10.255.255.1/24 updated'
194+
- query_params_372['diff']['after']['assigned_object'] == 3
195+
- query_params_372['diff']['after']['assigned_object_id'] == 3
196+
- query_params_372['diff']['after']['assigned_object_type'] == 'dcim.interface'

0 commit comments

Comments
 (0)