Skip to content

Commit

Permalink
Merge pull request #1323 from Ido-Don/github-issue-#975
Browse files Browse the repository at this point in the history
fixing bug #975
  • Loading branch information
sc68cal authored Oct 19, 2024
2 parents 33f3bc0 + 30cb663 commit 4b203df
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1323-fixing-bug-#975.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface
5 changes: 5 additions & 0 deletions plugins/module_utils/netbox_ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def run(self):
else:
name = data.get("name")

if self.endpoint == "ip_addresses":
if "interface" in data:
data["assigned_object_id"] = data["interface"]
data["assigned_object_type"] = "dcim.interface"

if self.endpoint in SLUG_REQUIRED:
if not data.get("slug"):
data["slug"] = self._to_slug(name)
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/targets/v3.5/tasks/netbox_ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,52 @@
- test_sixteen['diff']['after']['state'] == "present"
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"

- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
address: 10.10.200.31/16
interface:
device: test100
name: GigabitEthernet2
register: test_seventeen

- name: 17 - ASSERT
ansible.builtin.assert:
that:
- test_seventeen is changed
- test_seventeen['diff']['before']['state'] == "absent"
- test_seventeen['diff']['after']['state'] == "present"
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
- test_seventeen['ip_address']['family'] == 4
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_seventeen['ip_address']['assigned_object_id'] == 4

- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
prefix: 10.10.0.0/16
interface:
name: GigabitEthernet2
device: test100
state: new
register: test_eighteen

- name: 18 - ASSERT
ansible.builtin.assert:
that:
- test_eighteen is changed
- test_eighteen['diff']['before']['state'] == "absent"
- test_eighteen['diff']['after']['state'] == "present"
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
- test_eighteen['ip_address']['family'] == 4
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_eighteen['ip_address']['assigned_object_id'] == 4
49 changes: 49 additions & 0 deletions tests/integration/targets/v3.6/tasks/netbox_ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,52 @@
- test_sixteen['diff']['after']['state'] == "present"
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"

- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
address: 10.10.200.31/16
interface:
device: test100
name: GigabitEthernet2
register: test_seventeen

- name: 17 - ASSERT
ansible.builtin.assert:
that:
- test_seventeen is changed
- test_seventeen['diff']['before']['state'] == "absent"
- test_seventeen['diff']['after']['state'] == "present"
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
- test_seventeen['ip_address']['family'] == 4
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_seventeen['ip_address']['assigned_object_id'] == 4

- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
prefix: 10.10.0.0/16
interface:
name: GigabitEthernet2
device: test100
state: new
register: test_eighteen

- name: 18 - ASSERT
ansible.builtin.assert:
that:
- test_eighteen is changed
- test_eighteen['diff']['before']['state'] == "absent"
- test_eighteen['diff']['after']['state'] == "present"
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
- test_eighteen['ip_address']['family'] == 4
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_eighteen['ip_address']['assigned_object_id'] == 4
49 changes: 49 additions & 0 deletions tests/integration/targets/v3.7/tasks/netbox_ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,52 @@
- test_sixteen['diff']['after']['state'] == "present"
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"

- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
address: 10.10.200.31/16
interface:
device: test100
name: GigabitEthernet2
register: test_seventeen

- name: 17 - ASSERT
ansible.builtin.assert:
that:
- test_seventeen is changed
- test_seventeen['diff']['before']['state'] == "absent"
- test_seventeen['diff']['after']['state'] == "present"
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
- test_seventeen['ip_address']['family'] == 4
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_seventeen['ip_address']['assigned_object_id'] == 4

- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
prefix: 10.10.0.0/16
interface:
name: GigabitEthernet2
device: test100
state: new
register: test_eighteen

- name: 18 - ASSERT
ansible.builtin.assert:
that:
- test_eighteen is changed
- test_eighteen['diff']['before']['state'] == "absent"
- test_eighteen['diff']['after']['state'] == "present"
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
- test_eighteen['ip_address']['family'] == 4
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_eighteen['ip_address']['assigned_object_id'] == 4
49 changes: 49 additions & 0 deletions tests/integration/targets/v4.0/tasks/netbox_ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,52 @@
- test_sixteen['diff']['after']['state'] == "present"
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"

- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
address: 10.10.200.31/16
interface:
device: test100
name: GigabitEthernet2
register: test_seventeen

- name: 17 - ASSERT
ansible.builtin.assert:
that:
- test_seventeen is changed
- test_seventeen['diff']['before']['state'] == "absent"
- test_seventeen['diff']['after']['state'] == "present"
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
- test_seventeen['ip_address']['family'] == 4
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_seventeen['ip_address']['assigned_object_id'] == 4

- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
prefix: 10.10.0.0/16
interface:
name: GigabitEthernet2
device: test100
state: new
register: test_eighteen

- name: 18 - ASSERT
ansible.builtin.assert:
that:
- test_eighteen is changed
- test_eighteen['diff']['before']['state'] == "absent"
- test_eighteen['diff']['after']['state'] == "present"
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
- test_eighteen['ip_address']['family'] == 4
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_eighteen['ip_address']['assigned_object_id'] == 4
49 changes: 49 additions & 0 deletions tests/integration/targets/v4.1/tasks/netbox_ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,52 @@
- test_sixteen['diff']['after']['state'] == "present"
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"

- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
address: 10.10.200.31/16
interface:
device: test100
name: GigabitEthernet2
register: test_seventeen

- name: 17 - ASSERT
ansible.builtin.assert:
that:
- test_seventeen is changed
- test_seventeen['diff']['before']['state'] == "absent"
- test_seventeen['diff']['after']['state'] == "present"
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
- test_seventeen['ip_address']['family'] == 4
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_seventeen['ip_address']['assigned_object_id'] == 4

- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
netbox.netbox.netbox_ip_address:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
family: 4
prefix: 10.10.0.0/16
interface:
name: GigabitEthernet2
device: test100
state: new
register: test_eighteen

- name: 18 - ASSERT
ansible.builtin.assert:
that:
- test_eighteen is changed
- test_eighteen['diff']['before']['state'] == "absent"
- test_eighteen['diff']['after']['state'] == "present"
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
- test_eighteen['ip_address']['family'] == 4
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
- test_eighteen['ip_address']['assigned_object_id'] == 4

0 comments on commit 4b203df

Please sign in to comment.