mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
Fix for changing method only on specified interface (#39015)
Test added for interface method change
This commit is contained in:
parent
9f1254a32f
commit
a3f2e99864
8 changed files with 224 additions and 1 deletions
|
@ -188,3 +188,35 @@ class TestInterfacesFileModule(unittest.TestCase):
|
|||
self.compareInterfacesLinesToFile(lines, testfile, "%s_%s" % (testfile, testname))
|
||||
self.compareInterfacesToFile(ifaces, testfile, "%s_%s.json" % (testfile, testname))
|
||||
self.compareFileToBackup(path, backupp)
|
||||
|
||||
def test_change_method(self):
|
||||
testcases = {
|
||||
"change_method": [
|
||||
{
|
||||
'iface': 'eth0',
|
||||
'option': 'method',
|
||||
'value': 'manual',
|
||||
'state': 'present',
|
||||
}
|
||||
],
|
||||
}
|
||||
for testname, options_list in testcases.items():
|
||||
for testfile in self.getTestFiles():
|
||||
path = os.path.join(fixture_path, testfile)
|
||||
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'])
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue