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

fix: Add 'parent_interface' parameter for l2/l3 subinterface modules #552

Merged
merged 2 commits into from
Apr 11, 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
2 changes: 2 additions & 0 deletions extensions/eda/plugins/event_source/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def status() -> web.Response:
Returns
-------
A web.Response object with status 200 and the text "up" returned by the function.
"""
return web.Response(status=200, text="up")

Expand All @@ -78,6 +79,7 @@ async def webhook(request: web.Request) -> web.Response:
Returns
-------
A web.Response object with status 200 and the status.
"""
try:
payload = await request.json()
Expand Down
39 changes: 36 additions & 3 deletions plugins/modules/panos_l2_subinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
description:
- Name of the interface to configure.
type: str
parent_interface:
description:
- Name of the parent interface
type: str
tag:
description:
- Tag (vlan id) for the interface
Expand Down Expand Up @@ -103,8 +107,31 @@

class Helper(ConnectionHelper):
def initial_handling(self, module):
if "." not in module.params["name"]:
module.fail_json(msg='interface name does not have "." in it')
# Sanity check.
name_set = True if module.params["name"] is not None else False
parent_set = True if module.params["parent_interface"] is not None else False

if module.params["state"] == "gathered" and not parent_set:
module.fail_json(
msg="'parent_interface' is required when state is 'gathered'."
)

if name_set:
if "." not in module.params["name"]:
module.fail_json(
msg="Subinterface name does not have '.' in it: {0}".format(
module.params["name"]
)
)
if (
parent_set
and module.params["parent_interface"] not in module.params["name"]
):
module.fail_json(
msg="Parent and subinterface names do not match: {0} - {1}".format(
module.params["parent_interface"], module.params["name"]
)
)

if module.params["state"] not in ("present", "replaced"):
return
Expand All @@ -113,7 +140,10 @@ def initial_handling(self, module):
module.params["vsys"] = "vsys1"

def parent_handling(self, parent, module):
iname = module.params["name"].split(".")[0]
if module.params["parent_interface"] is not None:
iname = module.params["parent_interface"]
else:
iname = module.params["name"].split(".")[0]

if iname.startswith("ae"):
eth = to_sdk_cls("network", "AggregateInterface")(iname)
Expand Down Expand Up @@ -147,6 +177,9 @@ def main():
netflow_profile=dict(sdk_param="netflow_profile_l2"),
comment=dict(),
),
extra_params=dict(
parent_interface=dict(type="str"),
),
)

module = AnsibleModule(
Expand Down
39 changes: 35 additions & 4 deletions plugins/modules/panos_l3_subinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
description:
- Name of the interface to configure.
type: str
parent_interface:
description:
- Name of the parent interface
type: str
tag:
description:
- Tag (vlan id) for the interface
Expand Down Expand Up @@ -151,8 +155,30 @@
class Helper(ConnectionHelper):
def initial_handling(self, module):
# Sanity check.
if "." not in module.params["name"]:
module.fail_json(msg='Interface name does not have "." in it')
name_set = True if module.params["name"] is not None else False
parent_set = True if module.params["parent_interface"] is not None else False

if module.params["state"] == "gathered" and not parent_set:
module.fail_json(
msg="'parent_interface' is required when state is 'gathered'."
)

if name_set:
if "." not in module.params["name"]:
module.fail_json(
msg="Subinterface name does not have '.' in it: {0}".format(
module.params["name"]
)
)
if (
parent_set
and module.params["parent_interface"] not in module.params["name"]
):
module.fail_json(
msg="Parent and subinterface names do not match: {0} - {1}".format(
module.params["parent_interface"], module.params["name"]
)
)

if module.params["state"] not in ("present", "replaced"):
return
Expand All @@ -161,9 +187,11 @@ def initial_handling(self, module):
module.params["vsys"] = "vsys1"

def parent_handling(self, parent, module):
iname = module.params["name"].split(".")[0]
if module.params["parent_interface"] is not None:
iname = module.params["parent_interface"]
else:
iname = module.params["name"].split(".")[0]

eth = None
if iname.startswith("ae"):
eth = to_sdk_cls("network", "AggregateInterface")(iname)
else:
Expand Down Expand Up @@ -215,6 +243,9 @@ def main():
),
dhcp_default_route_metric=dict(type="int"),
),
extra_params=dict(
parent_interface=dict(type="str"),
),
)

