Skip to content

Commit

Permalink
addressed PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
AnilGadiyarHJ committed Dec 11, 2024
1 parent 1a5c16d commit a9c93fd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plugins/modules/dns_forward_nsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def payload_changed(self):
def find(self):
if self.params["id"] is not None:
try:
resp = ForwardNsgApi(self.client).read(self.params["id"], inherit="full")
resp = ForwardNsgApi(self.client).read(self.params["id"])
return resp.result
except NotFoundException as e:
if self.params["state"] == "absent":
Expand Down
13 changes: 1 addition & 12 deletions plugins/modules/dns_forward_nsg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@
- Filter query to filter objects
type: str
required: false
inherit:
description:
- Return inheritance information
type: str
required: false
choices:
- full
- partial
- none
default: full
tag_filters:
description:
- Filter dict to filter objects by tags
Expand Down Expand Up @@ -170,7 +160,7 @@ def __init__(self, *args, **kwargs):

def find_by_id(self):
try:
resp = ForwardNsgApi(self.client).read(self.params["id"], inherit="full")
resp = ForwardNsgApi(self.client).read(self.params["id"])
return [resp.result]
except NotFoundException as e:
return None
Expand Down Expand Up @@ -232,7 +222,6 @@ def main():
id=dict(type="str", required=False),
filters=dict(type="dict", required=False),
filter_query=dict(type="str", required=False),
inherit=dict(type="str", required=False, choices=["full", "partial", "none"], default="full"),
tag_filters=dict(type="dict", required=False),
tag_filter_query=dict(type="str", required=False),
)
Expand Down
50 changes: 48 additions & 2 deletions tests/integration/targets/dns_forward_nsg/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Create a random Forward Zone name to avoid conflicts
- ansible.builtin.set_fact:
forward_nsg_name: "test-forward-nsg-{{ 999999 | random | string }}.com."
forward_nsg_secondary_name: "test-forward-nsg-{{ 999999 | random | string }}.com."

- name: Create an Forward NSG (check mode)
infoblox.bloxone.dns_forward_nsg:
Expand Down Expand Up @@ -142,7 +143,7 @@
name: "{{ forward_nsg_name }}"
external_forwarders:
- address: "192.168.1.0"
fqdn: "terraform-acc-forward-ext."
fqdn: "test_external_forwarder."
state: present
register: forward_nsg
- name: Get Information about the Forward NSG
Expand All @@ -158,7 +159,7 @@
- forward_nsg_info.objects[0].id == forward_nsg.id
- forward_nsg_info.objects[0].external_forwarders | length == 1
- forward_nsg_info.objects[0].external_forwarders[0].address == "192.168.1.0"
- forward_nsg_info.objects[0].external_forwarders[0].fqdn == "terraform-acc-forward-ext."
- forward_nsg_info.objects[0].external_forwarders[0].fqdn == "test_external_forwarder."

- name: Create a Forward NSG with Forwarders Only Enabled
infoblox.bloxone.dns_forward_nsg:
Expand Down Expand Up @@ -199,9 +200,54 @@
- forward_nsg_info.objects[0].id == forward_nsg.id
- forward_nsg_info.objects[0].tags.location == "site-1"

- name: Create Primary Forward NSG
infoblox.bloxone.dns_forward_nsg:
name: "{{ forward_nsg_name }}"
state: present
register: forward_nsg
- name: Create Secondary Forward NSG referencing Primary
infoblox.bloxone.dns_forward_nsg:
name: "{{ forward_nsg_secondary_name }}"
nsgs:
- "{{ forward_nsg.id }}"
state: present
register: secondary_forward_nsg
- name: Validate Secondary Forward NSG Creation
infoblox.bloxone.dns_forward_nsg_info:
filters:
name: "{{ forward_nsg_secondary_name }}"
register: ssecondary_forward_nsg_info
- assert:
that:
- ssecondary_forward_nsg_info is not failed
- ssecondary_forward_nsg_info.objects | length == 1
- ssecondary_forward_nsg_info.objects[0].nsgs | length == 1
- ssecondary_forward_nsg_info.objects[0].nsgs[0] == forward_nsg.id
# Unlinking block
- block:
- name: Unlink Primary NSG from Secondary
infoblox.bloxone.dns_forward_nsg:
id: "{{ secondary_forward_nsg.id }}"
name: "{{ forward_nsg_secondary_name }}"
nsgs: [ ]
state: present
rescue:
- name: Cleanup in case of failure (force unlink Secondary from Primary)
infoblox.bloxone.dns_forward_nsg:
id: "{{ secondary_forward_nsg.id | default('') }}"
nsgs: [ ]
state: present
when: secondary_forward_nsg is defined

always:
- name: "Delete Forward NSG"
infoblox.bloxone.dns_forward_nsg:
name: "{{ forward_nsg_name }}"
state: "absent"
ignore_errors: true

- name: "Delete Secondary Forward NSG"
infoblox.bloxone.dns_forward_nsg:
name: "{{ forward_nsg_secondary_name }}"
state: "absent"
ignore_errors: true
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
name: "{{ forward_nsg_name }}"
state: "absent"
ignore_errors: true

0 comments on commit a9c93fd

Please sign in to comment.