Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- debug: msg={{cmd}}

- name: Initialize loganalyzer {{ testname }}
- name: Invoke loganalyzer analyse {{ testname }}
become: True
shell: "{{ cmd }}"
args:
Expand Down
53 changes: 37 additions & 16 deletions ansible/roles/test/files/tools/loganalyzer/loganalyzer_end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,45 @@
#------------------------------------------------

- set_fact:
result_file: result.loganalysis.{{testname_unique}}.log
summary_file: summary.loganalysis.{{testname_unique}}.log
- debug : msg="summary_file {{summary_file}}"
result_file: result.loganalysis.{{ testname_unique }}.log
summary_file: summary.loganalysis.{{ testname_unique }}.log
test_fetch_dir: test/{{ inventory_hostname }}

# Output content of result files to ansible console
- shell: cat {{ test_out_dir }}/*
register: out
- debug: var=out.stdout_lines

- name: Check if loganalyzer found any error
shell: grep "TOTAL MATCHES" "{{ test_out_dir }}/{{ summary_file }}" | sed -n "s/TOTAL MATCHES:[[:space:]]*//p"
register: errors_found

- set_fact:
fail_in_logs: errors_found.stdout != "0"

- name: Generate system dump
command: sonic_support
register: sonic_support
when: fail_in_logs

- name : Fetch result files from switch to ansible machine
fetch: src={{ test_out_dir }}/{{item}} dest=/tmp
fetch:
src: "{{ item }}"
dest: "{{ test_fetch_dir }}/{{ item | basename }}"
flat: yes
with_items:
- "{{result_file}}"
- "{{summary_file}}"

- name : Create destination directory on PTF host for loganalyzer results
file: path="{{ test_out_dir }}" state=directory
delegate_to: "{{ ptf_host }}"
- "{{ test_out_dir }}/{{result_file}}"
- "{{ test_out_dir }}/{{summary_file}}"
- "{{ sonic_support.stdout | default(omit) }}"
when: fail_in_logs

- name: Copy loganalyzer result files from ansible machine to PTF host
copy: src="/tmp/{{inventory_hostname}}/{{test_out_dir}}/{{item}}" dest="{{ test_out_dir }}/{{item}}"
- debug: msg="File {{ item }} saved to {{ test_fetch_dir }}"
with_items:
- "{{ result_file }}"
- "{{ summary_file }}"
delegate_to: "{{ ptf_host }}"
- "{{result_file}}"
- "{{summary_file}}"
- "{{ sonic_support.stdout | default(omit) }}"
when: fail_in_logs

- debug: msg="Location of log files on PTF host - {{ test_out_dir }}"
- name: Fail due to errors in logs
fail:
when: fail_in_logs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- name: create output directory for current test run
file: path="{{ test_out_dir }}" state=directory

- name: Force log rotation to have most of log file available
command: logrotate -f /etc/logrotate.conf

- debug: msg="starting loganalyzer_init.py"
- debug: msg="python {{ run_dir }}/loganalyzer.py --action init --run_id {{ testname_unique }}"
Expand Down
7 changes: 1 addition & 6 deletions ansible/roles/test/tasks/lag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,4 @@
always:
- include: roles/test/files/tools/loganalyzer/loganalyzer_analyze.yml

# Output content of result files to ansible console
- shell: cat {{ test_out_dir }}/*
register: out
- debug: var=out.stdout_lines

- include: roles/test/files/tools/loganalyzer/loganalyzer_end.yml
- include: roles/test/files/tools/loganalyzer/loganalyzer_end.yml