forked from pmacct/pmacct
-
Notifications
You must be signed in to change notification settings - Fork 0
339 lines (308 loc) · 12.5 KB
/
regression_tests.yaml
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
name: regression_tests
on:
push:
pull_request:
schedule:
- cron: '0 0 * * *' # every day at midnight
workflow_dispatch:
inputs:
default_only:
description: 'Test default scenarios only'
required: false
type: boolean
commit_id:
description: 'Commit ID'
required: false
default: ''
marker:
description: 'Pytest Marker (defined in pytest.ini)'
required: false
default: ''
type: choice
options:
- ''
- basic
- ipfix
- bmp
- bgp
- avro
- json
- redis
- signals
- ha
jobs:
### Step 0: Build Traffic Reproducer Images
### Step 1: Build Traffic Reproducer Images
traf-repro-docker:
runs-on: ubuntu-22.04
steps:
- name: Checkout pmacct
uses: actions/checkout@v4
with:
path: pmacct
submodules: recursive
- name: Create Traffic Reproducer Docker Images
run: |
sudo apt update
sudo apt install docker
cd pmacct/test-framework
tools/pcap_player/build_docker_image.sh
- name: Check Images and Save as Artifacts
run: |
echo "Checking Images..."
docker images | grep _build
echo
echo "Saving images as artifacts..."
mkdir -p /tmp/docker/
docker save -o /tmp/docker/traffic_reproducer_docker_images.tar traffic-reproducer:_build
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: traffic_reproducer_docker_images
path: /tmp/docker
### Step 2: Retrieve all other necessary images from Docker Hub and store as artifacts
### (to avoid possible Docker Hub pull limits)
cache-docker-images:
runs-on: ubuntu-22.04
steps:
- name: Checkout pmacct
uses: actions/checkout@v4
with:
path: pmacct
- name: Build containers
uses: ./pmacct/.github/actions/build_containers/
- name: Download images and prepare artifacts
run: |
cd pmacct/test-framework
source settings.conf
docker image pull $ZOOKEEPER_IMG
docker image pull $KAFKA_IMG
docker image pull $SCHEMAREGISTRY_IMG
docker image pull $REDIS_IMG
echo "List Images"
docker images | grep 'confluentinc\|redis'
echo
echo "Saving images as artifacts..."
mkdir -p /tmp/docker/
PMACCT_IMAGES=$(docker image ls | grep "_build")
docker save -o /tmp/docker/hub_pulled_docker_images.tar $ZOOKEEPER_IMG $KAFKA_IMG $SCHEMAREGISTRY_IMG $REDIS_IMG $PMACCT_IMAGES
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: hub_pulled_docker_images
path: /tmp/docker
### Step 3: Collect tests from framework
collect-tests:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout pmacct
uses: actions/checkout@v4
with:
path: pmacct
- name: Collect list of tests from tests/ folder
id: set-matrix
run: |
cd pmacct/tests
MATRIX="{"test": $(find . -mindepth 1 -maxdepth 1 -type d | cut -c 3- | cut -c 1-3 | sort | jq -R -s -c 'split("\n")[:-1]')}"
echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT
echo "Collected tests:"
echo $MATRIX
### Step 4: Setup Framework and Run Tests
pytest-runtests:
needs: [collect-tests, traf-repro-docker, hub-pulled-docker]
runs-on: ubuntu-22.04
env:
SKIP: 'false'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.collect-tests.outputs.matrix) }}
steps:
- name: Checkout pmacct
uses: actions/checkout@v4
with:
path: pmacct
fetch-depth: 0
fetch-tags: 1
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Framework Requirements
run: |
sudo apt update
sudo apt install librdkafka-dev docker
pip install --upgrade pip
pip install -r pmacct/test-framework/requirements.txt
- name: Dry-run to check collected tests
if: ${{ success() && inputs.marker != '' }}
env:
MARKER: ${{ inputs.marker }}
run: |
function intercept_pytest_no_tests_collected {
exit_code=$?
if [[ ${exit_code} -eq 5 ]]
then
echo "Intercepting pytest exit code 5 (no tests collected) and replacing with 0"
echo "Setting early_exit to true!"
echo "SKIP=true" >> "$GITHUB_ENV"
exit 0
fi
}
trap intercept_pytest_no_tests_collected EXIT
cd pmacct/test-framework
sudo env PATH="$PATH" ./runtest.sh --dry ${{ matrix.test }} --mark="$MARKER"
- name: Download Artifacts
if: ${{ success() && env.SKIP == 'false' }}
uses: actions/download-artifact@v4
with:
pattern: '*_docker_images'
path: /tmp/docker
- name: Import images in the local registry
if: ${{ success() && env.SKIP == 'false' }}
run: |
docker load -i /tmp/docker/traffic_reproducer_docker_images/traffic_reproducer_docker_images.tar
docker load -i /tmp/docker/hub_pulled_docker_images/hub_pulled_docker_images.tar
echo "List Images"
docker images | grep 'confluentinc\|redis\|traffic\|_build'
- name: Run the test(s)
if: ${{ success() && env.SKIP == 'false' }}
env:
DEFAULT_ONLY: ${{ inputs.default_only }}
MARKER: ${{ inputs.marker }}
run: |
cd pmacct/test-framework
if [[ "$DEFAULT_ONLY" == "true" ]]; then
if [[ "$MARKER" == "" ]]; then
sudo env PATH="$PATH" ./runtest.sh ${{ matrix.test }}:00
else
sudo env PATH="$PATH" ./runtest.sh ${{ matrix.test }}:00 --mark="$MARKER"
fi
else
if [[ "$MARKER" == "" ]]; then
sudo env PATH="$PATH" ./runtest.sh ${{ matrix.test }}
else
sudo env PATH="$PATH" ./runtest.sh ${{ matrix.test }} --mark="$MARKER"
fi
fi
- name: Prepare Results Folder for Upload (permissions and folder name)
if: ${{ !cancelled() && env.SKIP == 'false' }} # always run this step, unless job manually cancelled or we are skipping the test
run: |
cd pmacct/test-framework
sudo chown -R 1000:1000 results/
sudo chmod -R 777 results/
echo "Adjust results folder name (when : or * is used as part of ./runtest.sh argument...)"
TEST_FOLDER_NAME=$( echo ${{ matrix.test }} | sed 's/\*/x/g' )
TEST_FOLDER_NAME=$( echo $TEST_FOLDER_NAME | sed 's/\:/_/g' )
echo "TEST_FOLDER_NAME=$TEST_FOLDER_NAME" >> "$GITHUB_ENV"
- name: Upload Results Folder
if: ${{ !cancelled() && env.SKIP == 'false' }} # always run this step, unless job manually cancelled or we are skipping the test
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: "test_results_${{ env.TEST_FOLDER_NAME }}"
path: pmacct/test-framework/results
# Step 5.5: Expose Results as Artifacts
pytest-results:
if: '!cancelled()' # always run this job, unless job manually cancelled
needs: pytest-runtests
runs-on: ubuntu-22.04
steps:
- name: Download Results Folder
uses: actions/download-artifact@v4
with:
pattern: test_results_*
path: results
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Requirements
run: |
pip install --upgrade pip
pip install pytest-html-merger
- name: Merge results (test logs, global logs, and reports) in a single folder
run: |
mkdir test_results_merged
cat results/**/pytestlog.log > test_results_merged/pytestlog.log
cat results/**/monitor.log > test_results_merged/monitor.log
find results/**/* -maxdepth 0 -type d -exec cp -r {} test_results_merged/ \;
mkdir tmp_html
randomname() { head -c16 /dev/urandom | base64 | tr -dc a-zA-Z; }
for f in results/**/report.html; do mv "$f" tmp_html/`randomname`.html; done
cp -R test_results_merged/assets tmp_html
pytest_html_merger -i tmp_html -o test_results_merged/report_merged.html
cp -R tmp_html/assets test_results_merged
- name: Upload Merged Results Folder
id: upload-artifact-results
uses: actions/upload-artifact@v4
with:
retention-days: 15
name: test_results
path: test_results_merged
# Workaround until they support multiple URLs deployments to github pages
- name: Upload HTML report as standard artifact
id: upload-artifact-html-report
uses: actions/upload-artifact@v4
with:
retention-days: 15
name: pytest_html_report
path: test_results_merged/report_merged.html
- name: Create folder to deploy to pages and fix permissions
if: ${{ !cancelled() && github.ref == 'refs/heads/master' }}
run: |
mkdir github-pages
cp test_results_merged/report_merged.html github-pages/index.html
echo
echo "Fix permissions (if necessary)..."
chmod -c -R +rX github-pages | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
- name: Upload HTML report as github pages artifact (will be deployed by next job)
if: ${{ !cancelled() && github.ref == 'refs/heads/master' }}
uses: actions/upload-pages-artifact@v3
with:
path: github-pages/
- name: Add info to markdown summary
env:
MARKER: ${{ inputs.marker }}
COMMIT_ID: ${{ inputs.commit_id }}
DEFAULT_ONLY: ${{ inputs.default_only }}
run: |
echo "## :loudspeaker: Pytest Run Information: :loudspeaker:" >> $GITHUB_STEP_SUMMARY
echo "### Test Results:" >> $GITHUB_STEP_SUMMARY
echo "The Pytest HTML report is only deployed on github pages for runs triggered from the master branch (for security reasons), \
and is only available for the latest CI run. This is due to current Github Actions limitations of not supporting \
different URLs for deployments. Nonetheless, reports are anyway available for download as artifacts for up to 15 days \
after the test run (see Artifacts section above)." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Quick links for downloading:**" >> $GITHUB_STEP_SUMMARY
echo "- Pytest HTML Report: ${{ steps.upload-artifact-html-report.outputs.artifact-url }}'" >> $GITHUB_STEP_SUMMARY
echo "- Complete Pytest Results (with fine-grained logs for all tests): \
${{ steps.upload-artifact-results.outputs.artifact-url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo
echo "### Input Arguments (use for manual workflow dispatch of the CI only):" >> $GITHUB_STEP_SUMMARY
echo "Marker provided: $MARKER" >> $GITHUB_STEP_SUMMARY
echo "Commit ID provided: $COMMIT_ID" >> $GITHUB_STEP_SUMMARY
echo "Default_only: $DEFAULT_ONLY" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo
# Step 5.6: Deploy HTML report with github pages
pytest-html-report-deploy:
if: ${{ !cancelled() && github.ref == 'refs/heads/master' }} # We can only deploy pages from master (security reasons)
needs: pytest-results
runs-on: ubuntu-22.04
permissions: # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
pages: write # --> to deploy to Pages
id-token: write # --> to verify the deployment originates from an appropriate source
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }} # The deployment URL cannot be changed (for now...)
steps:
- name: Deploy artifact to Github Pages
uses: actions/deploy-pages@v4
id: deployment