From 890b97a38fdaaaa786d58af27fcdb5889b9e0a53 Mon Sep 17 00:00:00 2001 From: Anil Kumar Muraleedharan Date: Thu, 14 Dec 2017 02:27:51 +0530 Subject: [PATCH] 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 --- lib/ansible/module_utils/network/enos/enos.py | 7 ++++++- lib/ansible/modules/network/enos/enos_config.py | 17 ++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ansible/module_utils/network/enos/enos.py b/lib/ansible/module_utils/network/enos/enos.py index 953922441f8..0ab41597d08 100644 --- a/lib/ansible/module_utils/network/enos/enos.py +++ b/lib/ansible/module_utils/network/enos/enos.py @@ -97,7 +97,11 @@ def get_connection(module): def get_config(module, flags=None): flags = [] if flags is None else flags - passwords = module.params['passwords'] + passwords = None + try: + passwords = module.params['passwords'] + except KeyError: + passwords = None if passwords: cmd = 'more system:running-config' else: @@ -147,6 +151,7 @@ def run_commands(module, commands, check_rc=True): def load_config(module, config): try: conn = get_connection(module) + conn.get('enable') conn.edit_config(config) except ConnectionError as exc: module.fail_json(msg=to_text(exc)) diff --git a/lib/ansible/modules/network/enos/enos_config.py b/lib/ansible/modules/network/enos/enos_config.py index 31b066a3d8b..1b222b10032 100644 --- a/lib/ansible/modules/network/enos/enos_config.py +++ b/lib/ansible/modules/network/enos/enos_config.py @@ -166,20 +166,13 @@ backup_path: 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 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 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): contents = module.params['config'] if not contents: @@ -190,7 +183,10 @@ def get_running_config(module): def get_candidate(module): candidate = NetworkConfig(indent=1) 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']: parents = module.params['parents'] or list() candidate.add(module.params['lines'], parents=parents) @@ -228,8 +224,7 @@ def run(module, result): result['commands'] = commands - diff = load_config(module, commands, result['warnings'], - not check_mode, replace_config, comment, admin) + diff = load_config(module, commands) if diff: result['diff'] = dict(prepared=diff) result['changed'] = True