1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #18663. Bad handling of existing config in dellos9 module. (#18664)

* Fixes #18663. Bad handling of existing config in dellos9 module.

The dellos9 module doesn't build correctly the internal
structures used to represent the existing config of the managed
network device. This leads to apply changes every time the
playbook is run, even if the existing config is the same that the
one you are trying to push into the device.

Probably this problem exist also in the dellos6 and dellos10
modules, but I only fixed it in the dellos9 module.

The fix modifies two methods. The first one is `get_config`,
where the return clause didn't work correctly when the flow
doesn't enter in the `if` block. In that case the `contents`
variable is not an array an this should be handled.

The second fix is in the `get_sublevel_config` method. In this
case the indentation whitespaces of the parents should be rebuild
because further functions and methods required it to handle
correctly comparisons used to check if changes should be pushed
into device.

* Fixes #18663 for dellos10 module with the same patches as dellos9.
This commit is contained in:
Juan Antonio Valiño García 2016-12-12 21:51:32 +01:00 committed by Peter Sprygada
parent f9c4158ff8
commit 40ddbe026d
2 changed files with 12 additions and 6 deletions

View file

@ -42,8 +42,9 @@ def get_config(module):
if not contents:
contents = module.config.get_config()
module.params['config'] = contents
return NetworkConfig(indent=1, contents=contents[0])
return NetworkConfig(indent=1, contents=contents[0])
else:
return NetworkConfig(indent=1, contents=contents)
def get_sublevel_config(running_config, module):
@ -54,11 +55,13 @@ def get_sublevel_config(running_config, module):
contents = obj.children
contents[:0] = module.params['parents']
indent = 0
for c in contents:
if isinstance(c, str):
current_config_contents.append(c)
current_config_contents.append(c.rjust(len(c) + indent, ' '))
if isinstance(c, ConfigLine):
current_config_contents.append(c.raw)
indent = indent + 1
sublevel_config = '\n'.join(current_config_contents)
return sublevel_config

View file

@ -42,8 +42,9 @@ def get_config(module):
if not contents:
contents = module.config.get_config()
module.params['config'] = contents
return NetworkConfig(indent=1, contents=contents[0])
return NetworkConfig(indent=1, contents=contents[0])
else:
return NetworkConfig(indent=1, contents=contents)
def get_sublevel_config(running_config, module):
@ -54,11 +55,13 @@ def get_sublevel_config(running_config, module):
contents = obj.children
contents[:0] = module.params['parents']
indent = 0
for c in contents:
if isinstance(c, str):
current_config_contents.append(c)
current_config_contents.append(c.rjust(len(c) + indent, ' '))
if isinstance(c, ConfigLine):
current_config_contents.append(c.raw)
indent = indent + 1
sublevel_config = '\n'.join(current_config_contents)
return sublevel_config