Fix traceback empty config error to meaningful msg for IOS (#62572)

* Fix traceback empty config error to meaningful msg for IOS (#62538)

* fix empty config msg

* fix space

Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>
(cherry picked from commit 35463d45f4)

* changelog
pull/62607/head
Sumit Jaiswal 5 years ago committed by Toshio Kuratomi
parent b8e905cd4d
commit 34609a0973

@ -0,0 +1,3 @@
---
bugfixes:
- "Fix traceback with empty config error msg(https://github.com/ansible/ansible/pull/62538)"

@ -105,7 +105,10 @@ class Interfaces(ConfigBase):
to the deisred configuration
"""
commands = []
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have)

@ -100,6 +100,9 @@ class L2_Interfaces(ConfigBase):
commands = []
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have, self._module)
elif state == 'deleted':

@ -96,6 +96,9 @@ class L3_Interfaces(ConfigBase):
commands = []
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have, self._module)
elif state == 'deleted':

@ -102,6 +102,9 @@ class Lacp(ConfigBase):
to the desired configuration
"""
state = self._module.params['state']
if state in ('merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'deleted':
commands = self._state_deleted(want, have)
elif state == 'merged':

@ -104,7 +104,12 @@ class Lacp_Interfaces(ConfigBase):
:returns: the commands necessary to migrate the current configuration
to the desired configuration
"""
commands = []
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have)
elif state == 'deleted':

@ -104,6 +104,9 @@ class Lag_interfaces(ConfigBase):
"""
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
module = self._module
if state == 'overridden':
commands = self._state_overridden(want, have, module)

@ -109,6 +109,8 @@ class Lldp_global(ConfigBase):
"""
commands = []
state = self._module.params['state']
if state in ('merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have)

@ -105,6 +105,9 @@ class Lldp_Interfaces(ConfigBase):
to the desired configuration
"""
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have)
elif state == 'deleted':

@ -100,6 +100,9 @@ class Vlans(ConfigBase):
to the desired configuration
"""
state = self._module.params['state']
if state in ('overridden', 'merged', 'replaced') and not want:
self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state))
if state == 'overridden':
commands = self._state_overridden(want, have, state)
elif state == 'deleted':

@ -85,7 +85,9 @@ class Lldp_InterfacesFacts(object):
"""
config = deepcopy(spec)
match = re.search(r'^(\S+)(:)', conf)
intf = match.group(1)
intf = ''
if match:
intf = match.group(1)
if get_interface_type(intf) == 'unknown':
return {}

@ -0,0 +1,36 @@
---
- debug:
msg: "START ios_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- name: Merged with empty config should give appropriate error message
ios_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'

@ -0,0 +1,36 @@
---
- debug:
msg: "START ios_l2_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- name: Merged with empty config should give appropriate error message
ios_l2_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_l2_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_l2_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'

@ -0,0 +1,36 @@
---
- debug:
msg: "START ios_l3_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- name: Merged with empty config should give appropriate error message
ios_l3_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_l3_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_l3_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'

@ -0,0 +1,27 @@
---
- debug:
msg: "START ios_lacp empty_config.yaml integration tests on connection={{ ansible_connection }}"
- block:
- name: Merged with empty config should give appropriate error message
ios_lacp:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_lacp:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
when: ansible_net_version != "15.6(2)T"

@ -0,0 +1,38 @@
---
- debug:
msg: "START ios_lacp_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- block:
- name: Merged with empty config should give appropriate error message
ios_lacp_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_lacp_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_lacp_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'
when: ansible_net_version != "15.6(2)T"

@ -0,0 +1,38 @@
---
- debug:
msg: "START ios_lag_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- block:
- name: Merged with empty config should give appropriate error message
ios_lag_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_lag_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_lag_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'
when: ansible_net_version != "15.6(2)T"

@ -0,0 +1,25 @@
---
- debug:
msg: "START ios_lldp_global empty_config.yaml integration tests on connection={{ ansible_connection }}"
- name: Merged with empty config should give appropriate error message
ios_lldp_global:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_lldp_global:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'

@ -0,0 +1,36 @@
---
- debug:
msg: "START ios_lldp_interfaces empty_config.yaml integration tests on connection={{ ansible_connection }}"
- name: Merged with empty config should give appropriate error message
ios_lldp_interfaces:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_lldp_interfaces:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_lldp_interfaces:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'

@ -0,0 +1,38 @@
---
- debug:
msg: "START ios_vlans empty_config.yaml integration tests on connection={{ ansible_connection }}"
- block:
- name: Merged with empty config should give appropriate error message
ios_vlans:
config:
state: merged
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state merged'
- name: Replaced with empty config should give appropriate error message
ios_vlans:
config:
state: replaced
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state replaced'
- name: Overridden with empty config should give appropriate error message
ios_vlans:
config:
state: overridden
register: result
ignore_errors: True
- assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'
when: ansible_net_version != "15.6(2)T"
Loading…
Cancel
Save