module = AnsibleModule(
Expand Down
105 changes: 105 additions & 0 deletions tests/integration/firewall/test_panos_l2_subinterface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
- name: test_panos_l2_subinterface - Create
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
register: result

- name: test_panos_l2_subinterface - Assert create was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l2_subinterface - Create (idempotence)
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
register: result

- name: test_panos_l2_subinterface - Assert create (idempotence) was successful
assert:
that:
- result is success
- result is not changed

- name: test_panos_l2_subinterface - Modify
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 1
register: result

- name: test_panos_l2_subinterface - Assert modify was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l2_subinterface - Gather all
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: '*'
register: result

- name: test_panos_l2_subinterface - Assert gather all returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 1 }}"

- name: test_panos_l2_subinterface - Gather by parameter with one match
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: 'name ends-with 1'
register: result

- name: test_panos_l2_subinterface - Assert gather by parameter with one match returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 1 }}"

- name: test_panos_l2_subinterface - Gather by parameter with no match
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: 'name ends-with 2'
register: result

- name: test_panos_l2_subinterface - Assert gather by parameter with no match returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 0 }}"

- name: test_panos_l2_subinterface - Delete
paloaltonetworks.panos.panos_l2_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
state: 'absent'
register: result

- name: test_panos_l2_subinterface - Assert delete was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l2_subinterface - Make sure changes commit cleanly
paloaltonetworks.panos.panos_commit_firewall:
provider: '{{ device }}'
register: result

- name: test_panos_l2_subinterface - Assert commit was successful
assert:
that:
- result is success
105 changes: 105 additions & 0 deletions tests/integration/firewall/test_panos_l3_subinterface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
- name: test_panos_l3_subinterface - Create
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
register: result

- name: test_panos_l3_subinterface - Assert create was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l3_subinterface - Create (idempotence)
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
register: result

- name: test_panos_l3_subinterface - Assert create (idempotence) was successful
assert:
that:
- result is success
- result is not changed

- name: test_panos_l3_subinterface - Modify
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 1
register: result

- name: test_panos_l3_subinterface - Assert modify was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l3_subinterface - Gather all
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: '*'
register: result

- name: test_panos_l3_subinterface - Assert gather all returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 1 }}"

- name: test_panos_l3_subinterface - Gather by parameter with one match
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: 'name ends-with 1'
register: result

- name: test_panos_l3_subinterface - Assert gather by parameter with one match returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 1 }}"

- name: test_panos_l3_subinterface - Gather by parameter with no match
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
parent_interface: 'ethernet1/1'
state: 'gathered'
gathered_filter: 'name ends-with 2'
register: result

- name: test_panos_l3_subinterface - Assert gather by parameter with no match returned result
assert:
that:
- result is success
- "{{ result.gathered | length == 0 }}"

- name: test_panos_l3_subinterface - Delete
paloaltonetworks.panos.panos_l3_subinterface:
provider: '{{ device }}'
name: 'ethernet1/1.1'
tag: 2
state: 'absent'
register: result

- name: test_panos_l3_subinterface - Assert delete was successful
assert:
that:
- result is success
- result is changed

- name: test_panos_l3_subinterface - Make sure changes commit cleanly
paloaltonetworks.panos.panos_commit_firewall:
provider: '{{ device }}'
register: result

- name: test_panos_l3_subinterface - Assert commit was successful
assert:
that:
- result is success
Loading