This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
smoke_tests #144
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################### | |
# Automated Testing Framework for Network Analytics | |
# Github Action Workflow for Setting up the Framework | |
# and running test cases (smoke tests) | |
# [email protected] 22/02/2024 | |
################################################### | |
name: smoke_tests | |
on: | |
workflow_dispatch: | |
push: | |
pull_request: | |
schedule: | |
- cron: '0 2 * * *' # every day at 2am | |
jobs: | |
### Build Traffic Reproducer Images | |
traf-repro-docker: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout Framework | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct-test-automation | |
submodules: recursive | |
- name: Create Traffic Reproducer Docker Images | |
run: | | |
sudo apt update | |
sudo apt install docker | |
cd pmacct-test-automation | |
tools/pcap_player/build_docker_image.sh | |
- name: Check Images and Save as Artifacts | |
run: | | |
echo "Checking Images..." | |
docker images | grep 'traffic' | |
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 | |
### Retrieve all other necessary images from Docker Hub and store as artifacts | |
### (to avoid possible Docker Hub pull limits) | |
hub-pulled-docker: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout Framework | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct-test-automation | |
submodules: recursive | |
- name: Download kafka and redis images | |
run: | | |
source pmacct-test-automation/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' | |
- name: Download pmacct images and adjust tag to _build # TODO: later on bind to 1.7.8 version instead of bleeding edge... | |
run: | | |
source pmacct-test-automation/settings.conf | |
docker pull pmacct/nfacctd:bleeding-edge | |
docker pull pmacct/pmbmpd:bleeding-edge | |
docker pull pmacct/pmbgpd:bleeding-edge | |
docker image tag pmacct/nfacctd:bleeding-edge $PMACCT_NFACCTD_IMG | |
docker image tag pmacct/pmbmpd:bleeding-edge $PMACCT_PMBMPD_IMG | |
docker image tag pmacct/pmbgpd:bleeding-edge $PMACCT_PMBGPD_IMG | |
echo "List Images" | |
docker images | grep 'nfacctd\|pmbmpd\|pmbgpd' | |
- name: Prepare Artifacts | |
run: | | |
echo "Saving images as artifacts..." | |
source pmacct-test-automation/settings.conf | |
mkdir -p /tmp/docker/ | |
docker save -o /tmp/docker/hub_pulled_docker_images.tar $ZOOKEEPER_IMG $KAFKA_IMG $SCHEMAREGISTRY_IMG $REDIS_IMG \ | |
$PMACCT_NFACCTD_IMG $PMACCT_PMBMPD_IMG $PMACCT_PMBGPD_IMG | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
retention-days: 1 | |
name: hub_pulled_docker_images | |
path: /tmp/docker | |
### Collect tests from framework (TODO: --> change to collect smoke_tests when ready ) | |
collect-tests: | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout Framework | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct-test-automation | |
submodules: recursive | |
- name: Collect list of tests from tests/ folder | |
id: set-matrix | |
run: | | |
cd pmacct-test-automation/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 | |
### Setup Framework and Run Tests | |
pytest-runtests: | |
needs: [collect-tests, traf-repro-docker, hub-pulled-docker] | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
#matrix: ${{ fromJson(needs.collect-tests.outputs.matrix) }} | |
matrix: | |
test: [100, 200, 300] | |
steps: | |
- name: Checkout Framework | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct-test-automation | |
submodules: recursive | |
- 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-automation/requirements.txt | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: '*_docker_images' | |
path: /tmp/docker | |
- name: Import images in the local registry | |
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) | |
run: | | |
cd pmacct-test-automation | |
sudo env PATH="$PATH" ./runtest.sh ${{ matrix.test }} | |
- name: Prepare Results Folder for Upload (permissions and folder name) | |
if: ${{ !cancelled() }} # always run this step, unless job manually cancelled | |
run: | | |
cd pmacct-test-automation | |
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() }} # always run this step, unless job manually cancelled | |
uses: actions/upload-artifact@v4 | |
with: | |
retention-days: 7 | |
name: "test_results_${{ env.TEST_FOLDER_NAME }}" | |
path: pmacct-test-automation/results | |
# Expose Results as Artifacts | |
pytest-results: | |
if: '!cancelled()' # always run this job, unless job manually cancelled | |
needs: pytest-runtests | |
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 | |
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 | |
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 | |
# 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 |