From 1d2bb34992312a23a9a68b6901a26db2f0b8c563 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Thu, 23 Aug 2018 03:07:30 +0000 Subject: [PATCH] Includes support for Reverse-Mapping zone in nios_zone module (#44525) * support reverse mapping * support reverse mapping * support reverse mapping * fix shippable errors * fix shippable errors * fix shippable errors --- .../modules/net_tools/nios/nios_zone.py | 40 ++++- test/runner/lib/cloud/nios.py | 2 +- .../modules/net_tools/nios/test_nios_zone.py | 161 ++++++++++++++++++ 3 files changed, 201 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/net_tools/nios/nios_zone.py b/lib/ansible/modules/net_tools/nios/nios_zone.py index 83a943a9421..a449ab6fc15 100644 --- a/lib/ansible/modules/net_tools/nios/nios_zone.py +++ b/lib/ansible/modules/net_tools/nios/nios_zone.py @@ -65,6 +65,14 @@ options: - If set to true, causes the NIOS DNS service to restart and load the new zone configuration type: bool + zone_format: + version_added: "2.7" + description: + - Create an authorative Reverse-Mapping Zone which is an area of network + space for which one or more name servers-primary and secondary-have the + responsibility to respond to address-to-name queries. It supports + reverse-mapping zones for both IPv4 and IPv6 addresses. + default: FORWARD extattrs: description: - Allows for the configuration of Extensible Attributes on the @@ -103,7 +111,6 @@ EXAMPLES = ''' username: admin password: admin connection: local - - name: configure a zone on the system using a name server group nios_zone: name: ansible.com @@ -115,6 +122,26 @@ EXAMPLES = ''' username: admin password: admin connection: local +- name: configure a reverse mapping zone on the system using IPV4 zone format + nios_zone: + name: 10.10.10.0/24 + zone_format: IPV4 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +- name: configure a reverse mapping zone on the system using IPV6 zone format + nios_zone: + name: 100::1/128 + zone_format: IPV6 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local - name: update the comment and ext attributes for an existing zone nios_zone: name: ansible.com @@ -136,6 +163,16 @@ EXAMPLES = ''' username: admin password: admin connection: local +- name: remove the reverse mapping dns zone from the system with IPV4 zone format + nios_zone: + name: 10.10.10.0/24 + zone_format: IPV4 + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local ''' RETURN = ''' # ''' @@ -154,6 +191,7 @@ def main(): ib_spec = dict( fqdn=dict(required=True, aliases=['name'], ib_req=True, update=False), + zone_format=dict(default='FORWARD', aliases=['zone_format'], ib_req=False), view=dict(default='default', aliases=['dns_view'], ib_req=True), grid_primary=dict(type='list', elements='dict', options=grid_spec), diff --git a/test/runner/lib/cloud/nios.py b/test/runner/lib/cloud/nios.py index 67ea06945a1..5cd3284b2fb 100644 --- a/test/runner/lib/cloud/nios.py +++ b/test/runner/lib/cloud/nios.py @@ -31,7 +31,7 @@ class NiosProvider(CloudProvider): DOCKER_SIMULATOR_NAME = 'nios-simulator' - DOCKER_IMAGE = 'quay.io/ansible/nios-test-container:1.2.0' + DOCKER_IMAGE = 'quay.io/ansible/nios-test-container:1.3.0' """Default image to run the nios simulator. The simulator must be pinned to a specific version diff --git a/test/units/modules/net_tools/nios/test_nios_zone.py b/test/units/modules/net_tools/nios/test_nios_zone.py index 2f08b417379..3054ddbf028 100644 --- a/test/units/modules/net_tools/nios/test_nios_zone.py +++ b/test/units/modules/net_tools/nios/test_nios_zone.py @@ -124,3 +124,164 @@ class TestNiosZoneModule(TestNiosModule): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + + def test_nios_zone_create_using_grid_primary_secondaries(self): + self.module.params = {'provider': None, 'state': 'present', 'fqdn': 'ansible.com', + 'grid_primary': [{"name": "gridprimary.grid.com"}], + 'grid_secondaries': [{"name": "gridsecondary1.grid.com"}, + {"name": "gridsecondary2.grid.com"}], + 'restart_if_needed': True, + 'comment': None, 'extattrs': None} + + test_object = None + grid_spec = dict( + name=dict(required=True), + ) + test_spec = { + "fqdn": {"ib_req": True}, + "grid_primary": {}, + "grid_secondaries": {}, + "restart_if_needed": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + print("WAPI: ", wapi) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'fqdn': 'ansible.com', + "grid_primary": [{"name": "gridprimary.grid.com"}], + "grid_secondaries": [{"name": "gridsecondary1.grid.com"}, + {"name": "gridsecondary2.grid.com"}], + "restart_if_needed": True + }) + + def test_nios_zone_remove_using_grid_primary_secondaries(self): + self.module.params = {'provider': None, 'state': 'absent', 'fqdn': 'ansible.com', + 'grid_primary': [{"name": "gridprimary.grid.com"}], + 'grid_secondaries': [{"name": "gridsecondary1.grid.com"}, + {"name": "gridsecondary2.grid.com"}], + 'restart_if_needed': True, + 'comment': None, 'extattrs': None} + + ref = "zone/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false" + + test_object = [{ + "comment": "test comment", + "_ref": ref, + "fqdn": "ansible.com", + "grid_primary": [{"name": "gridprimary.grid.com"}], + "grid_secondaries": [{"name": "gridsecondary1.grid.com"}, {"name": "gridsecondary2.grid.com"}], + "restart_if_needed": True, + "extattrs": {'Site': {'value': 'test'}} + }] + + test_spec = { + "fqdn": {"ib_req": True}, + "grid_primary": {}, + "grid_secondaries": {}, + "restart_if_needed": {}, + "comment": {}, + "extattrs": {} + } + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) + + def test_nios_zone_create_using_name_server_group(self): + self.module.params = {'provider': None, 'state': 'present', 'fqdn': 'ansible.com', + 'ns_group': 'examplensg', 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "fqdn": {"ib_req": True}, + "ns_group": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + print("WAPI: ", wapi) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'fqdn': 'ansible.com', + 'ns_group': 'examplensg'}) + + def test_nios_zone_remove_using_name_server_group(self): + self.module.params = {'provider': None, 'state': 'absent', 'fqdn': 'ansible.com', + 'ns_group': 'examplensg', 'comment': None, 'extattrs': None} + + ref = "zone/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false" + + test_object = [{ + "comment": "test comment", + "_ref": ref, + "fqdn": "ansible.com", + "ns_group": "examplensg", + "extattrs": {'Site': {'value': 'test'}} + }] + + test_spec = { + "fqdn": {"ib_req": True}, + "ns_group": {}, + "comment": {}, + "extattrs": {} + } + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) + + def test_nios_zone_create_using_zone_format(self): + self.module.params = {'provider': None, 'state': 'present', 'fqdn': '10.10.10.in-addr.arpa', + 'zone_format': 'IPV4', 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "fqdn": {"ib_req": True}, + "zone_format": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + print("WAPI: ", wapi) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'fqdn': '10.10.10.in-addr.arpa', + 'zone_format': 'IPV4'}) + + def test_nios_zone_remove_using_using_zone_format(self): + self.module.params = {'provider': None, 'state': 'absent', 'fqdn': 'ansible.com', + 'zone_format': 'IPV4', 'comment': None, 'extattrs': None} + + ref = "zone/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/false" + + test_object = [{ + "comment": "test comment", + "_ref": ref, + "fqdn": "ansible.com", + "zone_format": "IPV4", + "extattrs": {'Site': {'value': 'test'}} + }] + + test_spec = { + "fqdn": {"ib_req": True}, + "zone_format": {}, + "comment": {}, + "extattrs": {} + } + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref)