Skip to content

Commit

Permalink
Merge pull request #440 from nautobot/u/tsm1th-add-module-field-to-po…
Browse files Browse the repository at this point in the history
…wer-port

Added module to power port model
  • Loading branch information
joewesch authored Nov 6, 2024
2 parents a2ff92e + d324b49 commit 705f458
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
25 changes: 21 additions & 4 deletions plugins/modules/power_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
device:
description:
- The device the power port is attached to
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand Down Expand Up @@ -60,6 +60,12 @@
required: false
type: str
version_added: "3.0.0"
module:
description:
- The attached module
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -129,16 +135,27 @@ def main():
argument_spec.update(deepcopy(TAGS_ARG_SPEC))
argument_spec.update(
dict(
device=dict(required=True, type="raw"),
device=dict(required=False, type="raw"),
module=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(required=False, type="str"),
allocated_draw=dict(required=False, type="int"),
maximum_draw=dict(required=False, type="int"),
description=dict(required=False, type="str"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device", "module"),
]
mutually_exclusive = [
("device", "module"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

power_port = NautobotDcimModule(module, NB_POWER_PORTS)
power_port.run()
Expand Down
44 changes: 44 additions & 0 deletions tests/integration/targets/latest/tasks/power_port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,47 @@
- test_five['diff']['before']['state'] == "present"
- test_five['diff']['after']['state'] == "absent"
- test_five['msg'] == "power_port Power Port 2 deleted"

- name: "NAUTOBOT 2.3+ TESTS"
when:
- "nautobot_version is version('2.3', '>=')"
block:
- name: "6 - SET ADDITIONAL FACTS"
set_fact:
power_port_module: '{{ lookup(''networktocode.nautobot.lookup'', ''modules'', api_endpoint=nautobot_url, token=nautobot_token, api_filter=''q="HooverMaxProModel60"'') }}'

- name: "POWER_PORT 6: Create power port with module"
networktocode.nautobot.power_port:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Power Port 3
module: HooverMaxProModel60
state: present
register: test_six

- name: "POWER_PORT 6: ASSERT"
assert:
that:
- test_six is changed
- test_six['diff']['before']['state'] == "absent"
- test_six['diff']['after']['state'] == "present"
- test_six['power_port']['name'] == "Power Port 3"
- test_six['power_port']['module'] == power_port_module['key']
- test_six['msg'] == "power_port Power Port 3 created"

- name: "POWER_PORT 7: Create duplicate"
networktocode.nautobot.power_port:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: Power Port 3
module: HooverMaxProModel60
state: present
register: test_seven

- name: "POWER_PORT 7: ASSERT - Create duplicate"
assert:
that:
- not test_seven['changed']
- test_seven['power_port']['name'] == "Power Port 3"
- test_seven['power_port']['module'] == power_port_module['key']
- test_seven['msg'] == "power_port Power Port 3 already exists"

0 comments on commit 705f458

Please sign in to comment.