From e4a6d64bc5f84aaf6c2d6bcdd69bedfe979de7ce Mon Sep 17 00:00:00 2001 From: nitish-ks Date: Mon, 18 Nov 2024 21:45:22 -0800 Subject: [PATCH 01/10] Fix for vLan modules --- plugins/module_utils/api.py | 6 +++++- plugins/modules/nios_network.py | 3 ++- plugins/modules/nios_vlan.py | 5 ++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index f78c5cee..f5431d88 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -417,6 +417,10 @@ def run(self, ib_obj_type, ib_spec): if 'default_value' in obj: obj['default_value'] = str(obj['default_value']) + if (ib_obj_type == NIOS_VLAN): + if 'parent' in current_object: + current_object['parent'] = current_object['parent']['_ref'] + # checks if the 'text' field has to be updated for the TXT Record if (ib_obj_type == NIOS_TXT_RECORD): text_obj = proposed_object["text"] @@ -696,7 +700,7 @@ def compare_objects(self, current_object, proposed_object): # If the lists are of a different length, the objects cannot be # equal, and False will be returned before comparing the list items # this code part will work for members' assignment - if (key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members') + if (key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members', 'vlans') and (len(proposed_item) != len(current_item))): return False diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index 532cc8e4..474ae64c 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -88,6 +88,7 @@ of values (see suboptions). When configuring suboptions at least one of C(name) or C(id) must be specified. type: list + default: [] elements: dict suboptions: name: @@ -430,7 +431,7 @@ def vlans(module): network=dict(required=True, aliases=['name', 'cidr'], ib_req=True), network_view=dict(default='default', ib_req=True), options=dict(type='list', elements='dict', options=option_spec, transform=options, default=[]), - vlans=dict(type='list', elements='dict', options=vlans_spec, transform=vlans), + vlans=dict(type='list', elements='dict', options=vlans_spec, transform=vlans, default=[]), template=dict(type='str'), extattrs=dict(type='dict'), comment=dict(), diff --git a/plugins/modules/nios_vlan.py b/plugins/modules/nios_vlan.py index b769d377..23709949 100644 --- a/plugins/modules/nios_vlan.py +++ b/plugins/modules/nios_vlan.py @@ -11,7 +11,7 @@ module: nios_vlan author: "Christoph Spatt (@edeka-spatt)" short_description: Configure Infoblox NIOS VLANs -version_added: "1.4.3" +version_added: "1.8.0" description: - Adds and/or removes instances of vlan objects from Infoblox NIOS servers. This module manages NIOS C(vlan) objects @@ -39,10 +39,9 @@ description: - Specifies the vlan parent to add or remove from the system. Can be either a C(vlanview) or C(vlanrange) - name. Feteches the required _ref object automatically. + name. Fetches the required _ref object automatically. If not specified defaults to vlan view C(default). type: str - default: default required: true comment: description: From 1b64e6c043f6f9315a38a0c74b28aa27356ab55a Mon Sep 17 00:00:00 2001 From: nitish-ks Date: Tue, 19 Nov 2024 00:37:55 -0800 Subject: [PATCH 02/10] Fixed sanity issues related to vlan parent --- plugins/modules/nios_network.py | 1 + plugins/modules/nios_vlan.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index 474ae64c..0f16410c 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -103,6 +103,7 @@ description: - The name of the parent vlanview or vlanrange. type: str + default: default extattrs: description: - Allows for the configuration of Extensible Attributes on the diff --git a/plugins/modules/nios_vlan.py b/plugins/modules/nios_vlan.py index 23709949..25c3d926 100644 --- a/plugins/modules/nios_vlan.py +++ b/plugins/modules/nios_vlan.py @@ -42,7 +42,7 @@ name. Fetches the required _ref object automatically. If not specified defaults to vlan view C(default). type: str - required: true + default: default comment: description: - Configures a text string comment to be associated with the instance From fa931b84af09182661803dd157095bd675a563cd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 19 Nov 2024 09:32:14 +0000 Subject: [PATCH 03/10] Removed trailing whitespaces --- plugins/modules/nios_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index 0f16410c..2b3752c3 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -401,7 +401,7 @@ def vlans(module): vlan_filtered['parent'] = obj_vlanrange[0]['_ref'] else: module.fail_json(msg='VLAN View/Range \'%s\' cannot be found.' % vlan_filtered['parent']) - + obj_vlan = wapi.get_object('vlan', vlan_filtered) if obj_vlan: @@ -410,7 +410,7 @@ def vlans(module): module.fail_json(msg='VLAN `%s` cannot be found.' % vlan['name']) return vlans_list - + option_spec = dict( # one of name or num is required; enforced by the function options() name=dict(), From 33d914372693f0e44edd175a7a17c54103f26563 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 4 Dec 2024 10:33:21 +0000 Subject: [PATCH 04/10] Fixed vLan parent transform --- plugins/modules/nios_vlan.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/nios_vlan.py b/plugins/modules/nios_vlan.py index 25c3d926..d7268c2e 100644 --- a/plugins/modules/nios_vlan.py +++ b/plugins/modules/nios_vlan.py @@ -150,10 +150,10 @@ def parent_transform(module): if module.params['parent']: parent_obj_vlanview = wapi.get_object('vlanview', {'name': module.params['parent']}) parent_obj_vlanrange = wapi.get_object('vlanrange', {'name': module.params['parent']}) - if parent_obj_vlanview and not parent_obj_vlanrange: - parent_ref = parent_obj_vlanview[0]['_ref'] - elif not parent_obj_vlanview and parent_obj_vlanrange: + if parent_obj_vlanrange: parent_ref = parent_obj_vlanrange[0]['_ref'] + elif parent_obj_vlanview: + parent_ref = parent_obj_vlanview[0]['_ref'] else: module.fail_json(msg='VLAN View/Range \'%s\' cannot be found.' % module.params['parent']) return parent_ref From cc2325a3f66db3580f175a2b6a9709f2f63cea84 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 4 Dec 2024 10:44:31 +0000 Subject: [PATCH 05/10] Fixed vLan transform in network --- plugins/modules/nios_network.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index 2b3752c3..1f108cc1 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -395,10 +395,10 @@ def vlans(module): if 'parent' in vlan_filtered: obj_vlanview = wapi.get_object('vlanview', {'name': vlan_filtered['parent']}) obj_vlanrange = wapi.get_object('vlanrange', {'name': vlan_filtered['parent']}) - if obj_vlanview and not obj_vlanrange: - vlan_filtered['parent'] = obj_vlanview[0]['_ref'] - elif not obj_vlanview and obj_vlanrange: + if obj_vlanrange: vlan_filtered['parent'] = obj_vlanrange[0]['_ref'] + elif obj_vlanview: + vlan_filtered['parent'] = obj_vlanview[0]['_ref'] else: module.fail_json(msg='VLAN View/Range \'%s\' cannot be found.' % vlan_filtered['parent']) From f12c22669e1e45c0222094b9a33419b599bee475 Mon Sep 17 00:00:00 2001 From: Nitish KS Date: Thu, 12 Dec 2024 16:59:56 +0530 Subject: [PATCH 06/10] Added unit tests for vLAN --- .../unit/plugins/modules/test_nios_network.py | 90 +++++++++ tests/unit/plugins/modules/test_nios_vlan.py | 180 ++++++++++++++++++ 2 files changed, 270 insertions(+) create mode 100644 tests/unit/plugins/modules/test_nios_vlan.py diff --git a/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index df9b0464..29f0e8d2 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -314,3 +314,93 @@ def test_nios_network_ipv4_update_with_use_logic_filter_rules(self): 'use_logic_filter_rules': True, 'logic_filter_rules': []} ) + + def test_nios_network_ipv4_create_with_vlan(self): + self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', + 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan', + 'parent': 'default' ,'id': '10'}]} + + test_object = None + test_spec = { + "network": {"ib_req": True}, + "comment": {}, + "extattrs": {}, + "vlans": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_IPV4_NETWORK', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('NIOS_IPV4_NETWORK', {'network': '192.168.10.0/24', + 'vlans': [{'name':'ansible_vlan', + 'parent': 'default' ,'id': '10'}] + } + ) + + def test_nios_network_ipv4_update_vlan(self): + self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', + 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan1', + 'parent': 'default' ,'id': '10'}, + {'name':'ansible_vlan2', + 'parent': 'default' ,'id': '20'}]} + ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "network": "192.168.10.0/24", + "vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}] + } + ] + test_spec = { + "network": {"ib_req": True}, + "comment": {}, + "extattrs": {}, + "vlans": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_IPV4_NETWORK', test_spec) + + self.assertTrue(res['changed']) + + wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24', + 'vlans': [{'name':'ansible_vlan1', + 'parent': 'default' ,'id': '10'}, + {'name':'ansible_vlan2', + 'parent': 'default' ,'id': '20'}] + } + ) + + def test_nios_network_ipv4_remove_vlan(self): + self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', + 'comment': None, 'extattrs': None, 'vlans': []} + ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "network": "192.168.10.0/24", + "vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}, + {'name':'ansible_vlan2', 'parent': 'default' ,'id': '20'} + ] + } + ] + test_spec = { + "network": {"ib_req": True}, + "comment": {}, + "extattrs": {}, + "vlans": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_IPV4_NETWORK', test_spec) + + self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24', + 'vlans': [] + } + ) diff --git a/tests/unit/plugins/modules/test_nios_vlan.py b/tests/unit/plugins/modules/test_nios_vlan.py new file mode 100644 index 00000000..8b1c5c98 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_vlan.py @@ -0,0 +1,180 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_vlan +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosVlanModule(TestNiosModule): + + module = nios_vlan + + def setUp(self): + super(TestNiosVlanModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_vlan.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_vlan.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_vlan.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosVlanModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_vlan_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible_vlan', + 'parent': 'default', 'id': '10', 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "parent": {"ib_req": True}, + "id": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + print("WAPI: ", wapi.__dict__) + res = wapi.run('NIOS_VLAN', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('NIOS_VLAN', {'name': 'ansible_vlan', + 'parent': 'default', 'id': '10'}) + + def test_nios_vlan_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible_vlan', + 'parent': 'default', 'id': '10', 'comment': 'updated comment', + 'contact': 'contact@email.com', 'department': 'IT', 'description': 'test', + 'reserved': True,'extattrs': None} + + ref = "vlan/ZG5zLm5ldHdvcmtfdmlldyQw:ansible_vlan" + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "ansible_vlan", + "parent": "default", + "id": "10", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "parent": {"ib_req": True}, + "id": {"ib_req": True}, + "comment": {}, + "contact": {}, + "department": {}, + "description": {}, + "reserved": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_VLAN', test_spec) + self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'parent': 'default', 'id': '10', 'name': 'ansible_vlan', + 'contact': 'contact@email.com', 'department': 'IT', 'description': 'test', 'reserved': True} + ) + + def test_nios_vlan_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible_vlan', + 'parent': 'default', 'id': '10', 'comment': None, 'extattrs': None} + + ref = "vlan/ZG5zLm5ldHdvcmtfdmlldyQw:ansible_vlan" + + test_object = [{ + "comment": "test comment", + "_ref": ref, + "name": "ansible_vlan", + "parent": "default", + "id": "10", + "extattrs": {'Site': {'value': 'test'}} + }] + + test_spec = { + "name": {"ib_req": True}, + "parent": {"ib_req": True}, + "id": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_VLAN', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) + + def test_nios_vlan_update_record_name(self): + self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'ansible_new_vlan', 'old_name': 'ansible_vlan'}, + 'parent': 'default', 'id': '10', 'comment': 'comment', 'extattrs': None} + + ref = "vlan/ZG5zLm5ldHdvcmtfdmlldyQw:ansible_new_vlan" + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "ansible_vlan", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "parent": {"ib_req": True}, + "id": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('NIOS_VLAN', test_spec) + + self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'name': 'ansible_new_vlan', 'parent': 'default', 'id': '10', + 'comment': 'comment'}) \ No newline at end of file From 05d48db45347da03319ee275422e5172ad0626cc Mon Sep 17 00:00:00 2001 From: Nitish KS Date: Tue, 17 Dec 2024 13:56:26 +0530 Subject: [PATCH 07/10] Updated examples for vLAN --- plugins/modules/nios_vlan.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/modules/nios_vlan.py b/plugins/modules/nios_vlan.py index d7268c2e..209dc193 100644 --- a/plugins/modules/nios_vlan.py +++ b/plugins/modules/nios_vlan.py @@ -91,7 +91,7 @@ infoblox.nios_modules.nios_vlan: name: ansible id: 10 - parent: default + parent: my_vlanview state: present provider: host: "{{ inventory_hostname_short }}" @@ -103,6 +103,7 @@ infoblox.nios_modules.nios_vlan: name: ansible id: 10 + parent: my_vlanview comment: this is an example comment state: present provider: @@ -115,6 +116,7 @@ infoblox.nios_modules.nios_vlan: name: ansible id: 10 + parent: my_vlanview state: absent provider: host: "{{ inventory_hostname_short }}" @@ -125,6 +127,27 @@ - name: Update an existing vlan infoblox.nios_modules.nios_vlan: name: {new_name: ansible-new, old_name: ansible} + id: 10 + parent: my_vlanview + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Create vlan with extensible attributes + infoblox.nios_modules.nios_vlan: + name: ansible + id: 11 + parent: my_vlanview + comment: "this is an example comment" + contact: "itlab@email.com" + department: "IT" + description: "test" + reserved: True + extattrs: + Site: "HQ" state: present provider: host: "{{ inventory_hostname_short }}" From 38a5e9d80c55615c84d997f88b6e8304855f6f72 Mon Sep 17 00:00:00 2001 From: Nitish KS Date: Tue, 7 Jan 2025 16:42:30 +0530 Subject: [PATCH 08/10] Fix sanity and unit tests --- .github/workflows/ansible-test.yml | 2 +- tests/unit/plugins/modules/test_extensible_attribute.py | 1 - tests/unit/plugins/modules/test_nios_a_record.py | 1 - tests/unit/plugins/modules/test_nios_aaaa_record.py | 1 - tests/unit/plugins/modules/test_nios_cname_record.py | 1 - tests/unit/plugins/modules/test_nios_dns_view.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_http.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py | 1 - tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py | 1 - tests/unit/plugins/modules/test_nios_dtc_topology.py | 1 - tests/unit/plugins/modules/test_nios_fixed_address.py | 1 - tests/unit/plugins/modules/test_nios_host_record.py | 1 - tests/unit/plugins/modules/test_nios_member.py | 1 - tests/unit/plugins/modules/test_nios_mx_record.py | 1 - tests/unit/plugins/modules/test_nios_naptr_record.py | 1 - tests/unit/plugins/modules/test_nios_network.py | 9 ++++----- tests/unit/plugins/modules/test_nios_network_view.py | 1 - tests/unit/plugins/modules/test_nios_nsgroup.py | 1 - tests/unit/plugins/modules/test_nios_ptr_record.py | 1 - tests/unit/plugins/modules/test_nios_srv_record.py | 1 - tests/unit/plugins/modules/test_nios_vlan.py | 3 +-- tests/unit/plugins/modules/test_nios_zone.py | 1 - 25 files changed, 6 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index cbf2666e..52191faa 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -162,7 +162,7 @@ jobs: echo $ANSIBLE_NIOSSIM_CONTAINER ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python-version }} --docker --coverage env: - ANSIBLE_NIOSSIM_CONTAINER: quay.io/ansible/nios-test-container:6.0.0 + ANSIBLE_NIOSSIM_CONTAINER: quay.io/ansible/nios-test-container:7.0.0 working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/ # ansible-test support producing code coverage date diff --git a/tests/unit/plugins/modules/test_extensible_attribute.py b/tests/unit/plugins/modules/test_extensible_attribute.py index faafcc89..5dceeb97 100644 --- a/tests/unit/plugins/modules/test_extensible_attribute.py +++ b/tests/unit/plugins/modules/test_extensible_attribute.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_extensible_attribute.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_extensible_attribute.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_a_record.py b/tests/unit/plugins/modules/test_nios_a_record.py index 9234f9c7..7d58603e 100644 --- a/tests/unit/plugins/modules/test_nios_a_record.py +++ b/tests/unit/plugins/modules/test_nios_a_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_a_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_a_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_aaaa_record.py b/tests/unit/plugins/modules/test_nios_aaaa_record.py index 10b6e18d..ecd0c65d 100644 --- a/tests/unit/plugins/modules/test_nios_aaaa_record.py +++ b/tests/unit/plugins/modules/test_nios_aaaa_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_aaaa_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_aaaa_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_cname_record.py b/tests/unit/plugins/modules/test_nios_cname_record.py index 3ad17abd..d5a9aebe 100644 --- a/tests/unit/plugins/modules/test_nios_cname_record.py +++ b/tests/unit/plugins/modules/test_nios_cname_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_cname_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_cname_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dns_view.py b/tests/unit/plugins/modules/test_nios_dns_view.py index ba003c8f..ad94a1a1 100644 --- a/tests/unit/plugins/modules/test_nios_dns_view.py +++ b/tests/unit/plugins/modules/test_nios_dns_view.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dns_view.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dns_view.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py index 037ea92b..fb72b5a3 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py index 78f13365..3a7078c2 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py index 0fb63682..eb0d076e 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py index 6e170d75..584074c6 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py index 374b5a67..f0c31a5a 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py index 8de3d25f..93728dff 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_dtc_topology.py b/tests/unit/plugins/modules/test_nios_dtc_topology.py index 6a11515b..43d23404 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_topology.py +++ b/tests/unit/plugins/modules/test_nios_dtc_topology.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_fixed_address.py b/tests/unit/plugins/modules/test_nios_fixed_address.py index ba435b76..394cda29 100644 --- a/tests/unit/plugins/modules/test_nios_fixed_address.py +++ b/tests/unit/plugins/modules/test_nios_fixed_address.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_fixed_address.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_fixed_address.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() def tearDown(self): diff --git a/tests/unit/plugins/modules/test_nios_host_record.py b/tests/unit/plugins/modules/test_nios_host_record.py index 7bc72337..ae309e8d 100644 --- a/tests/unit/plugins/modules/test_nios_host_record.py +++ b/tests/unit/plugins/modules/test_nios_host_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_host_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_host_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') diff --git a/tests/unit/plugins/modules/test_nios_member.py b/tests/unit/plugins/modules/test_nios_member.py index c8e02ce0..0ee75a7e 100644 --- a/tests/unit/plugins/modules/test_nios_member.py +++ b/tests/unit/plugins/modules/test_nios_member.py @@ -36,7 +36,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_member.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_member.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() def tearDown(self): diff --git a/tests/unit/plugins/modules/test_nios_mx_record.py b/tests/unit/plugins/modules/test_nios_mx_record.py index 7f8db39e..12f395b6 100644 --- a/tests/unit/plugins/modules/test_nios_mx_record.py +++ b/tests/unit/plugins/modules/test_nios_mx_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_mx_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_mx_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_naptr_record.py b/tests/unit/plugins/modules/test_nios_naptr_record.py index 38c3f059..a562f374 100644 --- a/tests/unit/plugins/modules/test_nios_naptr_record.py +++ b/tests/unit/plugins/modules/test_nios_naptr_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_naptr_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_naptr_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index 29f0e8d2..7a422151 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -40,7 +40,6 @@ def setUp(self): self.mock_wapi_run = patch( 'ansible_collections.infoblox.nios_modules.plugins.modules.nios_network.WapiModule.run' ) - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() def tearDown(self): @@ -314,7 +313,7 @@ def test_nios_network_ipv4_update_with_use_logic_filter_rules(self): 'use_logic_filter_rules': True, 'logic_filter_rules': []} ) - + def test_nios_network_ipv4_create_with_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan', @@ -337,7 +336,7 @@ def test_nios_network_ipv4_create_with_vlan(self): 'parent': 'default' ,'id': '10'}] } ) - + def test_nios_network_ipv4_update_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan1', @@ -365,7 +364,7 @@ def test_nios_network_ipv4_update_vlan(self): res = wapi.run('NIOS_IPV4_NETWORK', test_spec) self.assertTrue(res['changed']) - + wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24', 'vlans': [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}, @@ -373,7 +372,7 @@ def test_nios_network_ipv4_update_vlan(self): 'parent': 'default' ,'id': '20'}] } ) - + def test_nios_network_ipv4_remove_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', 'comment': None, 'extattrs': None, 'vlans': []} diff --git a/tests/unit/plugins/modules/test_nios_network_view.py b/tests/unit/plugins/modules/test_nios_network_view.py index 24ee5fbd..0fc64eaf 100644 --- a/tests/unit/plugins/modules/test_nios_network_view.py +++ b/tests/unit/plugins/modules/test_nios_network_view.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_network_view.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_network_view.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_nsgroup.py b/tests/unit/plugins/modules/test_nios_nsgroup.py index 195ea7a7..a9452d2c 100644 --- a/tests/unit/plugins/modules/test_nios_nsgroup.py +++ b/tests/unit/plugins/modules/test_nios_nsgroup.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_nsgroup.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_nsgroup.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() diff --git a/tests/unit/plugins/modules/test_nios_ptr_record.py b/tests/unit/plugins/modules/test_nios_ptr_record.py index 68f69b9c..4840f278 100644 --- a/tests/unit/plugins/modules/test_nios_ptr_record.py +++ b/tests/unit/plugins/modules/test_nios_ptr_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_ptr_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_ptr_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() diff --git a/tests/unit/plugins/modules/test_nios_srv_record.py b/tests/unit/plugins/modules/test_nios_srv_record.py index 5c41cd4c..ed66886b 100644 --- a/tests/unit/plugins/modules/test_nios_srv_record.py +++ b/tests/unit/plugins/modules/test_nios_srv_record.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_srv_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_srv_record.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() diff --git a/tests/unit/plugins/modules/test_nios_vlan.py b/tests/unit/plugins/modules/test_nios_vlan.py index 8b1c5c98..a816915b 100644 --- a/tests/unit/plugins/modules/test_nios_vlan.py +++ b/tests/unit/plugins/modules/test_nios_vlan.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_vlan.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_vlan.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() @@ -177,4 +176,4 @@ def test_nios_vlan_update_record_name(self): self.assertTrue(res['changed']) wapi.update_object.assert_called_once_with(ref, {'name': 'ansible_new_vlan', 'parent': 'default', 'id': '10', - 'comment': 'comment'}) \ No newline at end of file + 'comment': 'comment'}) diff --git a/tests/unit/plugins/modules/test_nios_zone.py b/tests/unit/plugins/modules/test_nios_zone.py index 20230c8e..ccea7b95 100644 --- a/tests/unit/plugins/modules/test_nios_zone.py +++ b/tests/unit/plugins/modules/test_nios_zone.py @@ -38,7 +38,6 @@ def setUp(self): self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_zone.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_zone.WapiModule.run') - self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() def tearDown(self): From aa9287982c41192fce5b5946b20129656765b8f3 Mon Sep 17 00:00:00 2001 From: Nitish KS Date: Fri, 10 Jan 2025 12:39:27 +0530 Subject: [PATCH 09/10] Fix sanity and added vLAN integration tests --- tests/integration/targets/nios_vlan/aliases | 3 + .../targets/nios_vlan/defaults/main.yaml | 3 + .../targets/nios_vlan/meta/main.yaml | 3 + .../targets/nios_vlan/tasks/main.yaml | 3 + .../nios_vlan/tasks/nios_vlan_idempotence.yml | 94 +++++++++++++++++++ .../unit/plugins/modules/test_nios_network.py | 72 +++++++++----- tests/unit/plugins/modules/test_nios_vlan.py | 12 ++- 7 files changed, 162 insertions(+), 28 deletions(-) create mode 100755 tests/integration/targets/nios_vlan/aliases create mode 100755 tests/integration/targets/nios_vlan/defaults/main.yaml create mode 100755 tests/integration/targets/nios_vlan/meta/main.yaml create mode 100755 tests/integration/targets/nios_vlan/tasks/main.yaml create mode 100755 tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml diff --git a/tests/integration/targets/nios_vlan/aliases b/tests/integration/targets/nios_vlan/aliases new file mode 100755 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_vlan/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_vlan/defaults/main.yaml b/tests/integration/targets/nios_vlan/defaults/main.yaml new file mode 100755 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_vlan/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_vlan/meta/main.yaml b/tests/integration/targets/nios_vlan/meta/main.yaml new file mode 100755 index 00000000..a4ad32ff --- /dev/null +++ b/tests/integration/targets/nios_vlan/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_vlan/tasks/main.yaml b/tests/integration/targets/nios_vlan/tasks/main.yaml new file mode 100755 index 00000000..1862fa6e --- /dev/null +++ b/tests/integration/targets/nios_vlan/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Include idempotence tasks for vlan + ansible.builtin.include_tasks: nios_vlan_idempotence.yml diff --git a/tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml b/tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml new file mode 100755 index 00000000..0da35124 --- /dev/null +++ b/tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml @@ -0,0 +1,94 @@ +--- +- name: Cleanup VLAN + nios_vlan: + name: ansible-vlan + id: 10 + parent: default + state: absent + provider: "{{ nios_provider }}" + +- name: Configure a VLAN on the system + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + contact: 'example@email.com' + department: 'IT' + description: 'This is an example VLAN' + reserved: true + state: present + provider: "{{ nios_provider }}" + register: vlan_create1 + +- name: Configure another VLAN on the system + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + contact: 'example@email.com' + department: 'IT' + description: 'This is an example VLAN' + reserved: true + state: present + provider: "{{ nios_provider }}" + register: vlan_create2 + +- name: Update the comment and ext attributes for an existing VLAN + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + contact: 'example@email.com' + department: 'IT' + description: 'This is an example VLAN' + reserved: true + comment: this is an example comment + extattrs: + Site: west-dc + state: present + provider: "{{ nios_provider }}" + register: vlan_update1 + +- name: Update again the comment and ext attributes for an existing VLAN + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + contact: 'example@email.com' + department: 'IT' + description: 'This is an example VLAN' + reserved: true + comment: this is an example comment + extattrs: + Site: west-dc + state: present + provider: "{{ nios_provider }}" + register: vlan_update2 + +- name: Remove the VLAN + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + state: absent + provider: "{{ nios_provider }}" + register: vlan_delete1 + +- name: Remove again the VLAN + infoblox.nios_modules.nios_vlan: + name: ansible-vlan + id: 10 + parent: default + state: absent + provider: "{{ nios_provider }}" + register: vlan_delete2 + +- name: Assert changes in VLAN + ansible.builtin.assert: + that: + - vlan_create1.changed + - not vlan_create2.changed + - vlan_update1.changed + - not vlan_update2.changed + - vlan_delete1.changed + - not vlan_delete2.changed diff --git a/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index 7a422151..77576a57 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -316,8 +316,8 @@ def test_nios_network_ipv4_update_with_use_logic_filter_rules(self): def test_nios_network_ipv4_create_with_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', - 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan', - 'parent': 'default' ,'id': '10'}]} + 'comment': None, 'extattrs': None, 'vlans': [{'name': 'ansible_vlan', + 'parent': 'default', 'id': '10'}]} test_object = None test_spec = { @@ -331,18 +331,26 @@ def test_nios_network_ipv4_create_with_vlan(self): res = wapi.run('NIOS_IPV4_NETWORK', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('NIOS_IPV4_NETWORK', {'network': '192.168.10.0/24', - 'vlans': [{'name':'ansible_vlan', - 'parent': 'default' ,'id': '10'}] - } - ) + wapi.create_object.assert_called_once_with( + 'NIOS_IPV4_NETWORK', + { + 'network': '192.168.10.0/24', + 'vlans': [ + { + 'name': 'ansible_vlan', + 'parent': 'default', + 'id': '10' + } + ] + } + ) def test_nios_network_ipv4_update_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', - 'comment': None, 'extattrs': None, 'vlans': [{'name':'ansible_vlan1', - 'parent': 'default' ,'id': '10'}, - {'name':'ansible_vlan2', - 'parent': 'default' ,'id': '20'}]} + 'comment': None, 'extattrs': None, 'vlans': [{'name': 'ansible_vlan1', + 'parent': 'default', 'id': '10'}, + {'name': 'ansible_vlan2', + 'parent': 'default', 'id': '20'}]} ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ @@ -350,7 +358,7 @@ def test_nios_network_ipv4_update_vlan(self): "comment": "test comment", "_ref": ref, "network": "192.168.10.0/24", - "vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}] + "vlans": [{'name': 'ansible_vlan1', 'parent': 'default', 'id': '10'}] } ] test_spec = { @@ -365,13 +373,24 @@ def test_nios_network_ipv4_update_vlan(self): self.assertTrue(res['changed']) - wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24', - 'vlans': [{'name':'ansible_vlan1', - 'parent': 'default' ,'id': '10'}, - {'name':'ansible_vlan2', - 'parent': 'default' ,'id': '20'}] - } - ) + wapi.update_object.assert_called_once_with( + ref, + { + 'network': '192.168.10.0/24', + 'vlans': [ + { + 'name': 'ansible_vlan1', + 'parent': 'default', + 'id': '10' + }, + { + 'name': 'ansible_vlan2', + 'parent': 'default', + 'id': '20' + } + ] + } + ) def test_nios_network_ipv4_remove_vlan(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', @@ -383,8 +402,8 @@ def test_nios_network_ipv4_remove_vlan(self): "comment": "test comment", "_ref": ref, "network": "192.168.10.0/24", - "vlans": [{'name':'ansible_vlan1', 'parent': 'default' ,'id': '10'}, - {'name':'ansible_vlan2', 'parent': 'default' ,'id': '20'} + "vlans": [{'name': 'ansible_vlan1', 'parent': 'default', 'id': '10'}, + {'name': 'ansible_vlan2', 'parent': 'default', 'id': '20'} ] } ] @@ -399,7 +418,10 @@ def test_nios_network_ipv4_remove_vlan(self): res = wapi.run('NIOS_IPV4_NETWORK', test_spec) self.assertTrue(res['changed']) - wapi.update_object.assert_called_once_with(ref, {'network': '192.168.10.0/24', - 'vlans': [] - } - ) + wapi.update_object.assert_called_once_with( + ref, + { + 'network': '192.168.10.0/24', + 'vlans': [] + } + ) diff --git a/tests/unit/plugins/modules/test_nios_vlan.py b/tests/unit/plugins/modules/test_nios_vlan.py index a816915b..0d30bb89 100644 --- a/tests/unit/plugins/modules/test_nios_vlan.py +++ b/tests/unit/plugins/modules/test_nios_vlan.py @@ -79,14 +79,20 @@ def test_nios_vlan_create(self): res = wapi.run('NIOS_VLAN', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('NIOS_VLAN', {'name': 'ansible_vlan', - 'parent': 'default', 'id': '10'}) + wapi.create_object.assert_called_once_with( + 'NIOS_VLAN', + { + 'name': 'ansible_vlan', + 'parent': 'default', + 'id': '10' + } + ) def test_nios_vlan_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible_vlan', 'parent': 'default', 'id': '10', 'comment': 'updated comment', 'contact': 'contact@email.com', 'department': 'IT', 'description': 'test', - 'reserved': True,'extattrs': None} + 'reserved': True, 'extattrs': None} ref = "vlan/ZG5zLm5ldHdvcmtfdmlldyQw:ansible_vlan" test_object = [ From 03aab0df90108022a51f01c98370e8e3c9a61813 Mon Sep 17 00:00:00 2001 From: Nitish KS Date: Fri, 10 Jan 2025 13:25:39 +0530 Subject: [PATCH 10/10] corrected file permissions --- tests/integration/targets/nios_vlan/aliases | 0 .../integration/targets/nios_vlan/defaults/main.yaml | 0 tests/integration/targets/nios_vlan/meta/main.yaml | 0 tests/integration/targets/nios_vlan/tasks/main.yaml | 0 .../nios_vlan/tasks/nios_vlan_idempotence.yml | 0 tests/unit/plugins/modules/test_nios_network.py | 12 ++++++------ tests/unit/plugins/modules/test_nios_vlan.py | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) mode change 100755 => 100644 tests/integration/targets/nios_vlan/aliases mode change 100755 => 100644 tests/integration/targets/nios_vlan/defaults/main.yaml mode change 100755 => 100644 tests/integration/targets/nios_vlan/meta/main.yaml mode change 100755 => 100644 tests/integration/targets/nios_vlan/tasks/main.yaml mode change 100755 => 100644 tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml diff --git a/tests/integration/targets/nios_vlan/aliases b/tests/integration/targets/nios_vlan/aliases old mode 100755 new mode 100644 diff --git a/tests/integration/targets/nios_vlan/defaults/main.yaml b/tests/integration/targets/nios_vlan/defaults/main.yaml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/nios_vlan/meta/main.yaml b/tests/integration/targets/nios_vlan/meta/main.yaml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/nios_vlan/tasks/main.yaml b/tests/integration/targets/nios_vlan/tasks/main.yaml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml b/tests/integration/targets/nios_vlan/tasks/nios_vlan_idempotence.yml old mode 100755 new mode 100644 diff --git a/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index 77576a57..b74be41a 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -332,13 +332,13 @@ def test_nios_network_ipv4_create_with_vlan(self): self.assertTrue(res['changed']) wapi.create_object.assert_called_once_with( - 'NIOS_IPV4_NETWORK', + 'NIOS_IPV4_NETWORK', { 'network': '192.168.10.0/24', 'vlans': [ { 'name': 'ansible_vlan', - 'parent': 'default', + 'parent': 'default', 'id': '10' } ] @@ -374,18 +374,18 @@ def test_nios_network_ipv4_update_vlan(self): self.assertTrue(res['changed']) wapi.update_object.assert_called_once_with( - ref, + ref, { 'network': '192.168.10.0/24', 'vlans': [ { 'name': 'ansible_vlan1', - 'parent': 'default', + 'parent': 'default', 'id': '10' }, { 'name': 'ansible_vlan2', - 'parent': 'default', + 'parent': 'default', 'id': '20' } ] @@ -419,7 +419,7 @@ def test_nios_network_ipv4_remove_vlan(self): self.assertTrue(res['changed']) wapi.update_object.assert_called_once_with( - ref, + ref, { 'network': '192.168.10.0/24', 'vlans': [] diff --git a/tests/unit/plugins/modules/test_nios_vlan.py b/tests/unit/plugins/modules/test_nios_vlan.py index 0d30bb89..e120f474 100644 --- a/tests/unit/plugins/modules/test_nios_vlan.py +++ b/tests/unit/plugins/modules/test_nios_vlan.py @@ -80,10 +80,10 @@ def test_nios_vlan_create(self): self.assertTrue(res['changed']) wapi.create_object.assert_called_once_with( - 'NIOS_VLAN', + 'NIOS_VLAN', { 'name': 'ansible_vlan', - 'parent': 'default', + 'parent': 'default', 'id': '10' } )