Lenovo enos bugfixes (#33857)
* Bug Fixes to issues foubd during testing * Removing blank line * undefined-variable Undefined variable 'run_commands' and training new line * Reverting and Modifying changes with both Unit test and Integrated test with Devices passing
This commit is contained in:
parent
15a58d498d
commit
890b97a38f
2 changed files with 12 additions and 12 deletions
|
@ -97,7 +97,11 @@ def get_connection(module):
|
||||||
def get_config(module, flags=None):
|
def get_config(module, flags=None):
|
||||||
flags = [] if flags is None else flags
|
flags = [] if flags is None else flags
|
||||||
|
|
||||||
passwords = module.params['passwords']
|
passwords = None
|
||||||
|
try:
|
||||||
|
passwords = module.params['passwords']
|
||||||
|
except KeyError:
|
||||||
|
passwords = None
|
||||||
if passwords:
|
if passwords:
|
||||||
cmd = 'more system:running-config'
|
cmd = 'more system:running-config'
|
||||||
else:
|
else:
|
||||||
|
@ -147,6 +151,7 @@ def run_commands(module, commands, check_rc=True):
|
||||||
def load_config(module, config):
|
def load_config(module, config):
|
||||||
try:
|
try:
|
||||||
conn = get_connection(module)
|
conn = get_connection(module)
|
||||||
|
conn.get('enable')
|
||||||
conn.edit_config(config)
|
conn.edit_config(config)
|
||||||
except ConnectionError as exc:
|
except ConnectionError as exc:
|
||||||
module.fail_json(msg=to_text(exc))
|
module.fail_json(msg=to_text(exc))
|
||||||
|
|
|
@ -166,20 +166,13 @@ backup_path:
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.enos.enos import load_config, get_config
|
from ansible.module_utils.network.enos.enos import load_config, get_config
|
||||||
from ansible.module_utils.network.enos.enos import enos_argument_spec
|
from ansible.module_utils.network.enos.enos import enos_argument_spec
|
||||||
from ansible.module_utils.network.enos.enos import check_args as enos_check_args
|
from ansible.module_utils.network.enos.enos import check_args
|
||||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMIT_COMMENT = 'configured by enos_config'
|
DEFAULT_COMMIT_COMMENT = 'configured by enos_config'
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
|
||||||
enos_check_args(module, warnings)
|
|
||||||
if module.params['comment']:
|
|
||||||
if len(module.params['comment']) > 60:
|
|
||||||
module.fail_json(msg='comment argument cannot be more than 60 characters')
|
|
||||||
|
|
||||||
|
|
||||||
def get_running_config(module):
|
def get_running_config(module):
|
||||||
contents = module.params['config']
|
contents = module.params['config']
|
||||||
if not contents:
|
if not contents:
|
||||||
|
@ -190,7 +183,10 @@ def get_running_config(module):
|
||||||
def get_candidate(module):
|
def get_candidate(module):
|
||||||
candidate = NetworkConfig(indent=1)
|
candidate = NetworkConfig(indent=1)
|
||||||
if module.params['src']:
|
if module.params['src']:
|
||||||
candidate.load(module.params['src'])
|
try:
|
||||||
|
candidate.loadfp(module.params['src'])
|
||||||
|
except IOError:
|
||||||
|
candidate.load(module.params['src'])
|
||||||
elif module.params['lines']:
|
elif module.params['lines']:
|
||||||
parents = module.params['parents'] or list()
|
parents = module.params['parents'] or list()
|
||||||
candidate.add(module.params['lines'], parents=parents)
|
candidate.add(module.params['lines'], parents=parents)
|
||||||
|
@ -228,8 +224,7 @@ def run(module, result):
|
||||||
|
|
||||||
result['commands'] = commands
|
result['commands'] = commands
|
||||||
|
|
||||||
diff = load_config(module, commands, result['warnings'],
|
diff = load_config(module, commands)
|
||||||
not check_mode, replace_config, comment, admin)
|
|
||||||
if diff:
|
if diff:
|
||||||
result['diff'] = dict(prepared=diff)
|
result['diff'] = dict(prepared=diff)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
Loading…
Reference in a new issue