Skip to content
Merged
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
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 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