mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
nmcli: Add ipv4.dns-search attribute (#34261)
This fix adds following - * ipv4.dns-search attribute * refactoring of code * correct return status for up_connection * documentation update Fixes: #17843 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
bbd6b8bb42
commit
b7724fdf85
2 changed files with 232 additions and 227 deletions
|
@ -62,6 +62,20 @@ TESTCASE_GENERIC = [
|
|||
'gw4': '10.10.10.1',
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': False,
|
||||
},
|
||||
]
|
||||
|
||||
TESTCASE_GENERIC_DNS4_SEARCH = [
|
||||
{
|
||||
'type': 'generic',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'ifname': 'generic_non_existant',
|
||||
'ip4': '10.10.10.10',
|
||||
'gw4': '10.10.10.1',
|
||||
'state': 'present',
|
||||
'dns4_search': 'search.redhat.com',
|
||||
'dns6_search': 'search6.redhat.com',
|
||||
'_ansible_check_mode': False,
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -101,6 +115,20 @@ def mocked_generic_connection_create(mocker):
|
|||
return command_result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_generic_connection_modify(mocker):
|
||||
mocker_set(mocker, connection_exists=True)
|
||||
command_result = mocker.patch.object(nmcli.Nmcli, 'execute_command')
|
||||
command_result.return_value = {"rc": 100, "out": "aaa", "err": "none"}
|
||||
return command_result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_connection_exists(mocker):
|
||||
connection = mocker_set(mocker, connection_exists=True)
|
||||
return connection
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BOND, indirect=['patch_ansible_module'])
|
||||
def test_bond_connection_create(mocked_generic_connection_create):
|
||||
"""
|
||||
|
@ -122,49 +150,9 @@ def test_bond_connection_create(mocked_generic_connection_create):
|
|||
assert args[0][6] == 'non_existent_nw_device'
|
||||
assert args[0][7] == 'ifname'
|
||||
assert args[0][8] == 'bond_non_existant'
|
||||
assert args[0][9] == 'mode'
|
||||
assert args[0][10] == 'active-backup'
|
||||
assert args[0][11] == 'ip4'
|
||||
assert args[0][12] == '10.10.10.10'
|
||||
assert args[0][13] == 'gw4'
|
||||
assert args[0][14] == '10.10.10.1'
|
||||
assert args[0][15] == 'primary'
|
||||
assert args[0][16] == 'non_existent_primary'
|
||||
|
||||
|
||||
def mocker_set(mocker, connection_exists=False):
|
||||
"""
|
||||
Common mocker object
|
||||
"""
|
||||
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 = connection_exists
|
||||
return connection
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_generic_connection_create(mocker):
|
||||
mocker_set(mocker)
|
||||
command_result = mocker.patch.object(nmcli.Nmcli, 'execute_command')
|
||||
command_result.return_value = {"rc": 100, "out": "aaa", "err": "none"}
|
||||
return command_result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_generic_connection_modify(mocker):
|
||||
mocker_set(mocker, connection_exists=True)
|
||||
command_result = mocker.patch.object(nmcli.Nmcli, 'execute_command')
|
||||
command_result.return_value = {"rc": 100, "out": "aaa", "err": "none"}
|
||||
return command_result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_connection_exists(mocker):
|
||||
connection = mocker_set(mocker, connection_exists=True)
|
||||
return connection
|
||||
for param in ['ipv4.gateway', 'primary', 'autoconnect', 'mode', 'active-backup', 'ipv4.address']:
|
||||
assert param in args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC, indirect=['patch_ansible_module'])
|
||||
|
@ -186,10 +174,9 @@ def test_generic_connection_create(mocked_generic_connection_create):
|
|||
assert args[0][4] == 'generic'
|
||||
assert args[0][5] == 'con-name'
|
||||
assert args[0][6] == 'non_existent_nw_device'
|
||||
assert args[0][9] == 'ip4'
|
||||
assert args[0][10] == '10.10.10.10'
|
||||
assert args[0][11] == 'gw4'
|
||||
assert args[0][12] == '10.10.10.1'
|
||||
|
||||
for param in ['autoconnect', 'ipv4.gateway', 'ipv4.address']:
|
||||
assert param in args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC, indirect=['patch_ansible_module'])
|
||||
|
@ -208,10 +195,41 @@ def test_generic_connection_modify(mocked_generic_connection_modify):
|
|||
assert args[0][1] == 'con'
|
||||
assert args[0][2] == 'mod'
|
||||
assert args[0][3] == 'non_existent_nw_device'
|
||||
assert args[0][4] == 'ipv4.address'
|
||||
assert args[0][5] == '10.10.10.10'
|
||||
assert args[0][6] == 'ipv4.gateway'
|
||||
assert args[0][7] == '10.10.10.1'
|
||||
|
||||
for param in ['ipv4.gateway', 'ipv4.address']:
|
||||
assert param in args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_DNS4_SEARCH, indirect=['patch_ansible_module'])
|
||||
def test_generic_connection_create_dns_search(mocked_generic_connection_create):
|
||||
"""
|
||||
Test : Generic connection created with dns search
|
||||
"""
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
assert nmcli.Nmcli.execute_command.call_count == 1
|
||||
arg_list = nmcli.Nmcli.execute_command.call_args_list
|
||||
args, kwargs = arg_list[0]
|
||||
|
||||
assert 'ipv4.dns-search' in args[0]
|
||||
assert 'ipv6.dns-search' in args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_DNS4_SEARCH, indirect=['patch_ansible_module'])
|
||||
def test_generic_connection_modify_dns_search(mocked_generic_connection_create):
|
||||
"""
|
||||
Test : Generic connection modified with dns search
|
||||
"""
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
assert nmcli.Nmcli.execute_command.call_count == 1
|
||||
arg_list = nmcli.Nmcli.execute_command.call_args_list
|
||||
args, kwargs = arg_list[0]
|
||||
|
||||
assert 'ipv4.dns-search' in args[0]
|
||||
assert 'ipv6.dns-search' in args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue