interfaces_file: Add test for changing ipv4 or ipv6 address through address_family

This commit is contained in:
Jocelyn Jaubert 2018-08-16 20:28:22 +02:00 committed by Michael Scherer
parent 7ec49d7472
commit bd7001cdb6
19 changed files with 498 additions and 0 deletions

View file

@ -229,3 +229,49 @@ class TestInterfacesFileModule(unittest.TestCase):
self.compareInterfacesToFile(ifaces, testfile, "%s_%s.json" % (testfile, testname))
# Restore backup
move(backupp, path)
def test_change_address(self):
testcases = {
"change_ipv4": [
{
'iface': 'eth0',
'address_family': 'inet',
'option': 'address',
'value': '192.168.0.42',
'state': 'present',
}
],
"change_ipv6": [
{
'iface': 'eth0',
'address_family': 'inet6',
'option': 'address',
'value': 'fc00::42',
'state': 'present',
}
],
}
for testname, options_list in testcases.items():
for testfile in self.getTestFiles():
with tempfile.NamedTemporaryFile() as temp_file:
src_path = os.path.join(fixture_path, testfile)
path = temp_file.name
shutil.copy(src_path, path)
lines, ifaces = interfaces_file.read_interfaces_file(module, path)
backupp = module.backup_local(path)
options = options_list[0]
fail_json_iterations = []
try:
_, lines = interfaces_file.setInterfaceOption(module, lines, options['iface'], options['option'],
options['value'], options['state'], options['address_family'])
except AnsibleFailJson as e:
fail_json_iterations.append("fail_json message: %s\noptions:\n%s" %
(str(e), json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))))
interfaces_file.write_changes(module, [d['line'] for d in lines if 'line' in d], path)
self.compareStringWithFile("\n=====\n".join(fail_json_iterations), "%s_%s.exceptions.txt" % (testfile, testname))
self.compareInterfacesLinesToFile(lines, testfile, "%s_%s" % (testfile, testname))
self.compareInterfacesToFile(ifaces, testfile, "%s_%s.json" % (testfile, testname))
# Restore backup
move(backupp, path)