Skip to content

Commit

Permalink
fix: Updated Zones logic to require View as a mandatory attribute (#63)
Browse files Browse the repository at this point in the history
* Updated Zones Logic to Require 'View' Parameter

* updated gitignore

* formatting fixes
  • Loading branch information
unasra authored Jan 22, 2025
1 parent f40219b commit 4f3529b
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ cython_debug/

# Ignore the metadata files
**/.DS_Store

# Ignore the Anstibull files addded
dest/
9 changes: 5 additions & 4 deletions plugins/modules/dns_auth_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@
description:
- "The resource identifier."
type: str
required: true
zone_authority:
description:
- "Optional. ZoneAuthority."
Expand Down Expand Up @@ -2015,7 +2016,7 @@ def find(self):
return None
raise e
else:
filter = f"fqdn=='{self.params['fqdn']}'"
filter = f"fqdn=='{self.params['fqdn']}' and view=='{self.params['view']}'"
resp = AuthZoneApi(self.client).list(filter=filter, inherit="full")
if len(resp.results) == 1:
return resp.results[0]
Expand All @@ -2036,7 +2037,7 @@ def update(self):
return None

update_body = self.payload
update_body = self.validate_readonly_on_update(self.existing, update_body, ["fqdn", "primary_type"])
update_body = self.validate_readonly_on_update(self.existing, update_body, ["fqdn", "primary_type", "view"])

resp = AuthZoneApi(self.client).update(id=self.existing.id, body=update_body, inherit="full")
return resp.result.model_dump(by_alias=True, exclude_none=True)
Expand Down Expand Up @@ -2309,7 +2310,7 @@ def main():
),
),
use_forwarders_for_subzones=dict(type="bool"),
view=dict(type="str"),
view=dict(type="str", required=True),
zone_authority=dict(
type="dict",
options=dict(
Expand All @@ -2328,7 +2329,7 @@ def main():
module = AuthZoneModule(
argument_spec=module_args,
supports_check_mode=True,
required_if=[("state", "present", ["fqdn", "primary_type"])],
required_if=[("state", "present", ["fqdn", "primary_type", "view"])],
)

module.run_command()
Expand Down
6 changes: 2 additions & 4 deletions plugins/modules/dns_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ def find(self):
return None
raise e
else:
# TODO - add view to filter once it is supported, removed due to NORTHSTAR-12614
# filter = f"fqdn=='{self.params['fqdn']}' and view =='{self.params['view']}'"
filter = f"fqdn=='{self.params['fqdn']}'"
filter = f"fqdn=='{self.params['fqdn']}' and view =='{self.params['view']}'"
resp = DelegationApi(self.client).list(filter=filter)
if len(resp.results) == 1:
return resp.results[0]
Expand Down Expand Up @@ -327,7 +325,7 @@ def main():
module = DelegationModule(
argument_spec=module_args,
supports_check_mode=True,
required_if=[("state", "present", ["fqdn", "delegation_servers"])],
required_if=[("state", "present", ["fqdn", "delegation_servers", "view"])],
)

module.run_command()
Expand Down
9 changes: 5 additions & 4 deletions plugins/modules/dns_forward_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
description:
- "The resource identifier."
type: str
required: true
extends_documentation_fragment:
- infoblox.bloxone.common
Expand Down Expand Up @@ -306,7 +307,7 @@ def find(self):
return None
raise e
else:
filter = f"fqdn=='{self.params['fqdn']}'"
filter = f"fqdn=='{self.params['fqdn']}' and view=='{self.params['view']}'"
resp = ForwardZoneApi(self.client).list(filter=filter)
if len(resp.results) == 1:
return resp.results[0]
Expand All @@ -327,7 +328,7 @@ def update(self):
return None

update_body = self.payload
update_body = self.validate_readonly_on_update(self.existing, update_body, ["fqdn"])
update_body = self.validate_readonly_on_update(self.existing, update_body, ["fqdn", "view"])

resp = ForwardZoneApi(self.client).update(id=self.existing.id, body=update_body)
return resp.result.model_dump(by_alias=True, exclude_none=True)
Expand Down Expand Up @@ -399,13 +400,13 @@ def main():
nsgs=dict(type="list", elements="str"),
parent=dict(type="str"),
tags=dict(type="dict"),
view=dict(type="str"),
view=dict(type="str", required=True),
)

module = ForwardZoneModule(
argument_spec=module_args,
supports_check_mode=True,
required_if=[("state", "present", ["fqdn"])],
required_if=[("state", "present", ["fqdn", "view"])],
)

module.run_command()
Expand Down
43 changes: 38 additions & 5 deletions tests/integration/targets/dns_auth_zone/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -44,6 +45,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -55,6 +57,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: external
view: "{{ _view.id }}"
external_primaries:
- fqdn: "as-infoblox-test.com."
address: "192.168.10.10"
Expand All @@ -65,6 +68,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -79,6 +83,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: external
view: "{{ _view.id }}"
state: present
register: auth_zone
- assert:
Expand All @@ -90,13 +95,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: external
view: "{{ _view.id }}"
state: absent
check_mode: true
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -115,6 +122,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand Down Expand Up @@ -148,6 +156,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -160,13 +169,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
comment: "Test Comment"
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -179,13 +190,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
disabled: true
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -198,6 +211,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
external_secondaries:
- fqdn: "as-infoblox-test.com."
address: "192.168.10.10"
Expand All @@ -207,6 +221,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -221,12 +236,14 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -240,13 +257,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
gss_tsig_enabled: true
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -259,6 +278,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
inheritance_sources:
# The API currently requires all fields inside the inheritance config to be explicitly provided,
# or it fails with error 'The value of an inheritance action field is not valid'.
Expand Down Expand Up @@ -293,6 +313,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -303,13 +324,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
notify: true
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -322,6 +345,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
query_acl:
- access: "allow"
element: "ip"
Expand All @@ -334,6 +358,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -351,6 +376,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
transfer_acl:
- access: "allow"
element: "ip"
Expand All @@ -363,6 +389,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -380,6 +407,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
update_acl:
- access: "allow"
element: "ip"
Expand All @@ -392,6 +420,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -409,13 +438,15 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
use_forwarders_for_subzones: true
state: present
register: auth_zone
- name: Get Information about the Auth Zone
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -428,6 +459,7 @@
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
zone_authority:
default_ttl: 28600
expire: 2519200
Expand All @@ -443,6 +475,7 @@
infoblox.bloxone.dns_auth_zone_info:
filters:
fqdn: "{{ fqdn }}"
view: "{{ _view.id }}"
register: auth_zone_info
- assert:
that:
Expand All @@ -461,12 +494,12 @@
- name: "Delete Auth Zone"
infoblox.bloxone.dns_auth_zone:
fqdn: "{{ fqdn }}"
primary_type: cloud
view: "{{ _view.id }}"
state: "absent"
ignore_errors: true

- name: "Delete the View"
infoblox.bloxone.dns_view:
name: "{{ name }}"
state: absent
register: _view
ignore_errors: true
ansible.builtin.include_role:
name: setup_view
tasks_from: cleanup.yml
2 changes: 2 additions & 0 deletions tests/integration/targets/dns_auth_zone_info/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
dependencies: [setup_view]
Loading

0 comments on commit 4f3529b

Please sign in to comment.