diff options
author | Fedor Sumkin <qosys.net@gmail.com> | 2017-12-20 10:18:22 +0300 |
---|---|---|
committer | Abhijeet Kasurde <akasurde@redhat.com> | 2017-12-20 12:48:22 +0530 |
commit | 8a9865cb1009a0a7ff6033f1b443a0c1e40a2f8b (patch) | |
tree | ba05171a7a3e2a72aefa45b88a6ef670bd0c545f | |
parent | f7fe6a065e129c33e05066ed88bf862c6e0100b0 (diff) | |
download | ansible-8a9865cb1009a0a7ff6033f1b443a0c1e40a2f8b.tar.gz |
Fix for `dns4` empty setting (#30757)
This fix check if DNS4 is None or not before proceeding with
other operations. Also, added unit test for this change.
Signed-off-by: Fedor Sumkin <qosys.net@gmail.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r-- | lib/ansible/modules/net_tools/nmcli.py | 2 | ||||
-rw-r--r-- | test/units/modules/net_tools/__init__.py | 0 | ||||
-rw-r--r-- | test/units/modules/net_tools/test_nmcli.py | 44 |
3 files changed, 45 insertions, 1 deletions
diff --git a/lib/ansible/modules/net_tools/nmcli.py b/lib/ansible/modules/net_tools/nmcli.py index 8b71d603de..e7b52316c9 100644 --- a/lib/ansible/modules/net_tools/nmcli.py +++ b/lib/ansible/modules/net_tools/nmcli.py @@ -556,7 +556,7 @@ class Nmcli(object): self.type = module.params['type'] self.ip4 = module.params['ip4'] self.gw4 = module.params['gw4'] - self.dns4 = ' '.join(module.params['dns4']) + self.dns4 = ' '.join(module.params['dns4']) if module.params.get('dns4') else None self.ip6 = module.params['ip6'] self.gw6 = module.params['gw6'] self.dns6 = module.params['dns6'] diff --git a/test/units/modules/net_tools/__init__.py b/test/units/modules/net_tools/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/units/modules/net_tools/__init__.py diff --git a/test/units/modules/net_tools/test_nmcli.py b/test/units/modules/net_tools/test_nmcli.py new file mode 100644 index 0000000000..55eb5f48b5 --- /dev/null +++ b/test/units/modules/net_tools/test_nmcli.py @@ -0,0 +1,44 @@ +# Copyright: (c) 2017 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +import pytest +import json + +from ansible.modules.net_tools import nmcli + +pytestmark = pytest.mark.usefixtures('patch_ansible_module') + +TESTCASE = [ + { + 'type': 'ethernet', + 'conn_name': 'non_existent_nw_device', + 'state': 'absent', + '_ansible_check_mode': True, + } +] + + +@pytest.fixture +def mocked_connection_exists(mocker): + mocker.patch('ansible.modules.net_tools.nmcli.HAVE_DBUS', True) + mocker.patch('ansible.modules.net_tools.nmcli.HAVE_NM_CLIENT', True) + + get_bin_path = mocker.patch('ansible.module_utils.basic.AnsibleModule.get_bin_path') + get_bin_path.return_value = '/usr/bin/nmcli' + + connection = mocker.patch.object(nmcli.Nmcli, 'connection_exists') + connection.return_value = True + return connection + + +@pytest.mark.parametrize('patch_ansible_module', TESTCASE, indirect=['patch_ansible_module']) +def test_dns4_none(mocked_connection_exists, capfd): + """ + Test if DNS4 param is None + """ + with pytest.raises(SystemExit): + nmcli.main() + + out, err = capfd.readouterr() + results = json.loads(out) + assert results['changed'] |