diff --git a/plugins/lookup/nios_next_ip.py b/plugins/lookup/nios_next_ip.py index 9b5d243f..fb469c7d 100644 --- a/plugins/lookup/nios_next_ip.py +++ b/plugins/lookup/nios_next_ip.py @@ -48,11 +48,13 @@ 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: @@ -64,14 +66,17 @@ 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'] +- 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: - ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, exclude=['192.168.10.1', '192.168.10.2'], + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, + exclude=['192.168.10.1', '192.168.10.2'], provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" - 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/tests/unit/plugins/modules/test_nios_network.py b/tests/unit/plugins/modules/test_nios_network.py index 0fad5aaa..8a7c9aaa 100644 --- a/tests/unit/plugins/modules/test_nios_network.py +++ b/tests/unit/plugins/modules/test_nios_network.py @@ -30,12 +30,16 @@ class TestNiosNetworkModule(TestNiosModule): def setUp(self): super(TestNiosNetworkModule, self).setUp() - self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_network.WapiModule') + self.module = MagicMock( + name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_network.WapiModule' + ) self.module.check_mode = False self.module.params = {'provider': None} self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_network.WapiModule') self.exec_command = self.mock_wapi.start() - self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_network.WapiModule.run') + 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() @@ -58,7 +62,8 @@ def _get_wapi(self, test_object): def test_nios_network_ipv4_create(self): self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', - 'comment': None, 'extattrs': None} + 'comment': None, 'extattrs': None, 'use_logic_filter_rules': False, + 'logic_filter_rules': []} test_object = None test_spec = { @@ -246,3 +251,56 @@ def test_nios_networkcontainer_ipv6_create(self): self.assertTrue(res['changed']) wapi.create_object.assert_called_once_with('testobject', {'ipv6networkcontainer': 'fe80::/64'}) + + def test_nios_network_ipv4_create_with_use_logic_filter_rules(self): + self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', + 'comment': None, 'extattrs': None, 'use_logic_filter_rules': True, + 'logic_filter_rules': []} + + test_object = None + test_spec = { + "network": {"ib_req": True}, + "comment": {}, + "extattrs": {}, + "use_logic_filter_rules": {}, + "logic_filter_rules": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'network': '192.168.10.0/24', + 'use_logic_filter_rules': True, + 'logic_filter_rules': [] + } + ) + + def test_nios_network_ipv4_update_with_use_logic_filter_rules(self): + self.module.params = {'provider': None, 'state': 'present', 'network': '192.168.10.0/24', + 'comment': 'updated comment', 'extattrs': None, 'use_logic_filter_rules': True, + 'logic_filter_rules': []} + + test_object = [ + { + "comment": "test comment", + "_ref": "network/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "network": "192.168.10.0/24", + "extattrs": {'options': {'name': 'test', 'value': 'ansible.com'}}, + "use_logic_filter_rules": False, + "logic_filter_rules": [] + } + ] + + test_spec = { + "network": {"ib_req": True}, + "comment": {}, + "extattrs": {}, + "use_logic_filter_rules": {}, + "logic_filter_rules": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed'])