Skip to content

Commit

Permalink
Adding docker-based integration test (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored Jul 29, 2024
1 parent 7534bea commit 6a57bb4
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 158 deletions.
153 changes: 153 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: UDMI Integration Suite

on:
push:
tags:
- '**'
workflow_dispatch:

concurrency:
group: it-${{ github.repository }}
cancel-in-progress: true

jobs:
images:
name: Build Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
container: [ "udmis", "validator", "pubber" ]
env:
PUSH_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CONTAINER: ${{ matrix.container }}
REF_NAME: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Log in to the github registry
uses: docker/login-action@v3
with:
registry: ${{ env.PUSH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Container build and push
run: |
revhash=$(git log -n 1 --pretty=format:"%h")
IMAGE_HASH=g${revhash:0:8}
PUSH_REPO=$PUSH_REGISTRY/${IMAGE_NAME,,}
TAG_BASE=$PUSH_REPO:$CONTAINER
PUSH_TAG=${TAG_BASE}-$IMAGE_HASH
echo PUSH_TAG=$PUSH_TAG >> $GITHUB_ENV
bin/clone_model
$CONTAINER/bin/build check
bin/container $CONTAINER push --no-check $PUSH_TAG
docker tag $CONTAINER:latest $TAG_BASE-latest
docker push $TAG_BASE-latest
docker tag $CONTAINER:latest $TAG_BASE-$REF_NAME
docker push $TAG_BASE-$REF_NAME
echo Pushed built $CONTAINER container as $PUSH_TAG | tee -a $GITHUB_STEP_SUMMARY
- name: Docker images summary
run: |
docker images
echo
docker history $PUSH_TAG
simple:
name: Simple sequence test
runs-on: ubuntu-latest
timeout-minutes: 5
needs: images
env:
IMAGE_NAME: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
steps:
- name: Setup Environment
run: |
git clone https://github.com/faucetsdn/udmi_site_model.git
ln -s udmi_site_model/ site_model
docker network create udminet --subnet 192.168.99.0/24
- name: Start UDMIS container
run: |
cat udmi_site_model/cloud_iot_config.json
docker run -d --net udminet --name udmis -p 8883:8883 \
-v $(realpath site_model):/root/site_model \
-v $PWD/var/tmp:/tmp \
-v $PWD/var/etcd:/root/udmi/var/etcd \
-v $PWD/var/mosquitto:/etc/mosquitto \
ghcr.io/$IMAGE_NAME:udmis-$REF_NAME udmi/bin/start_local block site_model/cloud_iot_config.json
for count in `seq 0 30`; do
echo Waiting for UDMIS startup $((30 - count))
[[ ! -f var/tmp/pod_ready.txt ]] || break
(docker ps | fgrep -q udmis) || break
sleep 1
done
ls -l var/tmp/pod_ready.txt 2>&1
- name: Registrar run
run: |
docker run --net udminet --name registrar -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:validator-$REF_NAME bin/registrar site_model/cloud_iot_config.json
- name: Pubber background run
run: |
echo docker run -d --net udminet --name pubber -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:pubber-$REF_NAME bin/pubber site_model/cloud_iot_config.json
docker run -d --net udminet --name pubber -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:pubber-$REF_NAME bin/pubber site_model/cloud_iot_config.json
for count in `seq 0 30`; do
(docker ps | fgrep -q pubber) || break
(docker logs pubber 2>&1 | fgrep -q -v "Connection complete") || break
echo Waiting for pubber startup $((30 - count))...
sleep 1
done
docker logs pubber 2>&1 | fgrep "Connection complete"
- name: Sequencer run
run: |
docker run --net udminet --name sequencer -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:validator-$REF_NAME bin/sequencer site_model/cloud_iot_config.json \
broken_config extra_config device_config_acked
- name: Sequencer results
run: |
cat site_model/out/devices/AHU-1/results.md
[[ $(cat site_model/out/devices/AHU-1/results.md | fgrep 'stable | pass' | wc -l) == 3 ]]
- name: UDMIS logs
if: ${{ !cancelled() }}
run: docker logs udmis
- name: Registrar logs
if: ${{ !cancelled() }}
run: docker logs registrar
- name: Pubber logs
if: ${{ !cancelled() }}
run: docker logs pubber
- name: Sequencer logs
if: ${{ !cancelled() }}
run: docker logs sequencer

udmif:
name: UDMIF unit tests
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.9.0
- name: Install Angular CLI
run: npm install -g @angular/cli
- name: web tests
run: echo Disabled udmif/web/runTests due to dependency integration problems
- name: api tests
run: echo Disabled udmif/api/runTests due to dependency integration problems
83 changes: 4 additions & 79 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: UDMI test suite
name: UDMI Test Suite

on:
push:
branches:
- '**'
workflow_dispatch:
pull_request:
schedule:
Expand Down Expand Up @@ -61,85 +63,9 @@ jobs:
config_path: .spellcheck.yml
task_name: Markdown

udmif:
name: UDMIF unit tests
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.9.0
- name: Install Angular CLI
run: npm install -g @angular/cli
- name: web tests
run: echo Disabled udmif/web/runTests due to dependency integration problems
- name: api tests
run: echo Disabled udmif/api/runTests due to dependency integration problems

pretest:
name: Pre-test Setup
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 5
if: vars.TARGET_PROJECT != ''
env:
PUSH_REGISTRY: ghcr.io
TARGET_PROJECT: ${{ vars.TARGET_PROJECT }}
UDMI_ALT_REGISTRY: ZZ-REDIRECT-NA
UDMI_UPDATE_UDMIS: ${{ vars.UDMI_UPDATE_UDMIS }}
IMAGE_NAME: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: sanity check
run: |
[[ -n $UDMI_ALT_REGISTRY ]]
[[ -n $TARGET_PROJECT ]]
- name: Log in to the github registry
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
registry: ${{ env.PUSH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup udmis container build
if: ${{ github.event_name == 'push' }}
run: |
revhash=$(git log -n 1 --pretty=format:"%h" udmis)
IMAGE_TAG=U${revhash:0:9}
PUSH_REPO=$PUSH_REGISTRY/${IMAGE_NAME,,}
PUSH_TAG=$PUSH_REPO:udmis-$IMAGE_TAG
echo PUSH_TAG=$PUSH_TAG >> $GITHUB_ENV
bin/container udmis prep --no-check $PUSH_TAG
echo Pushing built container as $PUSH_TAG | tee -a $GITHUB_STEP_SUMMARY
- name: Build and push docker image
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v5
with:
file: udmis/Dockerfile.udmis
context: udmis
push: true
tags: ${{ env.PUSH_TAG }}
- name: Update udmis deployment
if: ${{ env.UDMI_UPDATE_UDMIS != '' }}
run: |
bin/clone_model
bin/update_udmis sites/udmi_site_model/ $TARGET_PROJECT $PUSH_TAG
sequencer:
name: Sequencer Tests
runs-on: ubuntu-latest
needs: pretest
timeout-minutes: 20
strategy:
fail-fast: false
Expand Down Expand Up @@ -203,7 +129,6 @@ jobs:
baseline:
name: Baseline Tests
runs-on: ubuntu-latest
needs: pretest
timeout-minutes: 15
if: vars.TARGET_PROJECT != ''
env:
Expand Down Expand Up @@ -297,7 +222,7 @@ jobs:
redirect:
name: Endpoint Redirection
runs-on: ubuntu-latest
needs: [ pretest, baseline ]
needs: baseline
timeout-minutes: 15
if: vars.TARGET_PROJECT != ''
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
\#*

/udmi-support_*/
/site_model
udmi_site_model/
gcp_reflect_key.pkcs8
workspace.xml
Expand Down
4 changes: 3 additions & 1 deletion bin/container
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ fi

if [[ -n $push ]]; then
docker push $udmi_ref
hash=$(docker images --digests ${udmi_ref%:*} | fgrep $udmi_tag | awk '{print $3}')
docker images
docker images --digests ${udmi_ref%:*} || true
hash=$(docker images --digests ${udmi_ref%:*} | fgrep $udmi_tag | awk '{print $3}') || true
ihash=$udmi_ref@$hash
for file in $TEMPLATES; do
out_file=tmp/$file
Expand Down
25 changes: 19 additions & 6 deletions bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ trap cleanup EXIT

config_file=$(realpath $1)
serial_no=NA
cloud_region=us-central1
project_id=--
shift

Expand All @@ -42,12 +43,20 @@ elif [[ $(jq -r .device_id $config_file) == null ]]; then
fail Neither deviceId nor device_id defined in config file.
else
echo Constructing pubber configuration from site config.
cat $config_file
project_id=$(jq -r .project_id $config_file)
device_id=$(jq -r .device_id $config_file)
registry_id=$(jq -r .registry_id $config_file)
serial_no=$(jq -r .serial_no $config_file)
site_model=$(jq -r .site_model $config_file)
iot_provider=$(jq -r .iot_provider $config_file)
[[ $site_model != null ]] || site_model=$(dirname $config_file)
[[ $site_model = /* ]] || site_model=$(dirname $config_file)/$site_model
jq -r .device_endpoint $config_file > $ENDPOINT_TMP
device_endpoint=$(jq -r .device_endpoint $config_file)
[[ $device_endpoint == null ]] || (
echo Extracting configuration to $ENDPOINT_TMP
echo $device_endpoint > $ENDPOINT_TMP
)
fi

if [[ -n ${UDMI_REGISTRY_SUFFIX:-} ]]; then
Expand Down Expand Up @@ -102,15 +111,16 @@ elif [[ $project_id =~ @ ]]; then
iot_provider=jwt
broker_hostname=${project_id#*@}
project_target=${project_id%@*}
else
iot_provider=gcp
elif [[ -z $iot_provider ]]; then
false no iot_provider provided.
fi

[[ ${registry_id:-null} == null ]] && fail registry_id not defined
registry_actual=${udmi_prefix}${registry_id}${registry_suffix}
if [[ ! -f $ENDPOINT_TMP ]]; then
[[ ${registry_id:-null} == null ]] && fail registry_id not defined
registry_actual=${udmi_prefix}${registry_id}${registry_suffix}
client_id=\"projects/$project_target/locations/$cloud_region/registries/$registry_actual/devices/$device_id\"
fi

topic_prefix=null
auth_provider=null
transport=null
Expand All @@ -124,7 +134,7 @@ elif [[ $iot_provider == mqtt ]]; then
gateway_id=$(jq -r .gateway.gateway_id $site_model/devices/$device_id/metadata.json) || true
echo Attached to gateway $gateway_id
target_id=$device_id
[[ $gateway_id == null ]] || target_id=$gateway_id
[[ -z $gateway_id || $gateway_id == null ]] || target_id=$gateway_id
echo Target is $target_id
client_id=\"/r/$registry_actual/d/$target_id\"
key_file=$site_model/devices/$target_id/*_private.pkcs8
Expand All @@ -139,6 +149,7 @@ elif [[ -z $broker_hostname ]]; then
fi

if [[ ! -f $ENDPOINT_TMP ]]; then
echo Constructing new $ENDPOINT_TMP
cat <<EOF > $ENDPOINT_TMP
{
"protocol": "mqtt",
Expand Down Expand Up @@ -179,6 +190,8 @@ if [[ -f ${site_model:-}/reflector/ca.crt && -n ${project_target:-} ]]; then
ls -l ${site_model}/devices/${target_id}/*.crt
fi

cat $tmp_config

# Run in the background to force new process group and get PID
$UDMI_ROOT/pubber/bin/run $tmp_config &
PUB_PID=$!
Expand Down
3 changes: 2 additions & 1 deletion bin/sequencer
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ elif [[ -f $site_path ]]; then
device_id=`jq -r .device_id $site_path`
[[ $device_id == null ]] && fail Parameter device_id not defined in config file.
serial_no=`jq -r .serial_no $site_path`
[[ $serial_no == null ]] && serial_no=$DEFAULT_SERIAL
[[ $serial_no != null ]] || serial_no=$DEFAULT_SERIAL
iot_provider=`jq .iot_provider $site_path`
endpoint=`jq .reflector_endpoint $site_path`
alt_registry=`jq .alt_registry $site_path`
registry_suffix=`jq .registry_suffix $site_path`
Expand Down
4 changes: 2 additions & 2 deletions bin/setup_base
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ -n $(which apt-get) ]]; then
else
update_cmd="apk add"
# Some extra packages are necessary for alpine based docker builds.
extra_packages="linux-headers g++ gcc"
extra_packages="${NO_CACHE_DIR:+--no-cache} linux-headers g++ gcc"
fi

sudo $update_cmd $extra_packages moreutils expect python3-dev mosquitto mosquitto-clients
Expand All @@ -18,6 +18,6 @@ python3 --version
python3 -m venv venv

venv_pip3=$($(dirname $0)/which_venv_pip3)
${venv_pip3} install -r etc/requirements.txt
${venv_pip3} install ${NO_CACHE_DIR:+--no-cache-dir} -r etc/requirements.txt

java -version
Loading

0 comments on commit 6a57bb4

Please sign in to comment.