Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing bug #975 #1323

Merged
merged 22 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading