Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Changes from 1 commit
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here default PTF log file is set to /root/ptf.log, but all tests use /tmp/.
I believe it would be better to change this default to /tmp/ as well, so we have all logs in one place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is to specify where to get the PTF log and pcap files from the PTF container.

When PTF log file is not explicitly specified while calling ptf_runner.yml, PTF saves default log and pcap files to /root/ptf.log and /root/ptf.pcap on PTF container.

If explicit log file parameter is parsed from the PTF command line, this default value will be overwritten with custom log file location.

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
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved

- debug: msg="File {{ item }} saved to test/{{ inventory_hostname }}/ptf/"
with_items:
- "{{ptf_log_file}}"
- "{{ptf_pcap_file}}"
when: out.rc != 0
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved

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