From b24f7d2800baa6753edb962bad40a790df14af7e Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 18 Sep 2019 21:58:39 +0530 Subject: [PATCH] vyosnoconfig tracebackfix (#62518) * vyosnoconfig tracebackfix Signed-off-by: rohitthakur2590 * vyos noconfig tracebackfix test cases added Signed-off-by: rohitthakur2590 * test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml --- .../config/lag_interfaces/lag_interfaces.py | 2 ++ .../vyos/config/lldp_global/lldp_global.py | 2 ++ .../config/lldp_interfaces/lldp_interfaces.py | 2 ++ .../tests/cli/empty_config.yaml | 36 +++++++++++++++++++ .../tests/cli/empty_config.yaml | 25 +++++++++++++ .../tests/cli/empty_config.yaml | 36 +++++++++++++++++++ 6 files changed, 103 insertions(+) create mode 100644 test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml create mode 100644 test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml create mode 100644 test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml diff --git a/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py b/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py index d411754aed3..837b22780ea 100644 --- a/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py +++ b/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py @@ -107,6 +107,8 @@ class Lag_interfaces(ConfigBase): """ commands = [] state = self._module.params['state'] + if state in ('merged', 'replaced', 'overridden') and not want: + self._module.fail_json(msg='config is required for state {0}'.format(state)) if state == 'overridden': commands.extend(self._state_overridden(want, have)) elif state == 'deleted': diff --git a/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py b/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py index d77bf61c084..013d8dc81d6 100644 --- a/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py +++ b/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py @@ -100,6 +100,8 @@ class Lldp_global(ConfigBase): """ commands = [] state = self._module.params['state'] + if state in ('merged', 'replaced') and not want: + self._module.fail_json(msg='config is required for state {0}'.format(state)) if state == 'deleted': commands.extend(self._state_deleted(want=None, have=have)) elif state == 'merged': diff --git a/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py index 6f5e70279be..6cefee8a7c4 100644 --- a/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py +++ b/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py @@ -110,6 +110,8 @@ class Lldp_interfaces(ConfigBase): """ commands = [] state = self._module.params['state'] + if state in ('merged', 'replaced', 'overridden') and not want: + self._module.fail_json(msg='config is required for state {0}'.format(state)) if state == 'overridden': commands.extend(self._state_overridden(want=want, have=have)) elif state == 'deleted': diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000000..1e39dcee90c --- /dev/null +++ b/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: "START vyos_lag_interfaces empty_config integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + vyos_lag_interfaces: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state merged' + +- name: Replaced with empty config should give appropriate error message + vyos_lag_interfaces: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state replaced' + +- name: Overridden with empty config should give appropriate error message + vyos_lag_interfaces: + config: + state: overridden + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state overridden' diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml new file mode 100644 index 00000000000..e51c11e048f --- /dev/null +++ b/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml @@ -0,0 +1,25 @@ +--- +- debug: + msg: "START vyos_lldp_global empty_config integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + vyos_lldp_global: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state merged' + +- name: Replaced with empty config should give appropriate error message + vyos_lldp_global: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state replaced' diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000000..455b4c708e5 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: "START vyos_lldp_interfaces empty_config integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + vyos_lldp_interfaces: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state merged' + +- name: Replaced with empty config should give appropriate error message + vyos_lldp_interfaces: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state replaced' + +- name: Overridden with empty config should give appropriate error message + vyos_lldp_interfaces: + config: + state: overridden + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'config is required for state overridden'