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

Remove status attribute requirement when state is present #298

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 1 addition & 10 deletions plugins/modules/cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,7 @@ def main():
)
)

required_if = [
(
"state",
"present",
["termination_a_type", "termination_a", "termination_b_type", "termination_b", "status"],
),
("state", "absent", ["termination_a_type", "termination_a", "termination_b_type", "termination_b"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

cable = NautobotDcimModule(module, NB_CABLES)
cable.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ def main():
)
)

required_if = [
("state", "present", ["cid", "status"]),
("state", "absent", ["cid"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

circuit = NautobotCircuitsModule(module, NB_CIRCUITS)
circuit.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "cluster_type"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

cluster = NautobotVirtualizationModule(module, NB_CLUSTERS)
cluster.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "status"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
if module.params["name"] == "":
module.params["name"] = str(uuid.uuid4())

Expand Down
7 changes: 2 additions & 5 deletions plugins/modules/device_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
status:
description:
- The status of the interface
- Required if I(state=present) and using I(api_version) 1.4+
- Required if I(state=present) and the interface does not exist yet
required: false
type: raw
version_added: "4.5.0"
Expand Down Expand Up @@ -285,11 +285,8 @@ def main():
custom_fields=dict(required=False, type="dict"),
)
)
required_if = [
("state", "present", ["status"]),
]

module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

device_interface = NautobotDcimModule(module, NB_INTERFACES, remove_keys=["update_vc_child"])
device_interface.run()
Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/ip_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ def main():
)

required_if = [
("state", "present", ["address", "parent", "status"], True),
("state", "absent", ["address"]),
("state", "new", ["address", "parent"], True),
]

Expand Down
1 change: 0 additions & 1 deletion plugins/modules/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def main():
)

required_if = [
("state", "present", ["name", "location_type", "status"]),
("state", "absent", ["id"]),
]

Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/power_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ def main():
)
)

required_if = [
("state", "present", ["power_panel", "name", "status"]),
("state", "absent", ["power_panel", "name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

power_feed = NautobotDcimModule(module, NB_POWER_FEEDS)
power_feed.run()
Expand Down
1 change: 0 additions & 1 deletion plugins/modules/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ def main():
)

required_if = [
("state", "present", ["prefix", "parent", "status"], True),
("state", "absent", ["prefix"]),
("first_available", "yes", ["parent"]),
]
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "status"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

rack = NautobotDcimModule(module, NB_RACKS)
rack.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "content_types"], True),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

role = NautobotDcimModule(module, NB_ROLES)
role.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "content_types"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

status = NautobotExtrasModule(module, NB_STATUS)
status.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "status"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

virtual_machine = NautobotVirtualizationModule(module, NB_VIRTUAL_MACHINES)
virtual_machine.run()
Expand Down
6 changes: 1 addition & 5 deletions plugins/modules/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,8 @@ def main():
custom_fields=dict(required=False, type="dict"),
)
)
required_if = [
("state", "present", ["name", "status"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

vlan = NautobotIpamModule(module, NB_VLANS)
vlan.run()
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/vm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,7 @@ def main():
)
)

required_if = [
("state", "present", ["name", "status"]),
("state", "absent", ["name"]),
]

module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

vm_interface = NautobotVirtualizationModule(module, NB_VM_INTERFACES)
vm_interface.run()
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/targets/latest/tasks/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,44 @@
- test_three['cable']['length_unit'] == "m"
- test_three['msg'] == "cable dcim.interface Ethernet1/1 <> dcim.interface Ethernet2/1 updated"

- name: "CABLE 3.1: Update Cable without status"
networktocode.nautobot.cable:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
termination_a_type: dcim.interface
termination_a:
device: Test Nexus One
name: Ethernet1/1
termination_b_type: dcim.interface
termination_b:
device: Test Nexus Child One
name: Ethernet2/1
type: mmf-om4
label: label1234
color: abcdef
length: 30
length_unit: m
state: present
register: test_three

- name: "CABLE 3.1: ASSERT - Update Cable without status"
assert:
that:
- test_three is changed

- test_three['diff']['after']['label'] == "label1234"
- test_three['cable']['termination_a_type'] == "dcim.interface"
- test_three['cable']['termination_a_id'] == nexus_parent_intf['key']
- test_three['cable']['termination_b_type'] == "dcim.interface"
- test_three['cable']['termination_b_id'] == nexus_child_intf['key']
- test_three['cable']['type'] == "mmf-om4"
- test_three['cable']['status'] == planned['key']
- test_three['cable']['label'] == "label1234"
- test_three['cable']['color'] == "abcdef"
- test_three['cable']['length'] == 30
- test_three['cable']['length_unit'] == "m"
- test_three['msg'] == "cable dcim.interface Ethernet1/1 <> dcim.interface Ethernet2/1 updated"

- name: "CABLE 4: ASSERT - Delete"
networktocode.nautobot.cable:
url: "{{ nautobot_url }}"
Expand Down
36 changes: 34 additions & 2 deletions tests/integration/targets/latest/tasks/circuit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@
- test_three['circuit']['comments'] == "FAST CIRCUIT"
- test_three['msg'] == "circuit Test Circuit One updated"

- name: "PYNAUTOBOT_CIRCUIT 3.1: Update circuit without status"
networktocode.nautobot.circuit:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
cid: Test Circuit One
provider: Test Provider
circuit_type: Test Circuit Type
tenant: Test Tenant
install_date: "2018-12-25"
commit_rate: 10000
description: "Test circuit with updates"
comments: "FASTER CIRCUIT"
state: present
register: test_three

- name: "PYNAUTOBOT_CIRCUIT 3.1: ASSERT - Update circuit without status"
assert:
that:
- test_three is changed
- test_three['diff']['after']['description'] == "Test circuit with updates"
- test_three['diff']['after']['comments'] == "FASTER CIRCUIT"
- test_three['circuit']['cid'] == "Test Circuit One"
- test_three['circuit']['provider'] == provider['key']
- test_three['circuit']['circuit_type'] == type['key']
- test_three['circuit']['status'] == planned['key']
- test_three['circuit']['tenant'] == tenant['key']
- test_three['circuit']['install_date'] == "2018-12-25"
- test_three['circuit']['commit_rate'] == 10000
- test_three['circuit']['description'] == "Test circuit with updates"
- test_three['circuit']['comments'] == "FASTER CIRCUIT"
- test_three['msg'] == "circuit Test Circuit One updated"

- name: "PYNAUTOBOT_CIRCUIT 4: Delete provider within nautobot"
networktocode.nautobot.circuit:
url: "{{ nautobot_url }}"
Expand All @@ -108,6 +140,6 @@
- test_four['circuit']['tenant'] == tenant['key']
- test_four['circuit']['install_date'] == "2018-12-25"
- test_four['circuit']['commit_rate'] == 10000
- test_four['circuit']['description'] == "Test circuit"
- test_four['circuit']['comments'] == "FAST CIRCUIT"
- test_four['circuit']['description'] == "Test circuit with updates"
- test_four['circuit']['comments'] == "FASTER CIRCUIT"
- test_four['msg'] == "circuit Test Circuit One deleted"
5 changes: 1 addition & 4 deletions tests/integration/targets/latest/tasks/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
token: "{{ nautobot_token }}"
name: "R1"
serial: "FXS1001"
status: "Staged"
local_config_context_data:
bgp_as: "65412"
virtual_chassis: "VC1"
Expand Down Expand Up @@ -135,7 +134,6 @@
token: "{{ nautobot_token }}"
name: "R1-changed-name"
serial: "FXS1001"
status: "Staged"
query_params:
- serial
state: present
Expand All @@ -149,7 +147,7 @@
- test_three_dot_two['device']['role'] == role['key']
- test_three_dot_two['device']['device_type'] == device_type['key']
- test_three_dot_two['device']['location'] == parent_location['key']
- test_three_dot_two['device']['status'] == staged['key']
- test_three_dot_two['device']['status'] == active['key']
- test_three_dot_two['device']['serial'] == "FXS1001"
- test_three_dot_two['msg'] == "device R1-changed-name updated"

Expand Down Expand Up @@ -248,7 +246,6 @@
# This will test the UUID for ip4
primary_ip4: "{{ ip4['key'] }}"
primary_ip6: "2001::1:1/64"
status: "Active"
state: present
register: test_seven

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/latest/tasks/ip_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
address: 192.168.1.10/30
status: "Active"
description: "Updated ip address"
tags:
- "Updated"
Expand All @@ -42,6 +41,7 @@
- test_two['diff']['after']['tags'][0] == tag_updated['key']
- test_two['msg'] == "ip_address 192.168.1.10/30 updated"
- test_two['ip_address']['address'] == "192.168.1.10/30"
- test_two['ip_address']['status'] == active['key']
- test_two['ip_address']['tags'][0] == tag_updated['key']
- test_two['ip_address']['description'] == "Updated ip address"
vars:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/latest/tasks/location.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Test Location
status: Active
location_type: "{{ parent_location_type['key'] }}"
description: Test Location Description
register: test_update
Expand All @@ -61,6 +60,7 @@
- test_update is changed
- test_update['diff']['before']['description'] == ""
- test_update['diff']['after']['description'] == "Test Location Description"
- test_update['location']['status'] == active['key']

- name: "4 - Create location with all parameters"
networktocode.nautobot.location:
Expand Down
Loading