Skip to content

Commit

Permalink
[ptf_runner] Save ptf log to script executing host in case of failure (
Browse files Browse the repository at this point in the history
…#823)

* [ptf_runner] Save ptf log to script executing host in case of failure

The PTF log and pcap files are useful for debugging in case of PTF
script failed. However, these files are in the PTF container and could
be lost when the PTF container is re-deployed.

This improvement is to save the log and pcap files to the script
executing host when the PTF script is failed.

Signed-off-by: Xin Wang <xinw@mellanox.com>

* [ptf_runner] Add option for specifying whether to save ptf log

The previous commit changed the default behavior. This change is to add
an option for specifying whether to save ptf log in case of failure.
For example: ansible-playbook <some_test>.yml ... -e save_ptf_log=yes
  • Loading branch information
wangxin authored and lguohan committed Apr 10, 2019
1 parent 0541bf2 commit 56c9a00
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ansible/roles/test/tasks/ptf_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,36 @@

- debug: var=out.stdout_lines

- name: Set default PTF log filename
set_fact:
ptf_log_file: "/root/ptf.log"
ptf_log_file_param_index: "{{ out.cmd.find('--log-file') }}"

- name: Parse custom log filename specified in PTF command
set_fact:
ptf_log_file: "{{ out.cmd[ptf_log_file_param_index|int:].split(' ')[1] }}"
when: ptf_log_file_param_index|int >= 0

- name: Set PTF pcap filename
set_fact:
ptf_pcap_file: "{{ ptf_log_file | replace('.log', '.pcap') }}"

- name : Fetch result files from switch to ansible machine
fetch:
src: "{{ item }}"
dest: "test/{{ inventory_hostname }}/ptf/{{ item | basename }}.{{lookup('pipe','date +%Y-%m-%d-%H:%M:%S')}}"
flat: yes
with_items:
- "{{ ptf_log_file }}"
- "{{ ptf_pcap_file }}"
delegate_to: "{{ ptf_host }}"
when: out.rc != 0 and save_ptf_log is defined and save_ptf_log|bool == true

- debug: msg="File {{ item }} saved to test/{{ inventory_hostname }}/ptf/"
with_items:
- "{{ptf_log_file}}"
- "{{ptf_pcap_file}}"
when: out.rc != 0 and save_ptf_log is defined and save_ptf_log|bool == true

- fail: msg="Failed test '{{ ptf_test_name }}'"
when: out.rc != 0

0 comments on commit 56c9a00

Please sign in to comment.