-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure_preview.yml
178 lines (154 loc) · 5.3 KB
/
azure_preview.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
language: python
python: '2.7'
env:
global:
- exit_code=0
- message=()
- ANSIBLE_VERSION=latest
- max_retry_count=2
- max_id=30
#- ANSIBLE_VERSION=2.5.5
matrix:
- id=1
- id=2
- id=3
- id=4
- id=5
- id=6
- id=7
- id=8
- id=9
- id=10
- id=11
- id=12
- id=13
- id=14
- id=15
- id=16
- id=17
- id=18
- id=19
- id=20
- id=21
- id=22
- id=23
- id=24
- id=25
- id=26
- id=27
- id=28
- id=29
- id=30
before_install:
- sudo apt-get update -qq
- mkdir ~/.azure
- touch ~/.azure/credentials
- printf "[default]\nsubscription_id=${subscriptionId}\nclient_id=${clientId}\nsecret=${secret}\ntenant=${tenant}" > ~/.azure/credentials
- run_test(){
file=$1;
filename=${file##tests/integration/};
test_name=${file##tests/integration/targets/};
test_name=${test_name%%/tasks/main.yml};
m=1;
echo Run test $test_name from $filename;
resource_group="asb-roletest-${test_name##azure_rm_}$(date +%s)";
resource_group_secondary="asb-roletest-${test_name##azure_rm_}$(date +%s)2nd";
resource_prefix=$(date +%s);
printf "{\"resource_group\":\"$resource_group\",\n\"test\":\"$test_name\",\n\"resource_group_secondary\":\"$resource_group_secondary\",\n\"azure_object_id\":\"$AZURE_OBJECT_ID\",\n\"resource_prefix\":\"$resource_prefix\",\n\"azure_tenant\":\"$AZURE_TENANT\",\n\"azure_client_id\":\"$AZURE_CLIENT_ID\",\n\"azure_secret\":\"$AZURE_SECRET\",\n\"azure_subscription_id\":\"$AZURE_SUBSCRIPTION_ID\"}" > ~/arg.json;
cat ~/arg.json;
while [ $m -le $max_retry_count ]; do
echo Run test $m time;
travis_wait 50 ansible-playbook tests/integration/main.yml;
if [ $? -ne 0 ]; then
echo test $test_name failed;
if [ $m -eq $max_retry_count ]; then
message+=($test_name);
export exit_code=1;
fi;
m=$[$m+1];
else
echo test $test_name passed;
break;
fi;
done;
}
- scan_test() {
branch=$TRAVIS_BRANCH;
echo branch is $branch;
diffstr=$(git diff $branch remotes/origin/master --name-only -- * --no-pager);
liststr=tests/integration/targets/azure_rm_*;
list=($liststr);
run_all=true
echo run_all is $run_all;
if [ "$run_all" == true ]; then
listfiles=tests/integration/targets/azure_rm_*/tasks/main.yml;
sorted_unique_testList=($listfiles);
else
testlist=();
for changedfile in ${diffstr[*]}; do
arrChanged=(${changedfile//// });
changedFileName=${arrChanged[-1]};
changedFileNameWithPath=${arrChanged[-2]};
echo changedfile is $changedfile;
fileNameNoExtension=${changedFileName%%.py};
if [[ ! -f $changedfile ]]; then
continue;
fi;
if [[ -d "tests/integration/targets/${fileNameNoExtension}" ]]; then
echo test tests/integration/targets/${fileNameNoExtension}/tasks/main.yml;
testList=("tests/integration/targets/${fileNameNoExtension}/tasks/main.yml" "${testList[@]}");
elif [ "$changedFileName" == "main.yml" ]; then
if [[ "$changedFileNameWithPath" == "tasks" ]]; then
echo test $changedfile;
testList=("${changedfile}" "${testList[@]}");
fi;
else
for alias in "${list[@]}"; do
if grep -Fxq "$changedFileName" "${alias}/aliases"; then
if grep -Fxq "unsupported" "${alias}/aliases"; then
echo "not supported test";
else
echo test $alias;
testList=("${alias}/tasks/main.yml" "${testList[@]}");
break;
fi;
fi;
done;
fi;
done;
sorted_unique_testList=($(echo "${testList[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '));
fi;
total_length=${#sorted_unique_testList[@]};
number_per_job=$((${#sorted_unique_testList[@]}/$max_id+1));
start=$((id-1));
echo start = $start, list_lenth = $total_length;
for (( i = $start; i < $total_length; i=$i+$max_id )); do
echo "Running ${i}th test";
aliasFile="${sorted_unique_testList[$i]%%tasks/main.yml}";
if grep -Fxq "unsupported" "${aliasFile}/aliases"; then
echo "not supported declared in ${aliasFile}/aliases";
else
echo test file is ${sorted_unique_testList[$i]};
run_test ${sorted_unique_testList[$i]};
fi;
done;
}
install:
- if [ "$ANSIBLE_VERSION" == "latest" ]; then pip install ansible[azure]; else pip install ansible[azure]==$ANSIBLE_VERSION; fi
- "{ echo '[defaults]'; echo 'roles_path = ../'; echo 'lookup_plugins = ./tests/integration/targets/azure_rm_keyvaultkey/lookup_plugins'; } >> ansible.cfg"
- ansible --version
- ansible-galaxy init ../setup_azure
- pip install -I -r ./files/requirements-azure.txt
- pip install xmltodict
- pip freeze
- git remote set-branches --add origin master
- git fetch
script:
- scan_test
- exit $exit_code
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
email: