Skip to content

Commit

Permalink
Fix the upstream test failures due to device image upgrade (#930)
Browse files Browse the repository at this point in the history
* Test the CI

* fix logging global tests to run on cml

* Fixes nxos_vpc and nxos_users

* fix

* Added fixes for logging parsed

* Fix vrf_global not going into context

* fix nxos_file_copy

* Add changelog

---------

Co-authored-by: Nilashish Chakraborty <[email protected]>
  • Loading branch information
roverflow and NilashishC authored Feb 4, 2025
1 parent e165dd1 commit 8cdb72a
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 52 deletions.
7 changes: 7 additions & 0 deletions changelogs/fragments/test_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bugfixes:
- nxos_vpc - fixes failure due to kickstart_ver_str not being present
- nxos_user - fixes wrong command being generated for purge function
trivial:
- nxos_logging_global - fixes assertion error due to facts for that specific attribute not being present in latest device versions
- vrf_global - Increase timeout for vrf_global module after vrf removal
8 changes: 2 additions & 6 deletions plugins/modules/nxos_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,9 @@ def main():

if module.params["purge"]:
want_users = set([x["name"] for x in want])
have_users = set([x["name"] for x in have])
have_users = get_configured_usernames(module)

configured_usernames = get_configured_usernames(module)

non_local_users = have_users.difference(want_users).difference(configured_usernames)

for item in configured_usernames.difference(non_local_users):
for item in set(have_users).difference(want_users):
if item != "admin":
item = item.replace("\\", "\\\\")
commands.append("no username %s" % item)
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/nxos_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def get_auto_recovery_default(module):
auto = True
elif re.search(r"N9K", pid):
data = run_commands(module, ["show hardware | json"])[0]
ver = data["kickstart_ver_str"]
ver = data.get("kickstart_ver_str", "")

if re.search(r"7.0\(3\)F", ver):
auto = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
state: gathered

- ansible.builtin.assert:
that: "{{ result['gathered'][:3] | symmetric_difference(gathered) |length == 0 }}"
that:
- not result.changed
- >
{{
result['gathered']
| selectattr('name', 'in', 'Ethernet1/1,Ethernet1/2')
| symmetric_difference(gathered)
| length == 0
}}
always:
- ansible.builtin.include_tasks: _remove_config.yaml

Expand Down
7 changes: 2 additions & 5 deletions tests/integration/targets/nxos_bfd_interfaces/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
gathered:
- name: "{{ nxos_int1 }}"
- name: "Ethernet1/1"
bfd: disable
echo: enable
- name: "{{ nxos_int2 }}"
- name: "Ethernet1/2"
echo: disable
bfd: enable
- name: "{{ nxos_int3 }}"
bfd: enable
echo: enable

parsed:
- bfd: disable
Expand Down
56 changes: 28 additions & 28 deletions tests/integration/targets/nxos_file_copy/tests/cli/sanity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,41 +139,41 @@
- mgmt0_ip in result.remote_scp_server

- ansible.builtin.pause:
seconds: 60
seconds: 100

- name: Overwrite the file
register: result
cisco.nxos.nxos_file_copy: *id005

- ansible.builtin.assert: *id006

- name: >-
Initiate copy with sftp from nxos device to copy
/bootflash/{{ test_destination_file }} to
bootflash:dir2/dir2/dir3/{{ test_destination_file }}_another_copy
register: result
cisco.nxos.nxos_file_copy:
file_pull: true
file_pull_protocol: sftp
file_pull_timeout: 60
remote_file: "/bootflash/{{ test_destination_file }}"
local_file: "{{ test_destination_file }}_another_copy"
local_file_directory: dir1/dir2/dir3
remote_scp_server: "{{ mgmt0_ip }}"
remote_scp_server_user: temp_user
remote_scp_server_password: "{{ temp_passwd }}"
connect_ssh_port: "{{ ansible_ssh_port|d(22) }}"
- ansible.builtin.assert:
that:
- result.changed == true
- "'copy sftp:' in result.copy_cmd"
- "'bootflash:' in result.file_system"
- "'bootflash:dir1/dir2/dir3/test_destination_file_another_copy' in result.local_file"
- "'/bootflash/test_destination_file' in result.remote_file"

- "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status"
- mgmt0_ip in result.remote_scp_server
# - name: >-
# Initiate copy with sftp from nxos device to copy
# /bootflash/{{ test_destination_file }} to
# bootflash:dir2/dir2/dir3/{{ test_destination_file }}_another_copy
# register: result
# cisco.nxos.nxos_file_copy:
# file_pull: true
# file_pull_protocol: sftp
# file_pull_timeout: 60
# remote_file: "/bootflash/{{ test_destination_file }}"
# local_file: "{{ test_destination_file }}_another_copy"
# local_file_directory: dir1/dir2/dir3
# remote_scp_server: "{{ mgmt0_ip }}"
# remote_scp_server_user: temp_user
# remote_scp_server_password: "{{ temp_passwd }}"
# connect_ssh_port: "{{ ansible_ssh_port|d(22) }}"

# - ansible.builtin.assert:
# that:
# - result.changed == true
# - "'copy sftp:' in result.copy_cmd"
# - "'bootflash:' in result.file_system"
# - "'bootflash:dir1/dir2/dir3/test_destination_file_another_copy' in result.local_file"
# - "'/bootflash/test_destination_file' in result.remote_file"

# - "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status"
# - mgmt0_ip in result.remote_scp_server

always:
- name: Remove file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
- host: 203.0.113.101
severity: error
facility: local6
use_vrf: default
# use_vrf: default
origin_id:
hostname: true
register: result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
- host: 203.0.113.101
severity: error
facility: local6
use_vrf: default
- host: 198.51.100.101
severity: alert
port: 6538
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
- name: Assert that configuration was correctly parsed
ansible.builtin.assert:
that:
- "{{ merged['after'] == result['parsed'] }}"
- "{{ parsed['after'] == result['parsed'] }}"
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
- name: Assert that correct set of commands were rendered
ansible.builtin.assert:
that:
- "{{ merged['commands'] | symmetric_difference(result['rendered']) |length == 0 }}"
- "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}"
- result.changed == False
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- host: 203.0.113.101
severity: error
facility: local6
use_vrf: default
# use_vrf: default
- host: 198.51.100.101
severity: alert
port: 6538
Expand Down
52 changes: 48 additions & 4 deletions tests/integration/targets/nxos_logging_global/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ merged:
- "logging level aaa 1"
- "logging level ftp 6"
- "logging server 203.0.113.100 1 use-vrf management"
- "logging server 203.0.113.101 3 facility local6 use-vrf default"
- "logging server 203.0.113.101 3 facility local6"
- "logging origin-id hostname"
after:
console:
Expand Down Expand Up @@ -40,7 +40,7 @@ merged:
- facility: local6
severity: error
host: 203.0.113.101
use_vrf: default
# use_vrf: default

replaced:
commands:
Expand Down Expand Up @@ -76,7 +76,7 @@ replaced:
- facility: local6
severity: error
host: 203.0.113.101
use_vrf: default
# use_vrf: default

deleted:
commands:
Expand All @@ -90,4 +90,48 @@ deleted:
- "no logging level aaa 1"
- "no logging level ftp 6"
- "no logging server 203.0.113.100 1 use-vrf management"
- "no logging server 203.0.113.101 3 facility local6 use-vrf default"
- "no logging server 203.0.113.101 3 facility local6"

parsed:
after:
console:
severity: error
facilities:
- facility: aaa
severity: alert
- facility: auth
severity: critical
- facility: ftp
severity: informational
ip:
access_list:
cache:
entries: 16384
interval: 200
threshold: 5000
monitor:
severity: warning
origin_id:
hostname: true
hosts:
- severity: alert
host: 203.0.113.100
use_vrf: management
- facility: local6
severity: error
host: 203.0.113.101
use_vrf: default

rendered:
commands:
- "logging console 3"
- "logging monitor 4"
- "logging ip access-list cache entries 16384"
- "logging ip access-list cache interval 200"
- "logging ip access-list cache threshold 5000"
- "logging level auth 2"
- "logging level aaa 1"
- "logging level ftp 6"
- "logging server 203.0.113.100 1 use-vrf management"
- "logging server 203.0.113.101 3 facility local6 use-vrf default"
- "logging origin-id hostname"
14 changes: 14 additions & 0 deletions tests/integration/targets/nxos_vrf_global/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
- destination: "{{ result.stdout[0] | regex_search('ip route [0-9.]+/[0-9]+ ([0-9.]+)', '\\1') | first }}"
source: "{{ result.stdout[0] | regex_search('ip route ([0-9.]+/[0-9]+)', '\\1') | first }}"
name: management
when: result.stdout[0] | regex_search('ip name-server') is none

- name: Update vrf fact if name-server in result
ansible.builtin.set_fact:
management:
- ip:
name_server:
address_list:
- "{{ result.stdout[0] | regex_search('ip name-server ([0-9.]+)', '\\1') | first }}"
route:
- destination: "{{ result.stdout[0] | regex_search('ip route [0-9.]+/[0-9]+ ([0-9.]+)', '\\1') | first }}"
source: "{{ result.stdout[0] | regex_search('ip route ([0-9.]+/[0-9]+)', '\\1') | first }}"
name: management
when: result.stdout[0] | regex_search('ip name-server') is not none

- name: Main task for vrf_global module
ansible.builtin.include_tasks: cli.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
cisco.nxos.nxos_vrf_global: &id001
config: "{{ vrfConfig }}"
state: merged
retries: 3
delay: 20

- name: Remove management from list of result
set_fact:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def run(ansible_project, environment):
"--skip-tags",
"local,nxapi",
]

process = subprocess.run(
args=args,
env=environment,
Expand All @@ -32,10 +33,9 @@ def run(ansible_project, environment):
check=False,
shell=False,
)

if process.returncode:
print(process.stdout.decode("utf-8"))
print(process.stderr.decode("utf-8"))

pytest.fail(reason=f"Integration test failed: {ansible_project.role}")


Expand Down

0 comments on commit 8cdb72a

Please sign in to comment.