This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-testcases-in-parallel.yml
75 lines (63 loc) · 2.36 KB
/
run-testcases-in-parallel.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
- hosts: localhost
gather_facts: false
tasks:
- name: get timestamp
shell: date +%Y%m%d%H%M%S
register: timestamp
- name: list all test environments
shell: (cd ../conf.d; ls group_and_hosts-*;)
register: testenvs
- debug: msg="{{ testenvs.stdout_lines }}"
- pause:
prompt: Which environment to run the testcases?
echo: yes
register: input_env
- name: list all test suites
shell: (cd ../conf.d; ls vars-*;)
register: testsuites
- debug: msg="{{ testsuites.stdout_lines }}"
- pause:
prompt: Which testsuite to run?
echo: yes
register: input_suite
- debug: msg="{{ input_env.user_input }}"
- debug: msg="{{ input_suite.user_input }}"
- name: read from {{ input_suite.user_input }}
set_fact:
test_cases: "{{ (suite_content | from_yaml).testcases | map(attribute='name') | list}}"
test_logpath: ../logs/{{ timestamp.stdout }}--{{ input_env.user_input }}--{{ input_suite.user_input }}
test_env: "{{ input_env.user_input }}"
test_suite: "{{ input_suite.user_input }}"
vars:
suite_content: "{{ lookup('file', '../conf.d/{{ input_suite.user_input }}') }}"
- name: going to test the following cases
debug: msg="{{ test_cases }}"
- name: create log directory {{ test_logpath }}
file: path="{{ test_logpath }}" state=directory
# TODO: run the testcases in separate tenants to avoid mutual impacts.
- name: run test_cases in parallel.
shell: |
cmd="ansible-playbook -i ../conf.d/{{ test_env }} -e @../conf.d/{{ test_suite }} ../testcases/dev_test.yml -t {{ item }}"
echo $cmd > {{ test_logpath }}/{{ item }}.log
date >> {{ test_logpath }}/{{ item }}.log
start=`date +%s`
$cmd >> {{ test_logpath }}/{{ item }}.log
result=$?
end=`date +%s`
echo $(($end - $start)) >> {{ test_logpath }}/{{ item }}.log
exit $result
with_items: "{{ test_cases }}"
async: 1800
poll: 0
register: test_processes
# - name: show async processes ids
# debug: msg="{{ test_processes }}"
- name: waiting for tests to be finished
async_status:
jid: "{{ item.ansible_job_id }}"
register: inst
until: inst.finished
delay: 5
retries: 120
with_items: "{{ test_processes.results }}"