From 85df85e9336f20337469802039d17f1b6750ce65 Mon Sep 17 00:00:00 2001 From: Jeenitkumar Khatri <58591067+JkhatriInfobox@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:59:43 +0530 Subject: [PATCH] Ea definition support (#235) * Attributes (#4) * Add extensible attribute module * added choices to IB_spec * doco * Add the struct creation to api * doco * pep and lint * fix pep issues * Add flags for extensible attributes (#5) (#6) * Extensible attributes module - support flags infobloxopen/infoblox-ansible/#186 add support for flags to the extensible attributes module * Extensible attributes - fix linting reported by the ansible sanity tests --------- Co-authored-by: Hugues Malphettes * Documentation update fix doco line length fix line length PEP issue pep issue * [FIX] CI execution for unit test * [FIX] Github workflows for CI Run Updated workflow file to support ansible-stable 2.17 and removed 2.14 [FIX] coverage report for stable-2.16 [FIX] changed called_once_with to assert_called_once_with for unit tests [FIX] compact file deprication for ansible-2.17 * [FIX] Updated unit test case by replacing called_once_with to assert_called_once_with for python3.12 * Updated data type for Min and Max from str to int --------- Co-authored-by: matthewdennett <52452990+matthewdennett@users.noreply.github.com> Co-authored-by: matt Co-authored-by: Hugues Malphettes --- .github/workflows/ansible-test.yml | 58 ++--- plugins/lookup/nios_next_ip.py | 15 +- plugins/module_utils/api.py | 12 + plugins/modules/nios_extensible_attribute.py | 226 ++++++++++++++++++ tests/unit/compat/mock.py | 6 +- tests/unit/plugins/module_utils/test_api.py | 18 +- .../plugins/modules/test_nios_a_record.py | 15 +- .../plugins/modules/test_nios_aaaa_record.py | 19 +- .../plugins/modules/test_nios_cname_record.py | 8 +- .../plugins/modules/test_nios_dns_view.py | 7 +- .../modules/test_nios_dtc_monitor_http.py | 4 +- .../modules/test_nios_dtc_monitor_icmp.py | 4 +- .../modules/test_nios_dtc_monitor_pdp.py | 4 +- .../modules/test_nios_dtc_monitor_sip.py | 5 +- .../modules/test_nios_dtc_monitor_snmp.py | 5 +- .../modules/test_nios_dtc_monitor_tcp.py | 4 +- .../plugins/modules/test_nios_dtc_topology.py | 5 +- .../modules/test_nios_fixed_address.py | 13 +- .../plugins/modules/test_nios_host_record.py | 17 +- .../unit/plugins/modules/test_nios_member.py | 10 +- .../plugins/modules/test_nios_mx_record.py | 6 +- .../plugins/modules/test_nios_naptr_record.py | 5 +- .../unit/plugins/modules/test_nios_network.py | 8 +- .../plugins/modules/test_nios_network_view.py | 21 +- .../unit/plugins/modules/test_nios_nsgroup.py | 7 +- .../plugins/modules/test_nios_ptr_record.py | 16 +- .../plugins/modules/test_nios_srv_record.py | 6 +- tests/unit/plugins/modules/test_nios_zone.py | 5 +- tests/unit/requirements.txt | 1 - 29 files changed, 424 insertions(+), 106 deletions(-) create mode 100644 plugins/modules/nios_extensible_attribute.py diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 0d14379b..893d066c 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -13,15 +13,15 @@ jobs: strategy: fail-fast: false matrix: - ansible-version: [stable-2.14] + ansible-version: [stable-2.15] steps: - name: Check out code uses: actions/checkout@v2 - - name: Set up Python 3.10 - uses: actions/setup-python@v1 + - name: Set up Python 3.11 + uses: actions/setup-python@v2 with: - python-version: '3.10' + python-version: '3.11' - name: Install ansible (${{ matrix.ansible-version }}) run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check @@ -48,25 +48,25 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] + python-version: ['3.9', '3.10', '3.11', '3.12'] + ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel] exclude: - ansible-version: devel - python-version: '3.8' + python-version: '3.11' + - ansible-version: devel + python-version: '3.10' - ansible-version: devel python-version: '3.9' - - ansible-version: stable-2.16 - python-version: '3.8' + - ansible-version: stable-2.17 + python-version: '3.9' - ansible-version: stable-2.16 python-version: '3.9' - ansible-version: stable-2.15 - python-version: '3.8' - - ansible-version: stable-2.14 - python-version: '3.8' + python-version: '3.12' steps: - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} @@ -83,7 +83,7 @@ jobs: run: | ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz git clone https://github.com/ansible/ansible.git -b ${{ matrix.ansible-version }} - if [ "${{ matrix.ansible-version }}" != "devel" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi + if [ "${{ matrix.ansible-version }}" != "devel" ] && [ "${{ matrix.ansible-version }}" != "stable-2.17" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi cp -rf ansible/test/units/modules/utils.py /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/ sed -i 's/units/ansible_collections.infoblox.nios_modules.tests.unit/' /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py if [ -f /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt ]; then pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt; fi @@ -93,8 +93,8 @@ jobs: - name: Generate coverage report run: | - if [ "${{ matrix.ansible-version }}" == "stable-2.14" ]; then - pip install coverage==6.5.0; + if [ "${{ matrix.ansible-version }}" == "devel" ]; then + pip install coverage==7.5.3; elif [ "${{ matrix.ansible-version }}" == "stable-2.15" ]; then pip install coverage==6.5.0; fi @@ -114,24 +114,24 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] + python-version: ['3.9', '3.10', '3.11', '3.12'] + ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel] exclude: - ansible-version: devel - python-version: '3.8' + python-version: '3.11' + - ansible-version: devel + python-version: '3.10' - ansible-version: devel python-version: '3.9' - - ansible-version: stable-2.16 - python-version: '3.8' + - ansible-version: stable-2.17 + python-version: '3.9' - ansible-version: stable-2.16 python-version: '3.9' - ansible-version: stable-2.15 - python-version: '3.8' - - ansible-version: stable-2.14 - python-version: '3.8' + python-version: '3.12' steps: - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} @@ -186,15 +186,15 @@ jobs: strategy: fail-fast: false matrix: - ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] + ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel] steps: - - name: Set up Python 3.10 - uses: actions/setup-python@v1 + - name: Set up Python 3.11 + uses: actions/setup-python@v2 with: # it is just required to run that once as "ansible-test sanity" in the docker image # will run on all python versions it supports. - python-version: '3.10' + python-version: 3.11 - name: Install ansible (${{ matrix.ansible-version }}) version run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check diff --git a/plugins/lookup/nios_next_ip.py b/plugins/lookup/nios_next_ip.py index 9b5d243f..41a9c6bc 100644 --- a/plugins/lookup/nios_next_ip.py +++ b/plugins/lookup/nios_next_ip.py @@ -48,21 +48,23 @@ EXAMPLES = """ - name: return next available IP address for network 192.168.10.0/24 ansible.builtin.set_fact: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" - name: return next available IP address for network 192.168.10.0/24 from DHCP range ansible.builtin.set_fact: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', use_range=true, provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', use_range=true, + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" - name: return next available IP address for network 192.168.10.0/24 in a non-default network view ansible.builtin.set_fact: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', network_view='ansible', \ + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', network_view='ansible', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" - name: return the next 3 available IP addresses for network 192.168.10.0/24 ansible.builtin.set_fact: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, - provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, \ + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" - name: return the next 3 available IP addresses for network 192.168.10.0/24 excluding ip addresses - ['192.168.10.1', '192.168.10.2'] ansible.builtin.set_fact: @@ -71,7 +73,8 @@ - name: return next available IP address for network fd30:f52:2:12::/64 ansible.builtin.set_fact: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', 'fd30:f52:2:12::/64', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', 'fd30:f52:2:12::/64', + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" """ RETURN = """ diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 3a586193..a6303369 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -78,6 +78,7 @@ NIOS_DTC_MONITOR_SNMP = 'dtc:monitor:snmp' NIOS_DTC_MONITOR_TCP = 'dtc:monitor:tcp' NIOS_DTC_TOPOLOGY = 'dtc:topology' +NIOS_EXTENSIBLE_ATTRIBUTE = 'extensibleattributedef' NIOS_PROVIDER_SPEC = { 'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])), @@ -214,6 +215,14 @@ def convert_members_to_struct(member_spec): return member_spec +def convert_ea_list_to_struct(member_spec): + ''' Transforms the list of the values into a valid WAPI struct. + ''' + if 'list_values' in member_spec.keys(): + member_spec['list_values'] = [{'_struct': 'extensibleattributedef:listvalues', 'value': v} for v in member_spec['list_values']] + return member_spec + + def normalize_ib_spec(ib_spec): result = {} for arg in ib_spec: @@ -381,6 +390,9 @@ def run(self, ib_obj_type, ib_spec): proposed_object['end_addr'] = proposed_object.get('new_end_addr') del proposed_object['new_end_addr'] + if (ib_obj_type == NIOS_EXTENSIBLE_ATTRIBUTE): + proposed_object = convert_ea_list_to_struct(proposed_object) + # 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"] diff --git a/plugins/modules/nios_extensible_attribute.py b/plugins/modules/nios_extensible_attribute.py new file mode 100644 index 00000000..50e6b9ff --- /dev/null +++ b/plugins/modules/nios_extensible_attribute.py @@ -0,0 +1,226 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_extensible_attribute +author: + - "Matthew Dennett (@matthewdennett)" + - "Hugues Malphettes (@hmalphettes)" +short_description: Configure Infoblox NIOS extensible attribute definition +version_added: "1.7.0" +description: + - Adds and/or removes a extensible attribute definition objects from + Infoblox NIOS servers. This module manages NIOS C(extensibleattributedef) + objects using the Infoblox WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + default_value: + description: + - Configures the default value which is pre populated in the GUI when + this attribute is used. Email, URL and string types the value is a + with a maximum of 256 characters. + type: str + list_values: + description: + - Configures a list of preset values associated with the instance of this + object. Only applicable when the attribute type is set to ENUM. + type: list + elements: str + max: + description: + - Configures the maximum value to be associated with the instance of + this object. When provided for an extensible attribute of type + STRING the value represents the maximum number of characters the string + can contain. When provided for an extensible attribute of type INTEGER + the value represents the maximum integer value permitted.Not + applicable for other attributes types. + type: int + min: + description: + - Configures the minimum value to be associated with the instance of + this object. When provided for an extensible attribute of type + STRING the value represents the minimum number of characters the string + can contain. When provided for an extensible attribute of type INTEGER + the value represents the minimum integer value permitted. Not + applicable for other attributes types. + type: int + name: + description: + - Configures the intended name of the instance of the object on the + NIOS server. + type: str + required: true + type: + description: + - Configures the intended type for this attribute object definition + on the NIOS server. + type: str + default: STRING + choices: + - DATE + - EMAIL + - ENUM + - INTEGER + - STRING + - URL + flags: + description: + - This field contains extensible attribute flags. + The possible values are (A)udited, (C)loud API, Cloud (G)master, (I)nheritable, (L)isted, (M)andatory value, + MGM (P)rivate, (R)ead Only, (S)ort enum values, Multiple (V)alues. + If there are two or more flags in the field, you must list them according to the order they are listed above. + For example, "CR" is a valid value for the "flags" field because C = Cloud API is listed before R = Read only. + However, the value "RC" is invalid because the order for the "flags" field is broken. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + type: str + default: present + choices: + - present + - absent +''' + +EXAMPLES = ''' +- name: Configure an extensible attribute + infoblox.nios_modules.nios_extensible_attribute: + name: my_string + type: STRING + comment: Created by ansible + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Update an extensible attribute to accept multiple values + infoblox.nios_modules.nios_extensible_attribute: + name: my_string + type: STRING + flags: V + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a extensible attribute + infoblox.nios_modules.nios_extensible_attribute: + name: my_string + type: INTEGER + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Create INT extensible attribute + infoblox.nios_modules.nios_extensible_attribute: + name: my_int + type: INTEGER + comment: Created by ansible + min: 10 + max: 20 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Update an extensible attribute + infoblox.nios_modules.nios_extensible_attribute: + name: my_int + type: INTEGER + comment: Updated by ansible + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Create an list extensible attribute + infoblox.nios_modules.nios_extensible_attribute: + name: my_list + type: ENUM + state: present + list_values: + - one + - two + - three + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import normalize_ib_spec +from ..module_utils.api import NIOS_EXTENSIBLE_ATTRIBUTE + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + comment=dict(type='str'), + default_value=dict(type='str'), + list_values=dict(type='list', elements='str'), + max=dict(type='int'), + min=dict(type='int'), + flags=dict(type='str'), + name=dict(type='str', required=True, ib_req=True), + type=dict(type='str', default='STRING', + choices=['DATE', 'EMAIL', 'ENUM', 'INTEGER', 'STRING', 'URL']) + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + + result = wapi.run(NIOS_EXTENSIBLE_ATTRIBUTE, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py index ba8455bf..802cf61e 100644 --- a/tests/unit/compat/mock.py +++ b/tests/unit/compat/mock.py @@ -64,8 +64,7 @@ def _iterate_read_data(read_data): # newline that our naive format() added data_as_list[-1] = data_as_list[-1][:-1] - for line in data_as_list: - yield line + yield from data_as_list def mock_open(mock=None, read_data=''): """ @@ -91,8 +90,7 @@ def _readline_side_effect(): if handle.readline.return_value is not None: while True: yield handle.readline.return_value - for line in _data: - yield line + yield from _data global file_spec if file_spec is None: diff --git a/tests/unit/plugins/module_utils/test_api.py b/tests/unit/plugins/module_utils/test_api.py index 18d02faf..73911a8d 100644 --- a/tests/unit/plugins/module_utils/test_api.py +++ b/tests/unit/plugins/module_utils/test_api.py @@ -79,11 +79,11 @@ def test_wapi_no_change(self): def test_wapi_change(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'updated comment', 'extattrs': None} - + ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "extattrs": {} } @@ -99,16 +99,16 @@ def test_wapi_change(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'default'}) def test_wapi_change_false(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'updated comment', 'extattrs': None, 'fqdn': 'foo'} - + ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "extattrs": {} } @@ -125,7 +125,9 @@ def test_wapi_change_false(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'name': 'default'} + ) def test_wapi_extattrs_change(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', @@ -161,9 +163,10 @@ def test_wapi_extattrs_nochange(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'test comment', 'extattrs': {'Site': 'test'}} + ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [{ "comment": "test comment", - "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "extattrs": {'Site': {'value': 'test'}} }] @@ -178,6 +181,7 @@ def test_wapi_extattrs_nochange(self): res = wapi.run('testobject', test_spec) self.assertFalse(res['changed']) + wapi.update_object.assert_not_called() def test_wapi_create(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible', diff --git a/tests/unit/plugins/modules/test_nios_a_record.py b/tests/unit/plugins/modules/test_nios_a_record.py index 16d81866..9234f9c7 100644 --- a/tests/unit/plugins/modules/test_nios_a_record.py +++ b/tests/unit/plugins/modules/test_nios_a_record.py @@ -86,10 +86,11 @@ def test_nios_a_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1', 'comment': 'updated comment', 'extattrs': None} + ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "a.ansible.com", "ipv4": "192.168.10.1", "extattrs": {} @@ -105,8 +106,10 @@ def test_nios_a_record_update_comment(self): wapi = self._get_wapi(test_object) res = wapi.run('testobject', test_spec) - self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'ipv4': '192.168.10.1', 'name': 'a.ansible.com'} + ) def test_nios_a_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1', @@ -139,12 +142,12 @@ def test_nios_a_record_update_record_name(self): self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'a_new.ansible.com', 'old_name': 'a.ansible.com'}, 'comment': 'comment', 'extattrs': None} + ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": "a_new.ansible.com", - "old_name": "a.ansible.com", + "_ref": ref, + "name": "a.ansible.com", "extattrs": {} } ] @@ -159,4 +162,4 @@ def test_nios_a_record_update_record_name(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with(ref, {'name': 'a_new.ansible.com', 'comment': 'comment'}) diff --git a/tests/unit/plugins/modules/test_nios_aaaa_record.py b/tests/unit/plugins/modules/test_nios_aaaa_record.py index 1b4f96c0..10b6e18d 100644 --- a/tests/unit/plugins/modules/test_nios_aaaa_record.py +++ b/tests/unit/plugins/modules/test_nios_aaaa_record.py @@ -86,10 +86,11 @@ def test_nios_aaaa_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'aaaa.ansible.com', 'ipv6': '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'comment': 'updated comment', 'extattrs': None} + ref = "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "aaaa.ansible.com", "ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "extattrs": {} @@ -107,6 +108,10 @@ def test_nios_aaaa_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'updated comment', 'ipv6': '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'name': 'aaaa.ansible.com'} + ) def test_nios_aaaa_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'aaaa.ansible.com', @@ -138,13 +143,12 @@ def test_nios_aaaa_record_remove(self): def test_nios_aaaa_record_update_record_name(self): self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'aaaa_new.ansible.com', 'old_name': 'aaaa.ansible.com'}, 'comment': 'comment', 'extattrs': None} - + ref = "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": "aaaa_new.ansible.com", - "old_name": "aaaa.ansible.com", + "_ref": ref, + "name": "aaaa.ansible.com", "extattrs": {} } ] @@ -159,4 +163,7 @@ def test_nios_aaaa_record_update_record_name(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'comment', 'name': 'aaaa_new.ansible.com'} + ) diff --git a/tests/unit/plugins/modules/test_nios_cname_record.py b/tests/unit/plugins/modules/test_nios_cname_record.py index 360a9cc9..3ad17abd 100644 --- a/tests/unit/plugins/modules/test_nios_cname_record.py +++ b/tests/unit/plugins/modules/test_nios_cname_record.py @@ -85,11 +85,11 @@ def test_nios_cname_record_create(self): def test_nios_cname_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com', 'comment': 'updated comment', 'extattrs': None} - + ref = "cnamerecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "cnamerecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "cname.ansible.com", "canonical": "realhost.ansible.com", "extattrs": {} @@ -107,6 +107,10 @@ def test_nios_cname_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'updated comment', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com'} + ) def test_nios_cname_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'cname.ansible.com', diff --git a/tests/unit/plugins/modules/test_nios_dns_view.py b/tests/unit/plugins/modules/test_nios_dns_view.py index b4933b55..ba003c8f 100644 --- a/tests/unit/plugins/modules/test_nios_dns_view.py +++ b/tests/unit/plugins/modules/test_nios_dns_view.py @@ -58,6 +58,9 @@ def _get_wapi(self, test_object): return wapi def load_fixtures(self, commands=None): + """ + Load fixtures for the module + """ self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) self.load_config.return_value = dict(diff=None, session='session') @@ -84,10 +87,11 @@ def test_nios_dns_view_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible-dns', 'comment': 'updated comment', 'extattrs': None} + ref = "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/true" test_object = [ { "comment": "test comment", - "_ref": "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "ansible-dns", "extattrs": {} } @@ -103,6 +107,7 @@ def test_nios_dns_view_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'ansible-dns'}) def test_nios_dns_view_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible-dns', 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 d053f0bf..037ea92b 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py @@ -84,10 +84,11 @@ def test_nios_dtc_monitor_http_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', 'comment': 'updated comment', 'extattrs': None} + ref = "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "https_monitor", "port": 443, "secure": True, @@ -105,6 +106,7 @@ def test_nios_dtc_monitor_http_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'https_monitor'}) def test_nios_dtc_monitor_http_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'https_monitor', 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 fb4b300d..78f13365 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py @@ -81,10 +81,11 @@ def test_nios_dtc_monitor_icmp_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', 'comment': 'updated comment', 'extattrs': None} + ref = "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "icmp_monitor", "extattrs": {} } @@ -100,6 +101,7 @@ def test_nios_dtc_monitor_icmp_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'icmp_monitor'}) def test_nios_dtc_monitor_icmp_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'icmp_monitor', 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 80263784..0fb63682 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py @@ -81,10 +81,11 @@ def test_nios_dtc_monitor_pdp_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', 'comment': 'updated comment', 'extattrs': None} + ref = "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "pdp_monitor", "port": 2123, "extattrs": {} @@ -101,6 +102,7 @@ def test_nios_dtc_monitor_pdp_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'pdp_monitor'}) def test_nios_dtc_monitor_pdp_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'pdp_monitor', 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 90b86bfa..6e170d75 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py @@ -80,11 +80,11 @@ def test_nios_dtc_monitor_sip_create(self): def test_nios_dtc_monitor_sip_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', 'comment': 'updated comment', 'extattrs': None} - + ref = "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "sip_monitor", "extattrs": {} } @@ -100,6 +100,7 @@ def test_nios_dtc_monitor_sip_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'sip_monitor'}) def test_nios_dtc_monitor_sip_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'sip_monitor', 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 838a35eb..374b5a67 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py @@ -80,11 +80,11 @@ def test_nios_dtc_monitor_snmp_create(self): def test_nios_dtc_monitor_snmp_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', 'comment': 'updated comment', 'extattrs': None} - + ref = "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "snmp_monitor", "port": 161, "version": "V2C", @@ -107,6 +107,7 @@ def test_nios_dtc_monitor_snmp_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'snmp_monitor'}) def test_nios_dtc_monitor_snmp_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'snmp_monitor', 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 072ba1a3..8de3d25f 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py @@ -83,10 +83,11 @@ def test_nios_dtc_monitor_tcp_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', 'comment': 'updated comment', 'extattrs': None} + ref = "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "tcp_monitor", "port": 8080, "extattrs": {} @@ -103,6 +104,7 @@ def test_nios_dtc_monitor_tcp_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'tcp_monitor'}) def test_nios_dtc_monitor_tcp_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'tcp_monitor', diff --git a/tests/unit/plugins/modules/test_nios_dtc_topology.py b/tests/unit/plugins/modules/test_nios_dtc_topology.py index d0ee4c69..6a11515b 100644 --- a/tests/unit/plugins/modules/test_nios_dtc_topology.py +++ b/tests/unit/plugins/modules/test_nios_dtc_topology.py @@ -101,10 +101,10 @@ def test_nios_dtc_topology_create(self): def test_nios_dtc_topology_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'a_topology', 'comment': 'updated comment', 'extattrs': None} - + ref = "dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { - '_ref': 'dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true', + '_ref': ref, 'name': 'a_topology', 'rules': [{ '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' @@ -124,6 +124,7 @@ def test_nios_dtc_topology_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'a_topology'}) def test_nios_dtc_topology_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'a_topology', diff --git a/tests/unit/plugins/modules/test_nios_fixed_address.py b/tests/unit/plugins/modules/test_nios_fixed_address.py index ae373fd3..ba435b76 100644 --- a/tests/unit/plugins/modules/test_nios_fixed_address.py +++ b/tests/unit/plugins/modules/test_nios_fixed_address.py @@ -82,11 +82,12 @@ def test_nios_fixed_address_ipv4_dhcp_update(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'test_fa', 'ipaddr': '192.168.10.1', 'mac': '08:6d:41:e8:fd:e8', 'network': '192.168.10.0/24', 'network_view': 'default', 'comment': 'updated comment', 'extattrs': None} + ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", "name": "test_fa", - "_ref": "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "ipaddr": "192.168.10.1", "mac": "08:6d:41:e8:fd:e8", "network": "192.168.10.0/24", @@ -109,6 +110,16 @@ def test_nios_fixed_address_ipv4_dhcp_update(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, + { + 'comment': 'updated comment', + 'name': 'test_fa', + 'ipaddr': '192.168.10.1', + 'mac': '08:6d:41:e8:fd:e8', + 'network': '192.168.10.0/24', + } + ) def test_nios_fixed_address_ipv4_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'test_fa', 'ipaddr': '192.168.10.1', 'mac': '08:6d:41:e8:fd:e8', diff --git a/tests/unit/plugins/modules/test_nios_host_record.py b/tests/unit/plugins/modules/test_nios_host_record.py index 8a5a8e6f..7bc72337 100644 --- a/tests/unit/plugins/modules/test_nios_host_record.py +++ b/tests/unit/plugins/modules/test_nios_host_record.py @@ -107,10 +107,11 @@ def test_nios_host_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'updated comment', 'extattrs': None} + ref = "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "extattrs": {} } @@ -126,18 +127,20 @@ def test_nios_host_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'name': 'default'} + ) def test_nios_host_record_update_record_name(self): self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'default', 'old_name': 'old_default'}, 'comment': 'comment', 'extattrs': None} + ref = "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "record:host/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": "default", - "old_name": "old_default", + "_ref": ref, + "name": "old_default", "extattrs": {} } ] @@ -152,4 +155,6 @@ def test_nios_host_record_update_record_name(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'comment', 'name': 'default'} + ) diff --git a/tests/unit/plugins/modules/test_nios_member.py b/tests/unit/plugins/modules/test_nios_member.py index a65b5df1..c8e02ce0 100644 --- a/tests/unit/plugins/modules/test_nios_member.py +++ b/tests/unit/plugins/modules/test_nios_member.py @@ -84,11 +84,11 @@ def test_nios_member_update(self): self.module.params = {'provider': None, 'state': 'present', 'host_name': 'test_member', 'vip_setting': {'address': '192.168.1.110', 'subnet_mask': '255.255.255.0', 'gateway': '192.168.1.1'}, 'config_addr_type': 'IPV4', 'platform': 'VNIOS', 'comment': 'updated comment', 'extattrs': None} - + ref = "member/b25lLnZpcnR1YWxfbm9kZSQ3:member01.ansible-dev.com" test_object = [ { "comment": "Created with Ansible", - "_ref": "member/b25lLnZpcnR1YWxfbm9kZSQ3:member01.ansible-dev.com", + "_ref": ref, "config_addr_type": "IPV4", "host_name": "member01.ansible-dev.com", "platform": "VNIOS", @@ -118,6 +118,12 @@ def test_nios_member_update(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'updated comment', 'host_name': 'test_member', + 'vip_setting': {'address': '192.168.1.110', 'subnet_mask': '255.255.255.0', 'gateway': '192.168.1.1'}, + 'config_addr_type': 'IPV4', 'platform': 'VNIOS'} + ) def test_nios_member_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'host_name': 'test_member', diff --git a/tests/unit/plugins/modules/test_nios_mx_record.py b/tests/unit/plugins/modules/test_nios_mx_record.py index 55524b4d..7f8db39e 100644 --- a/tests/unit/plugins/modules/test_nios_mx_record.py +++ b/tests/unit/plugins/modules/test_nios_mx_record.py @@ -86,11 +86,11 @@ def test_nios_mx_record_create(self): def test_nios_mx_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible.com', 'mx': 'mailhost.ansible.com', 'preference': 0, 'comment': 'updated comment', 'extattrs': None} - + ref = "mxrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "mxrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "ansible.com", "mx": "mailhost.ansible.com", "preference": 0, @@ -110,6 +110,8 @@ def test_nios_mx_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'ansible.com', + 'mx': 'mailhost.ansible.com', 'preference': 0}) def test_nios_mx_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible.com', 'mx': 'mailhost.ansible.com', diff --git a/tests/unit/plugins/modules/test_nios_naptr_record.py b/tests/unit/plugins/modules/test_nios_naptr_record.py index 44c9c349..38c3f059 100644 --- a/tests/unit/plugins/modules/test_nios_naptr_record.py +++ b/tests/unit/plugins/modules/test_nios_naptr_record.py @@ -91,10 +91,11 @@ def test_nios_naptr_record_update_comment(self): 'order': '1000', 'preference': '10', 'replacement': 'replacement1.network.ansiblezone.com', 'comment': 'updated comment', 'extattrs': None} + ref = "naptrrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "naptrrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "*.subscriber-100.ansiblezone.com", "order": "1000", "preference": "10", @@ -116,6 +117,8 @@ def test_nios_naptr_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': '*.subscriber-100.ansiblezone.com', + 'order': '1000', 'preference': '10', 'replacement': 'replacement1.network.ansiblezone.com'}) def test_nios_naptr_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': '*.subscriber-100.ansiblezone.com', diff --git a/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index 0fad5aaa..afc96330 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -78,10 +78,11 @@ def test_nios_network_ipv4_dhcp_update(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', 'comment': 'updated comment', 'extattrs': None} + ref = "network/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/true" test_object = [ { "comment": "test comment", - "_ref": "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "network": "192.168.10.0/24", "extattrs": {'options': {'name': 'test', 'value': 'ansible.com'}} } @@ -97,15 +98,17 @@ def test_nios_network_ipv4_dhcp_update(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'network': '192.168.10.0/24'}) def test_nios_network_ipv6_dhcp_update(self): self.module.params = {'provider': None, 'state': 'present', 'ipv6network': 'fe80::/64', 'comment': 'updated comment', 'extattrs': None} + ref = "ipv6network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "ipv6network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "ipv6network": "fe80::/64", "extattrs": {'options': {'name': 'test', 'value': 'ansible.com'}} } @@ -120,6 +123,7 @@ def test_nios_network_ipv6_dhcp_update(self): wapi = self._get_wapi(test_object) res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'ipv6network': 'fe80::/64'}) def test_nios_network_ipv4_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'network': '192.168.10.0/24', diff --git a/tests/unit/plugins/modules/test_nios_network_view.py b/tests/unit/plugins/modules/test_nios_network_view.py index fc95f180..24ee5fbd 100644 --- a/tests/unit/plugins/modules/test_nios_network_view.py +++ b/tests/unit/plugins/modules/test_nios_network_view.py @@ -83,11 +83,11 @@ def test_nios_network_view_create(self): def test_nios_network_view_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'updated comment', 'extattrs': None, 'network_view': 'default'} - + ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "extattrs": {}, "network_view": "default" @@ -104,18 +104,20 @@ def test_nios_network_view_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'updated comment', 'name': 'default'} + ) def test_nios_network_view_update_name(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'old_name': 'old_default', 'comment': 'updated comment', 'extattrs': None, 'network_view': 'default'} - + ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": "default", - "old_name": "old_default", + "_ref": ref, + "name": "old_default", "extattrs": {}, "network_view": "default" } @@ -131,7 +133,10 @@ def test_nios_network_view_update_name(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, + {'comment': 'updated comment', 'name': 'default'} + ) def test_nios_network_view_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible', diff --git a/tests/unit/plugins/modules/test_nios_nsgroup.py b/tests/unit/plugins/modules/test_nios_nsgroup.py index 60b21dcc..195ea7a7 100644 --- a/tests/unit/plugins/modules/test_nios_nsgroup.py +++ b/tests/unit/plugins/modules/test_nios_nsgroup.py @@ -107,10 +107,11 @@ def test_nios_nsgroup_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', 'comment': 'updated comment', 'grid_primary': None} + ref = "nsgroup/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "nsgroup/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "default", "grid_primary": {} } @@ -126,4 +127,6 @@ def test_nios_nsgroup_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'name': 'default'} + ) diff --git a/tests/unit/plugins/modules/test_nios_ptr_record.py b/tests/unit/plugins/modules/test_nios_ptr_record.py index 5ffd6487..68f69b9c 100644 --- a/tests/unit/plugins/modules/test_nios_ptr_record.py +++ b/tests/unit/plugins/modules/test_nios_ptr_record.py @@ -109,11 +109,11 @@ def test_nios_ptr_record_remove(self): def test_nios_ptr_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'ptrdname': 'ansible.test.com', 'ipv4addr': '10.36.241.14', 'comment': 'updated comment', 'extattrs': None, 'view': 'default'} - + ref = "record:ptr/ZG5zLm5ldHdvcmtfdmlldyQw:14.241.36.10.in-addr.arpa/default" test_object = [ { "comment": "test comment", - "_ref": "record:ptr/ZG5zLm5ldHdvcmtfdmlldyQw:14.241.36.10.in-addr.arpa/default", + "_ref": ref, "ptrdname": "ansible.test.com", "ipv4addr": "10.36.241.14", "extattrs": {}, @@ -133,16 +133,18 @@ def test_nios_ptr_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'updated comment', 'ptrdname': 'ansible.test.com', 'ipv4addr': '10.36.241.14', 'view': 'default'} + ) def test_nios_ptr_record_update_record_ptrdname(self): self.module.params = {'provider': None, 'state': 'present', 'ptrdname': 'ansible.test.org', 'ipv4addr': '10.36.241.14', 'comment': 'comment', 'extattrs': None, 'view': 'default'} - + ref = "record:ptr/ZG5zLm5ldHdvcmtfdmlldyQw:14.241.36.10.in-addr.arpa/default" test_object = [ { "comment": "test comment", - "_ref": "record:ptr/ZG5zLm5ldHdvcmtfdmlldyQw:14.241.36.10.in-addr.arpa/default", + "_ref": ref, "ptrdname": "ansible.test.com", "ipv4addr": "10.36.241.14", "extattrs": {}, @@ -162,7 +164,9 @@ def test_nios_ptr_record_update_record_ptrdname(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.update_object.called_once_with(test_object) + wapi.update_object.assert_called_once_with( + ref, {'comment': 'comment', 'ptrdname': 'ansible.test.org', 'ipv4addr': '10.36.241.14', 'view': 'default'} + ) def test_nios_ptr6_record_create(self): self.module.params = {'provider': None, 'state': 'present', 'ptrdname': 'ansible6.test.com', diff --git a/tests/unit/plugins/modules/test_nios_srv_record.py b/tests/unit/plugins/modules/test_nios_srv_record.py index 9a6f3fb3..5c41cd4c 100644 --- a/tests/unit/plugins/modules/test_nios_srv_record.py +++ b/tests/unit/plugins/modules/test_nios_srv_record.py @@ -90,11 +90,11 @@ def test_nios_srv_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': '_sip._tcp.service.ansible.com', 'port': 5080, 'target': 'service1.ansible.com', 'priority': 10, 'weight': 10, 'comment': None, 'extattrs': None} - + ref = "srvrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "srvrecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "name": "_sip._tcp.service.ansible.com", 'port': 5080, "target": "mailhost.ansible.com", @@ -118,6 +118,8 @@ def test_nios_srv_record_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'name': '_sip._tcp.service.ansible.com', + 'port': 5080, 'target': 'service1.ansible.com', 'priority': 10, 'weight': 10}) def test_nios_srv_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': '_sip._tcp.service.ansible.com', diff --git a/tests/unit/plugins/modules/test_nios_zone.py b/tests/unit/plugins/modules/test_nios_zone.py index 693ab060..20230c8e 100644 --- a/tests/unit/plugins/modules/test_nios_zone.py +++ b/tests/unit/plugins/modules/test_nios_zone.py @@ -104,11 +104,11 @@ def test_nios_zone_remove(self): def test_nios_zone_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'fqdn': 'ansible.com', 'comment': 'updated comment', 'extattrs': None} - + ref = "zone/ZG5zLm5ldHdvcmtfdmlldyQw:default/true" test_object = [ { "comment": "test comment", - "_ref": "zone/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "_ref": ref, "fqdn": "ansible.com", "extattrs": {'Site': {'value': 'test'}} } @@ -124,6 +124,7 @@ def test_nios_zone_update_comment(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) + wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'fqdn': 'ansible.com'}) def test_nios_zone_create_using_grid_primary_secondaries(self): self.module.params = {'provider': None, 'state': 'present', 'fqdn': 'ansible.com', diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt index fc67ca9e..c64045e9 100644 --- a/tests/unit/requirements.txt +++ b/tests/unit/requirements.txt @@ -6,4 +6,3 @@ mock pytest-mock pytest-cov coverage==7.3.2 -