Skip to content

Commit

Permalink
[qa] Improved testing pipeline
Browse files Browse the repository at this point in the history
- Configured gitlab-ci.yml with terraform to run gitlab-pipeline with multiple runners on GCE
- Set "allow_failures" for testing releases debian10 and fedora28
  • Loading branch information
hispanico committed Sep 27, 2018
1 parent bebe1f2 commit de87021
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ target/

#Ipython Notebook
.ipynb_checkpoints

# Terraform
.terraform/*
creds/*
keys/*
126 changes: 113 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---

.script_template: &testing_script
.testing_script_template: &testing_script
stage: ansible
tags:
- docker-tester
- docker-ansible
before_script:
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token $CI_REGISTRY --password-stdin
script:
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gitlab.ninux.org/snippets/10/raw
- wget -O ${PWD}/tests/test.sh https://gitlab.com/snippets/1751673/raw
- chmod +x ${PWD}/tests/test.sh

# Run tests.
Expand All @@ -17,69 +20,166 @@
| sed -n '1p' | grep -q '200'
&& (echo 'Status code 200 test: pass' && exit 0)
|| (echo 'Status code 200 test: fail'; docker exec ${container_id} sh -c 'tail -n 500 /opt/openwisp2/log/*.log' && exit 1)
dependencies: []
after_script:
- docker rm -f $container_id

.terraform_setup_template: &terraform_setup
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- wget -O $CI_PROJECT_DIR/terraform.tf https://gitlab.com/snippets/1757951/raw
- rm -rf .terraform
- terraform --version
- mkdir -p ./creds
- echo $SERVICEACCOUNT | base64 -d > ./creds/serviceaccount.json
- terraform init

variables:
cleanup: 'false'
container_id: '$CI_JOB_NAME-$CI_PROJECT_NAME-Pipeline$CI_PIPELINE_ID-Job$CI_JOB_ID'

before_script:
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token $CI_REGISTRY --password-stdin
stages:
- validate
- plan
- apply
- ansible
- destroy

ansible-syntax:
stage: validate
tags:
- docker
image:
name: registry.gitlab.com/hispanico/docker-terraform-ansible:latest
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
script:
- ansible-galaxy install -r tests/requirements.yml
- ansible-playbook tests/test.yml --syntax-check
- ansible-playbook tests/test_networktopology.yml --syntax-check

ansible-lint:
stage: validate
tags:
- docker
image:
name: registry.gitlab.com/hispanico/docker-terraform-ansible:latest
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
script:
- ansible-galaxy install -r tests/requirements.yml
- ansible-lint tests/test.yml
- ansible-lint tests/test_networktopology.yml
allow_failure: true

terraform-validate:
stage: validate
tags:
- docker
<<: *terraform_setup
script:
- terraform validate

terraform-plan:
stage: plan
tags:
- docker
<<: *terraform_setup
script:
- terraform plan -out "planfile"
dependencies:
- terraform-validate
artifacts:
paths:
- planfile

terraform-apply:
stage: apply
tags:
- docker
<<: *terraform_setup
script:
- terraform apply -input=false "planfile"
dependencies:
- terraform-plan

Ubuntu1604:
variables:
distro: 'ubuntu:16.04'
playbook: test.yml

<<: *testing_script

Ubuntu1804:
variables:
distro: 'ubuntu:18.04'
playbook: test.yml

<<: *testing_script

Centos7:
variables:
distro: centos:7
playbook: test.yml

<<: *testing_script

Debian8:
variables:
distro: debian:8
playbook: test.yml

<<: *testing_script

Debian9:
variables:
distro: debian:9
playbook: test.yml

<<: *testing_script

Debian10:
variables:
distro: debian:10
playbook: test.yml

<<: *testing_script
allow_failure: true

Fedora27:
variables:
distro: fedora:27
playbook: test.yml
<<: *testing_script

Fedora28:
variables:
distro: fedora:28
playbook: test.yml
<<: *testing_script
allow_failure: true

Ubuntu1804_NetworkTopology:
variables:
distro: 'ubuntu:18.04'
playbook: test_networktopology.yml

<<: *testing_script

terraform-destroy_on_failure:
stage: destroy
tags:
- docker
<<: *terraform_setup
script:
- terraform destroy -auto-approve
dependencies: []
when: on_failure

terraform-destroy:
stage: destroy
tags:
- docker
<<: *terraform_setup
script:
- terraform destroy -auto-approve
dependencies: []
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
services: docker

env:
matrix:
- distro: centos:7
playbook: test.yml
- distro: 'ubuntu:16.04'
Expand All @@ -17,17 +18,23 @@ env:
playbook: test.yml
- distro: fedora:27
playbook: test.yml

- distro: fedora:28
playbook: test.yml
- distro: 'ubuntu:18.04'
playbook: test_networktopology.yml

matrix:
allow_failures:
- env: distro=debian:10 playbook=test.yml
- env: distro=fedora:28 playbook=test.yml

script:
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false

# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gitlab.ninux.org/snippets/10/raw
- wget -O ${PWD}/tests/test.sh https://gitlab.com/snippets/1751673/raw
- chmod +x ${PWD}/tests/test.sh

# Run tests.
Expand Down
2 changes: 1 addition & 1 deletion tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
state: absent

roles:
- role_under_test
- openwisp.openwisp2
2 changes: 1 addition & 1 deletion tests/test_networktopology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
state: absent

roles:
- role_under_test
- openwisp.openwisp2

0 comments on commit de87021

Please sign in to comment.