From 5ac1b7772b137d6631d362ae73a115177ace76fb Mon Sep 17 00:00:00 2001 From: Longxiang Lyu Date: Mon, 13 Jul 2020 07:26:56 +0000 Subject: [PATCH] [Ansible] Start ptf_tgen in ptf container Add following steps to `add_topo`: 1. Copy requried scripts to /ptf_tgen of `PTF` container. 2. Start the ptf_tgen supervisor process inside `PTF` container. **NOTICE**: skip if * `topo` is not `fullmesh` * `ptf_tgen` supervisor process is present. Signed-off-by: Longxiang Lyu --- ansible/roles/vm_set/tasks/add_topo.yml | 4 ++ ansible/roles/vm_set/tasks/start_ptf_tgen.yml | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ansible/roles/vm_set/tasks/start_ptf_tgen.yml diff --git a/ansible/roles/vm_set/tasks/add_topo.yml b/ansible/roles/vm_set/tasks/add_topo.yml index 8b1dd6eb8e4..afbb1e1e050 100644 --- a/ansible/roles/vm_set/tasks/add_topo.yml +++ b/ansible/roles/vm_set/tasks/add_topo.yml @@ -70,3 +70,7 @@ - name: Send arp ping packet to gw for flusing the ARP table command: docker exec -i ptf_{{ vm_set_name }} python -c "from scapy.all import *; arping('{{ mgmt_gw }}')" become: yes + +- name: Start ptf_tgen service + include_tasks: start_ptf_tgen.yml + when: topo == 'fullmesh' diff --git a/ansible/roles/vm_set/tasks/start_ptf_tgen.yml b/ansible/roles/vm_set/tasks/start_ptf_tgen.yml new file mode 100644 index 00000000000..26aecd1f235 --- /dev/null +++ b/ansible/roles/vm_set/tasks/start_ptf_tgen.yml @@ -0,0 +1,55 @@ +--- +- name: Include variables for PTF containers + include_vars: + dir: "{{ playbook_dir }}/group_vars/ptf_host/" + +- block: + - name: Set ptf host + set_fact: + ptf_host: "ptf_{{ vm_set_name }}" + ptf_host_ip: "{{ ptf_ip.split('/')[0] }}" + + - name: Add ptf host + add_host: + hostname: "{{ ptf_host }}" + ansible_user: "{{ ptf_host_user }}" + ansible_ssh_host: "{{ ptf_host_ip }}" + ansible_ssh_pass: "{{ ptf_host_pass }}" + groups: + - ptf_host + + - name: Check if ptf_tgen exists + supervisorctl: + name: ptf_tgen + state: present + become: True + delegate_to: "{{ ptf_host }}" + ignore_errors: True + register: ptf_tgen_state + + - block: + - name: Copy scapy scripts to ptf host + copy: + src: "{{ item }}" + dest: "/ptf_tgen/" + with_fileglob: + - "{{ playbook_dir }}/../spytest/spytest/tgen/scapy/*" + - "{{ playbook_dir }}/../spytest/spytest/dicts.py" + + - name: Create ptf_tgen service + copy: + src: "/ptf_tgen/service.sh" + dest: "/ptf_tgen/ptf_tgen.sh" + mode: "0755" + remote_src: yes + + - name: Start ptf_tgen + supervisorctl: + name: ptf_tgen + state: restarted + become: True + delegate_to: "{{ ptf_host }}" + when: ptf_tgen_state is not failed + when: + - ptf_host_user is defined + - ptf_host_pass is defined