217 lines
5.5 KiB
YAML
217 lines
5.5 KiB
YAML
|
|
.integration_test:
|
|
|
|
stage: test
|
|
|
|
needs:
|
|
- "Build Collection"
|
|
|
|
image:
|
|
name: nofusscomputing/docker-buildx-qemu:dev
|
|
pull_policy: always
|
|
|
|
variables:
|
|
DOCKER_HOST: tcp://docker:2375/
|
|
DOCKER_DRIVER: overlay2
|
|
# GIT_STRATEGY: none
|
|
|
|
services:
|
|
- name: docker:23-dind
|
|
entrypoint: ["env", "-u", "DOCKER_HOST"]
|
|
command: ["dockerd-entrypoint.sh"]
|
|
before_script:
|
|
- | # start test container
|
|
docker run -d \
|
|
--privileged \
|
|
-v ${PWD}:/workdir \
|
|
-v ${PWD}/artifacts/galaxy:/collection \
|
|
--workdir /workdir \
|
|
--rm \
|
|
--env "ANSIBLE_FORCE_COLOR=true" \
|
|
--env "CI_COMMIT_SHA=${CI_COMMIT_SHA}" \
|
|
--env "ANSIBLE_LOG_PATH=/workdir/ansible.log" \
|
|
--env "PIP_BREAK_SYSTEM_PACKAGES=1" \
|
|
--name test_image_${CI_JOB_ID} \
|
|
nofusscomputing/ansible-docker-os:dev-${test_image}
|
|
|
|
- | # enter test container
|
|
docker exec -i test_image_${CI_JOB_ID} ps aux
|
|
- docker ps
|
|
- docker exec -i test_image_${CI_JOB_ID} apt update
|
|
- docker exec -i test_image_${CI_JOB_ID} apt install -y --no-install-recommends python3-pip net-tools dnsutils iptables
|
|
- |
|
|
if [ "${test_image}" == 'debian-12' ]; then
|
|
|
|
echo "Debian 12":
|
|
|
|
docker exec -i test_image_${CI_JOB_ID} pip install ansible-core --break-system-packages;
|
|
|
|
docker exec -i test_image_${CI_JOB_ID} mkdir -p /etc/iptables;
|
|
|
|
docker exec -i test_image_${CI_JOB_ID} touch /etc/iptables/rules.v6;
|
|
|
|
docker exec -i test_image_${CI_JOB_ID} update-alternatives --set iptables /usr/sbin/iptables-legacy;
|
|
|
|
else
|
|
|
|
echo " Not Debian 12":
|
|
|
|
docker exec -i test_image_${CI_JOB_ID} pip install ansible-core;
|
|
|
|
fi
|
|
|
|
- docker exec -i test_image_${CI_JOB_ID} cat /etc/hosts
|
|
- docker exec -i test_image_${CI_JOB_ID} cat /etc/resolv.conf
|
|
- | # check if DNS working
|
|
docker exec -i test_image_${CI_JOB_ID} nslookup google.com
|
|
script:
|
|
- | # inside container?
|
|
docker exec -i test_image_${CI_JOB_ID} ls -l /collection;
|
|
docker exec -i test_image_${CI_JOB_ID} echo $PWD;
|
|
|
|
- | # Show Network Interfaces
|
|
docker exec -i test_image_${CI_JOB_ID} ifconfig;
|
|
|
|
- | # Install the collection
|
|
docker exec -i test_image_${CI_JOB_ID} bash -c 'ansible-galaxy collection install $(ls /collection/*.tar.gz)'
|
|
|
|
- | # output ansible vars
|
|
docker exec -i test_image_${CI_JOB_ID} ansible -m setup localhost
|
|
|
|
- | # run the collection
|
|
docker exec -i test_image_${CI_JOB_ID} \
|
|
${test_command} \
|
|
--extra-vars "nfc_role_firewall_policy_input=ACCEPT" \
|
|
--extra-vars "nfc_role_firewall_policy_forward=ACCEPT" \
|
|
-vv
|
|
|
|
- | # Create test.yaml
|
|
mkdir -p test_results;
|
|
cat <<EOF > test_results/${test_image}.json
|
|
{
|
|
"$( echo ${test_image} | sed -e 's/\./_/')": "Pass"
|
|
}
|
|
|
|
EOF
|
|
|
|
after_script:
|
|
- | # Create test.yaml if not exists
|
|
if [ ! -f test_results/${test_image}.json ]; then
|
|
|
|
echo "[TRACE] Test has failed"
|
|
|
|
mkdir -p test_results;
|
|
|
|
cat <<EOF > test_results/${test_image}.json
|
|
{
|
|
"$( echo ${test_image} | sed -e 's/\./_/')": "Fail"
|
|
}
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
- | # Run trace script for debugging
|
|
chmod +x ./.gitlab/integration_test_trace.sh;
|
|
|
|
./.gitlab/integration_test_trace.sh;
|
|
|
|
artifacts:
|
|
untracked: false
|
|
paths:
|
|
- ansible.log
|
|
- test_results/*
|
|
when: always
|
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_TAG
|
|
allow_failure: true
|
|
when: on_success
|
|
|
|
# Needs to run, even by bot as the test results need to be available
|
|
# - if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
|
|
# when: never
|
|
|
|
- if: # Occur on merge
|
|
$CI_COMMIT_BRANCH
|
|
&&
|
|
$CI_PIPELINE_SOURCE == "push"
|
|
allow_failure: true
|
|
when: on_success
|
|
|
|
# - if:
|
|
# $CI_COMMIT_BRANCH != "development"
|
|
# &&
|
|
# $CI_COMMIT_BRANCH != "master"
|
|
# &&
|
|
# $CI_PIPELINE_SOURCE == "push"
|
|
# allow_failure: true
|
|
# when: always
|
|
|
|
- when: never
|
|
|
|
|
|
|
|
Playbook - Install:
|
|
extends: .integration_test
|
|
parallel:
|
|
matrix:
|
|
- test_image: debian-11
|
|
test_command: ansible-playbook nofusscomputing.kubernetes.install
|
|
- test_image: debian-12
|
|
test_command: ansible-playbook nofusscomputing.kubernetes.install
|
|
- test_image: ubuntu-20.04
|
|
test_command: ansible-playbook nofusscomputing.kubernetes.install
|
|
- test_image: ubuntu-22.04
|
|
test_command: ansible-playbook nofusscomputing.kubernetes.install
|
|
|
|
|
|
|
|
test_results:
|
|
stage: test
|
|
|
|
extends: .ansible_playbook
|
|
|
|
variables:
|
|
ansible_playbook: .gitlab/test_results.yaml
|
|
ANSIBLE_PLAYBOOK_DIR: $CI_PROJECT_DIR
|
|
|
|
needs:
|
|
- Playbook - Install
|
|
|
|
artifacts:
|
|
untracked: false
|
|
when: always
|
|
access: all
|
|
expire_in: "3 days"
|
|
paths:
|
|
- test_results.json
|
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_TAG
|
|
allow_failure: true
|
|
when: on_success
|
|
|
|
# Needs to run, even by bot as the test results need to be available
|
|
# - if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
|
|
# when: never
|
|
|
|
- if: # Occur on merge
|
|
$CI_COMMIT_BRANCH
|
|
&&
|
|
$CI_PIPELINE_SOURCE == "push"
|
|
allow_failure: true
|
|
when: on_success
|
|
|
|
# - if:
|
|
# $CI_COMMIT_BRANCH != "development"
|
|
# &&
|
|
# $CI_COMMIT_BRANCH != "master"
|
|
# &&
|
|
# $CI_PIPELINE_SOURCE == "push"
|
|
# allow_failure: true
|
|
# when: always
|
|
|
|
- when: never |