From 299047d9638b1143f7968d48a61c9c72ecb42c40 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Wed, 16 May 2018 12:19:39 +0530 Subject: [PATCH] cherry-pick stable-2.5 (#40177) * Fix nxos terminal plugin regex (#39659) Fix nxos terminal plugin regex to match command prompt without newline character as prefix (cherry picked from commit 0ac222d68b0ea4c3fc929120da35cc9c6c4479a2) * remove purge from nxos_logging doc, argspec (#39947) * remove purge from nxos_logging doc, argspec Signed-off-by: Trishna Guha * shippable Signed-off-by: Trishna Guha (cherry picked from commit f1103a7a025c2012a5bfb2a7777db76ad821fbd2) * IT cases for nxos_logging (#39929) * IT cases for nxos_logging * review comment (cherry picked from commit 2557c0662a12b86767beae95a20a2ff3a18b01ee) * fix nxos_ping issues (#40028) (cherry picked from commit 6fac574f174edcd0d4bef4de54c0af62b9dd6ea8) * Fix vxlan_vtep_vni tests (#39968) (cherry picked from commit 0407c514477742e04fd6f777655cbe4f6ca1a3b7) * ios cliconf plugin fix regex for version (#40066) Signed-off-by: Trishna Guha (cherry picked from commit 5cf61d7401822d5bd4a2701bfc25830adede2bd0) * update changelog Signed-off-by: Trishna Guha * shippable Signed-off-by: Trishna Guha --- changelogs/fragments/ios_cliconf_plugin.yaml | 2 + changelogs/fragments/nxos_bugfixes.yaml | 3 + .../fragments/nxos_terminal_plugin.yaml | 2 + .../modules/network/nxos/nxos_logging.py | 7 +- lib/ansible/modules/network/nxos/nxos_ping.py | 14 +-- lib/ansible/plugins/cliconf/ios.py | 4 +- lib/ansible/plugins/terminal/nxos.py | 2 +- .../nxos_logging/tests/common/basic.yaml | 95 ++++++++++++------- .../tests/common/sanity.yaml | 32 ++++++- test/sanity/validate-modules/ignore.txt | 1 - 10 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 changelogs/fragments/ios_cliconf_plugin.yaml create mode 100644 changelogs/fragments/nxos_terminal_plugin.yaml diff --git a/changelogs/fragments/ios_cliconf_plugin.yaml b/changelogs/fragments/ios_cliconf_plugin.yaml new file mode 100644 index 00000000000..045e6c1c616 --- /dev/null +++ b/changelogs/fragments/ios_cliconf_plugin.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ios cliconf plugin fix regex for version (https://github.com/ansible/ansible/pull/40066) diff --git a/changelogs/fragments/nxos_bugfixes.yaml b/changelogs/fragments/nxos_bugfixes.yaml index a95ea3d23a0..a90119630e1 100644 --- a/changelogs/fragments/nxos_bugfixes.yaml +++ b/changelogs/fragments/nxos_bugfixes.yaml @@ -29,3 +29,6 @@ bugfixes: - nxos_snmp_traps - Fix nxos_snmp_traps issues (https://github.com/ansible/ansible/pull/39444) - nxos_linkagg - nxos_linkagg abbreviated form issue (https://github.com/ansible/ansible/pull/39591) - nxos_snmp_user - Fix nxos_snmp_user (https://github.com/ansible/ansible/pull/39760) +- nxos_logging - remove purge from nxos_logging doc, argspec (https://github.com/ansible/ansible/pull/39947) +- nxos_ping - Fix nxos_ping issues (https://github.com/ansible/ansible/pull/40028) +- nxos_vxlan_vtep_vni - Fix nxos_vxlan_vtep_vni test (https://github.com/ansible/ansible/pull/39968) diff --git a/changelogs/fragments/nxos_terminal_plugin.yaml b/changelogs/fragments/nxos_terminal_plugin.yaml new file mode 100644 index 00000000000..a5b3b365fa2 --- /dev/null +++ b/changelogs/fragments/nxos_terminal_plugin.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix nxos terminal plugin regex (https://github.com/ansible/ansible/pull/39659) diff --git a/lib/ansible/modules/network/nxos/nxos_logging.py b/lib/ansible/modules/network/nxos/nxos_logging.py index cf263deae44..e20bd7c0d4f 100644 --- a/lib/ansible/modules/network/nxos/nxos_logging.py +++ b/lib/ansible/modules/network/nxos/nxos_logging.py @@ -52,10 +52,6 @@ options: - Set logging serverity levels for facility based log messages. aggregate: description: List of logging definitions. - purge: - description: - - Purge logging not defined in the aggregate parameter. - default: no state: description: - State of the logging configuration. @@ -295,8 +291,7 @@ def main(): dest_level=dict(type='int', aliases=['level']), facility_level=dict(type='int'), state=dict(default='present', choices=['present', 'absent']), - aggregate=dict(type='list'), - purge=dict(default=False, type='bool') + aggregate=dict(type='list') ) argument_spec.update(nxos_argument_spec) diff --git a/lib/ansible/modules/network/nxos/nxos_ping.py b/lib/ansible/modules/network/nxos/nxos_ping.py index e5afc07f276..9593aeb1696 100644 --- a/lib/ansible/modules/network/nxos/nxos_ping.py +++ b/lib/ansible/modules/network/nxos/nxos_ping.py @@ -43,18 +43,13 @@ options: count: description: - Number of packets to send. - required: false - default: 2 + default: 5 source: description: - - Source IP Address. - required: false - default: null + - Source IP Address or hostname (resolvable by switch) vrf: description: - Outgoing VRF. - required: false - default: null state: description: - Determines if the expected result is success or fail. @@ -183,7 +178,7 @@ def get_ping_results(command, module): def main(): argument_spec = dict( dest=dict(required=True), - count=dict(required=False, default=2), + count=dict(required=False, default=5), vrf=dict(required=False), source=dict(required=False), state=dict(required=False, choices=['present', 'absent'], default='present'), @@ -200,9 +195,6 @@ def main(): count = module.params['count'] state = module.params['state'] - if count and not 1 <= int(count) <= 655350: - module.fail_json(msg="'count' must be an integer between 1 and 655350.", count=count) - ping_command = 'ping {0}'.format(destination) for command in ['count', 'source', 'vrf']: arg = module.params[command] diff --git a/lib/ansible/plugins/cliconf/ios.py b/lib/ansible/plugins/cliconf/ios.py index 9b86e067d49..6a93c337a56 100644 --- a/lib/ansible/plugins/cliconf/ios.py +++ b/lib/ansible/plugins/cliconf/ios.py @@ -38,9 +38,9 @@ class Cliconf(CliconfBase): reply = self.get(b'show version') data = to_text(reply, errors='surrogate_or_strict').strip() - match = re.search(r'Version (\S+),', data) + match = re.search(r'Version (\S+)', data) if match: - device_info['network_os_version'] = match.group(1) + device_info['network_os_version'] = match.group(1).strip(',') match = re.search(r'^Cisco (.+) \(revision', data, re.M) if match: diff --git a/lib/ansible/plugins/terminal/nxos.py b/lib/ansible/plugins/terminal/nxos.py index 698fe4a2fdc..38419ccfeab 100644 --- a/lib/ansible/plugins/terminal/nxos.py +++ b/lib/ansible/plugins/terminal/nxos.py @@ -30,7 +30,7 @@ from ansible.module_utils._text import to_bytes, to_text class TerminalModule(TerminalBase): terminal_stdout_re = [ - re.compile(br'[\r\n](?!\s*<)?(\x1b\S+)*[a-zA-Z_]{1}[a-zA-Z0-9-_.]*[>|#|%](?:\s*)*(\x1b\S+)*$'), + re.compile(br'[\r\n]?(?!\s*<)?(\x1b\S+)*[a-zA-Z_]{1}[a-zA-Z0-9-_.]*[>|#|%](?:\s*)*(\x1b\S+)*$'), re.compile(br'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-_.]*\(.+\)#(?:\s*)$') ] diff --git a/test/integration/targets/nxos_logging/tests/common/basic.yaml b/test/integration/targets/nxos_logging/tests/common/basic.yaml index 5e4d99eb524..f9bbb2c4106 100644 --- a/test/integration/targets/nxos_logging/tests/common/basic.yaml +++ b/test/integration/targets/nxos_logging/tests/common/basic.yaml @@ -4,7 +4,7 @@ when: ansible_connection == "local" - name: Set up console logging - nxos_logging: + nxos_logging: &clog dest: console dest_level: 0 state: present @@ -17,73 +17,96 @@ - '"logging console 0" in result.commands' - name: Set up console logging again (idempotent) - nxos_logging: - dest: console - dest_level: 0 - state: present - provider: "{{ connection }}" + nxos_logging: *clog register: result -- assert: +- assert: &false that: - 'result.changed == false' -- name: Delete/disable console logging - nxos_logging: - dest: console - dest_level: 0 - state: absent +- name: Logfile logging with level + nxos_logging: &llog + dest: logfile + name: test + dest_level: 1 + state: present provider: "{{ connection }}" register: result - assert: that: - 'result.changed == true' - - '"no logging console" in result.commands' + - '"logging logfile test 1" in result.commands' -- name: Delete/disable console logging (idempotent) - nxos_logging: - dest: console - dest_level: 0 - state: absent +- name: Logfile logging with level (idempotent) + nxos_logging: *llog + register: result + +- assert: *false + +- name: Configure module with level + nxos_logging: &molog + dest: module + dest_level: 2 provider: "{{ connection }}" register: result - assert: that: - - 'result.changed == false' + - 'result.changed == true' + - '"logging module 2" in result.commands' -- name: Logfile logging with level - nxos_logging: - dest: logfile - name: test - dest_level: 0 - state: present +- name: Configure module with level (idempotent) + nxos_logging: *molog + register: result + +- assert: *false + +- name: Configure monitor with level + nxos_logging: &mlog + dest: monitor + dest_level: 3 provider: "{{ connection }}" register: result - assert: that: - 'result.changed == true' - - '"logging logfile test 0" in result.commands' + - '"logging monitor 3" in result.commands' + +- name: Configure monitor with level (idempotent) + nxos_logging: *mlog + register: result + +- assert: *false - name: Configure facility with level - nxos_logging: + nxos_logging: &flog facility: daemon - facility_level: 0 + facility_level: 4 provider: "{{ connection }}" register: result - assert: that: - 'result.changed == true' - - '"logging level daemon 0" in result.commands' + - '"logging level daemon 4" in result.commands' + +- name: Configure facility with level (idempotent) + nxos_logging: *flog + register: result + +- assert: *false - name: remove logging as collection tearDown - nxos_logging: + nxos_logging: &agg aggregate: - - { dest: logfile, name: test, dest_level: 0, state: absent } - - { facility: daemon, facility_level: 0, state: absent } + - { dest: console, dest_level: 0 } + - { dest: module, dest_level: 2 } + - { dest: monitor, dest_level: 3 } + - { dest: logfile, dest_level: 1, name: test } + - { facility: daemon, facility_level: 4 } + state: absent provider: "{{ connection }}" register: result @@ -92,5 +115,13 @@ - 'result.changed == true' - '"no logging logfile" in result.commands' - '"no logging level daemon" in result.commands' + - '"no logging monitor" in result.commands' + - '"no logging module" in result.commands' + +- name: remove aggregate logging (idempotent) + nxos_logging: *agg + register: result + +- assert: *false - debug: msg="END connection={{ ansible_connection }} nxos_logging basic test" diff --git a/test/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml b/test/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml index 05e0126b8d7..b5c8b31932c 100644 --- a/test/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_vxlan_vtep_vni/tests/common/sanity.yaml @@ -123,12 +123,30 @@ - assert: *true - - name: "Conf 6 Idempotence" + - name: check configure vxlan_vtep_vni ingress static idempotence check nxos_vxlan_vtep_vni: *conf6 register: result - assert: *false + - name: Remove and reconfigure vxlan_vtep + nxos_vxlan_vtep: &remove_vtep + interface: nve1 + state: absent + provider: "{{ connection }}" + + - name: Configure vxlan_vtep with host reachability bgp + nxos_vxlan_vtep: + interface: nve1 + host_reachability: True + provider: "{{ connection }}" + + - name: configure vxlan_vtep_vni + nxos_vxlan_vtep_vni: &config_vni + interface: nve1 + vni: 8000 + provider: "{{ connection }}" + - name: configure vxlan_vtep_vni ingress bgp nxos_vxlan_vtep_vni: &conf7 interface: nve1 @@ -161,6 +179,18 @@ - assert: *false + - name: Remove and reconfigure vxlan_vtep + nxos_vxlan_vtep: *remove_vtep + + - name: Configure vxlan_vtep with host reachability static + nxos_vxlan_vtep: + interface: nve1 + host_reachability: False + provider: "{{ connection }}" + + - name: configure vxlan_vtep_vni + nxos_vxlan_vtep_vni: *config_vni + - name: configure vxlan_vtep_vni peer-list nxos_vxlan_vtep_vni: &conf9 interface: nve1 diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt index 238919bc867..187257a8971 100644 --- a/test/sanity/validate-modules/ignore.txt +++ b/test/sanity/validate-modules/ignore.txt @@ -1730,7 +1730,6 @@ lib/ansible/modules/network/nxos/nxos_linkagg.py E324 lib/ansible/modules/network/nxos/nxos_linkagg.py E325 lib/ansible/modules/network/nxos/nxos_linkagg.py E326 lib/ansible/modules/network/nxos/nxos_lldp.py E326 -lib/ansible/modules/network/nxos/nxos_logging.py E325 lib/ansible/modules/network/nxos/nxos_ntp_auth.py E324 lib/ansible/modules/network/nxos/nxos_ntp_options.py E325 lib/ansible/modules/network/nxos/nxos_ntp_options.py E326