From ca55b302b48c46d89914ff44198cb07eed294f79 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 7 Mar 2019 14:09:01 +0800 Subject: [PATCH 1/2] [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 --- ansible/roles/test/tasks/ptf_runner.yml | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ansible/roles/test/tasks/ptf_runner.yml b/ansible/roles/test/tasks/ptf_runner.yml index 467d946d617..7f95175b2bd 100644 --- a/ansible/roles/test/tasks/ptf_runner.yml +++ b/ansible/roles/test/tasks/ptf_runner.yml @@ -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 + +- debug: msg="File {{ item }} saved to test/{{ inventory_hostname }}/ptf/" + with_items: + - "{{ptf_log_file}}" + - "{{ptf_pcap_file}}" + when: out.rc != 0 + - fail: msg="Failed test '{{ ptf_test_name }}'" when: out.rc != 0 From 0c7924d3724e54cc847f15ec5defa746b4d18bbc Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 21 Mar 2019 12:16:58 +0800 Subject: [PATCH 2/2] [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 .yml ... -e save_ptf_log=yes --- ansible/roles/test/tasks/ptf_runner.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/test/tasks/ptf_runner.yml b/ansible/roles/test/tasks/ptf_runner.yml index 7f95175b2bd..67a5f15d45b 100644 --- a/ansible/roles/test/tasks/ptf_runner.yml +++ b/ansible/roles/test/tasks/ptf_runner.yml @@ -74,13 +74,13 @@ - "{{ ptf_log_file }}" - "{{ ptf_pcap_file }}" delegate_to: "{{ ptf_host }}" - when: out.rc != 0 + 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 + 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