From f4ac7759e1e21a833ca80b5bbb8986ce295ac5a2 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Tue, 4 Apr 2023 14:11:36 +0200 Subject: [PATCH] Extend the UC testing workflow to add config provider snap (#178) * Extend the UC testing workflow to add config provider snap Extend the UC testing workflow to add config provider snap * Update the format - disable the security feature of edgexfoundry in V2 format - directly modify the 'mmodel.yaml' file - update the format in the 'test.sh' script * Remove echo newlines * Simplfy scripts, update default channel * Update test.sh and output in readme * [skip ci] Enable debugging, add style flag to yq --- test/suites/ubuntu-core-edgex-image/README.md | 52 +++++++++++++++---- test/suites/ubuntu-core-edgex-image/build.sh | 47 ++++++++++++----- .../kernel-options/cmdline.full | 29 +++++++++++ .../suites/ubuntu-core-edgex-image/model.yaml | 4 ++ test/suites/ubuntu-core-edgex-image/run.sh | 2 +- test/suites/ubuntu-core-edgex-image/test.sh | 36 ++++++++----- 6 files changed, 135 insertions(+), 35 deletions(-) create mode 100755 test/suites/ubuntu-core-edgex-image/kernel-options/cmdline.full diff --git a/test/suites/ubuntu-core-edgex-image/README.md b/test/suites/ubuntu-core-edgex-image/README.md index 9515f73c..4de86756 100644 --- a/test/suites/ubuntu-core-edgex-image/README.md +++ b/test/suites/ubuntu-core-edgex-image/README.md @@ -49,15 +49,47 @@ Once you see the SSH command and the IP address, open a new terminal to test the ``` $ USER= ./test.sh -# {"apiVersion":"v2","timestamp":"Wed Mar 22 18:05:07 UTC 2023","serviceName":"core-data"} -# {"apiVersion":"v2","timestamp":"Wed Mar 22 18:05:07 UTC 2023","serviceName":"core-metadata"} -# {"apiVersion":"v2","timestamp":"Wed Mar 22 18:05:07 UTC 2023","serviceName":"core-command"} -# { -# "security": false -# } ++ SSH_USER= ++ SSH_PORT=8022 ++ remote_call 'snap install curl' ++ ssh @localhost -p 8022 'snap install curl' +curl 8.0.1 from Wouter van Bommel (woutervb) installed ++ ports=(59880 59881 59882) ++ for port in "${ports[@]}" ++ remote_call 'curl -s http://localhost:59880/api/v2/ping' ++ ssh @localhost -p 8022 'curl -s http://localhost:59880/api/v2/ping' +{"apiVersion":"v2","timestamp":"Tue Apr 4 07:33:14 UTC 2023","serviceName":"core-data"}+ for port in "${ports[@]}" ++ remote_call 'curl -s http://localhost:59881/api/v2/ping' ++ ssh @localhost -p 8022 'curl -s http://localhost:59881/api/v2/ping' +{"apiVersion":"v2","timestamp":"Tue Apr 4 07:33:14 UTC 2023","serviceName":"core-metadata"}+ for port in "${ports[@]}" ++ remote_call 'curl -s http://localhost:59882/api/v2/ping' ++ ssh @localhost -p 8022 'curl -s http://localhost:59882/api/v2/ping' +{"apiVersion":"v2","timestamp":"Tue Apr 4 07:33:14 UTC 2023","serviceName":"core-command"}+ remote_call 'snap get edgexfoundry security-secret-store -d' ++ ssh @localhost -p 8022 'snap get edgexfoundry security-secret-store -d' +{ + "security-secret-store": "off" +} ++ remote_call 'snap services edgex-device-virtual' ++ ssh @localhost -p 8022 'snap services edgex-device-virtual' +Service Startup Current Notes +edgex-device-virtual.device-virtual enabled active - ++ remote_call 'snap list' ++ ssh @localhost -p 8022 'snap list' +Name Version Rev Tracking Publisher Notes +core20 20230308 1852 latest/stable canonical** base +core22 20230316 583 latest/stable canonical** base +curl 8.0.1 1579 latest/stable woutervb - +edgex-config-provider-example 2.3 6 latest/stable farshidtz - +edgex-device-virtual 2.3.0 335 latest/stable canonical** - +edgexfoundry 2.3.0+1 4108 latest/stable canonical** - +pc 22-0.3 x1 - - gadget +pc-kernel 5.15.0-69.76.1 1258 22/stable canonical** kernel +snapd 2.58.3 18596 latest/stable canonical** snapd ++ remote_call 'curl --silent http://localhost:59881/api/v2/deviceprofile/all' ++ ssh @localhost -p 8022 'curl --silent http://localhost:59881/api/v2/deviceprofile/all' ++ jq .totalCount +0 ++ remote_call 'snap logs -n=all edgex-device-virtual | grep "CONFIG BY EXAMPLE PROVIDER"' ++ ssh @localhost -p 8022 'snap logs -n=all edgex-device-virtual | grep "CONFIG BY EXAMPLE PROVIDER"' -# Service Startup Current Notes -# edgex-device-virtual.device-virtual enabled active - - -# 2023-03-22T17:51:27Z edgex-device-virtual.device-virtual[3874]: level=INFO ts=2023-03-22T17:51:27.022824501Z app=device-virtual source=variables.go:377 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=Startup message from gadget!" ``` diff --git a/test/suites/ubuntu-core-edgex-image/build.sh b/test/suites/ubuntu-core-edgex-image/build.sh index da6c0e04..e051d120 100755 --- a/test/suites/ubuntu-core-edgex-image/build.sh +++ b/test/suites/ubuntu-core-edgex-image/build.sh @@ -1,38 +1,61 @@ #!/bin/bash -ex +# Remove the pc-gadget directory if it already exists rm -rf pc-gadget git clone https://github.com/snapcore/pc-gadget.git --branch=22 -# build gadget snap +# Build gadget snap cd pc-gadget -# extend the size of disk partitions to have sufficient capacity for EdgeX snaps -yq e '(.volumes.pc.structure[] | select(.name=="ubuntu-seed") | .size)="1500M"' gadget.yaml -i -# setup default options for snaps +# Extend the size of disk partitions to have sufficient capacity for EdgeX snaps +yq e -i '(.volumes.pc.structure[] | select(.name=="ubuntu-seed") | .size)="1500M"' gadget.yaml + +# Set up default options for snaps # AZGf0KNnh8aqdkbGATNuRuxnt1GNRKkV (edgexfoundry snap) # AmKuVTOfsN0uEKsyJG34M8CaMfnIqxc0 (edgex-device-virtual snap) -yq e '.defaults += { +yq e -i '.defaults += { "AZGf0KNnh8aqdkbGATNuRuxnt1GNRKkV": { "app-options": true, - "security": false + "security-secret-store": "off" }, "AmKuVTOfsN0uEKsyJG34M8CaMfnIqxc0": { "autostart": true, - "app-options": true, "apps": { "device-virtual": { "config": { - "service-startupmsg": "Startup message from gadget!", "edgex-security-secret-store": false } } } } -}' gadget.yaml -i +} | .defaults.AZGf0KNnh8aqdkbGATNuRuxnt1GNRKkV.security-secret-store style="double"' gadget.yaml + + +# Connect edgex-device-virtual's plug (consumer) to +# edgex-config-provider-example's slot (provider) +# to override the default configuration files. +yq e -i '.connections += [ + { + "plug": "AmKuVTOfsN0uEKsyJG34M8CaMfnIqxc0:device-virtual-config", + "slot": "WWPGZGi1bImphPwrRfw46aP7YMyZYl6w:device-virtual-config" + } + ] + ' gadget.yaml +# Add kernel options for extended logging and a debugging shell +cp -r ../kernel-options/ . +yq e -i '.parts += { + "kernel-options": + { + "source": "kernel-options/", + "plugin": "dump" + } + }' snapcraft.yaml + +# Build gadget snap snapcraft -# configure model assertion +# Configure model assertion cd ../ DEVELOPER_ID=$(snapcraft whoami | grep 'id:' | awk '{print $2}') TIMESTAMP=$(date -Iseconds --utc) @@ -40,8 +63,8 @@ yq e -i ".authority-id = \"$DEVELOPER_ID\"" model.yaml yq e -i ".brand-id = \"$DEVELOPER_ID\"" model.yaml yq e -i ".timestamp = \"$TIMESTAMP\"" model.yaml -# sign the model assertion +# Sign the model assertion yq eval model.yaml -o=json | snap sign -k $KEY_NAME > model.signed.yaml -# check the signed model +# Check the signed model cat model.signed.yaml diff --git a/test/suites/ubuntu-core-edgex-image/kernel-options/cmdline.full b/test/suites/ubuntu-core-edgex-image/kernel-options/cmdline.full new file mode 100755 index 00000000..93ebee7d --- /dev/null +++ b/test/suites/ubuntu-core-edgex-image/kernel-options/cmdline.full @@ -0,0 +1,29 @@ +# this is the first serial console, pick a suitable one for your device +console=ttyS0 + +# set to get more output from snapd +#snapd.debug=1 + +# these will output more device status/logging to our console, +# which is kinda annoying in that it goes to the same place we +# have our shell, but I think it's more useful to be able to see +# than have a perfectly pristine console, if you have multiple +# consoles you could of course use a different console for +# systemd output and your debug shell +rd.systemd.journald.forward_to_console=1 +systemd.journald.forward_to_console=1 + +# to disable console-conf from running on ttyS0 so we can setup +# our debug shell there, this is the most key part here, without +# this console-conf will kill/prevent from starting our debug shell +systemd.mask=serial-getty@ttyS0.service + +# create our debug shell on ttyS0 +systemd.debug-shell=ttyS0 + +# needed in order to allow the debug-shell to run on UC20 +dangerous + +# standard Ubuntu Core kernel command line parameters +panic=-1 + diff --git a/test/suites/ubuntu-core-edgex-image/model.yaml b/test/suites/ubuntu-core-edgex-image/model.yaml index 222f0cce..0d69372c 100644 --- a/test/suites/ubuntu-core-edgex-image/model.yaml +++ b/test/suites/ubuntu-core-edgex-image/model.yaml @@ -41,3 +41,7 @@ snaps: type: app default-channel: latest/stable id: AmKuVTOfsN0uEKsyJG34M8CaMfnIqxc0 + - name: edgex-config-provider-example + type: app + default-channel: latest/stable + id: WWPGZGi1bImphPwrRfw46aP7YMyZYl6w diff --git a/test/suites/ubuntu-core-edgex-image/run.sh b/test/suites/ubuntu-core-edgex-image/run.sh index 1b114d0b..50e71da0 100755 --- a/test/suites/ubuntu-core-edgex-image/run.sh +++ b/test/suites/ubuntu-core-edgex-image/run.sh @@ -17,6 +17,6 @@ sudo qemu-system-x86_64 \ -machine accel=kvm \ -serial mon:stdio \ -net nic,model=virtio \ - -net user,hostfwd=tcp::8022-:22,hostfwd=tcp::59880-:59880,hostfwd=tcp::8443-:8443 + -net user,hostfwd=tcp::8022-:22 diff --git a/test/suites/ubuntu-core-edgex-image/test.sh b/test/suites/ubuntu-core-edgex-image/test.sh index 66911d30..1ac430b1 100755 --- a/test/suites/ubuntu-core-edgex-image/test.sh +++ b/test/suites/ubuntu-core-edgex-image/test.sh @@ -1,23 +1,35 @@ -#!/bin/bash -e +#!/bin/bash -ex -ssh "$USER@localhost" -p 8022 "snap install curl" +SSH_USER="$USER" +SSH_PORT="8022" +remote_call() { + ssh "$SSH_USER@localhost" -p $SSH_PORT "$@" +} -# check status of core services inside of the emulator + +# Install curl on emulator +remote_call "snap install curl" + +# Check status of core services inside of the emulator ports=(59880 59881 59882) for port in "${ports[@]}" do - ssh "$USER@localhost" -p 8022 "curl -s http://localhost:$port/api/v2/ping; printf '\n'" + remote_call "curl -s http://localhost:$port/api/v2/ping" done -# verify that the security is avaliable as a snap option of edgexfoundry within the emulator -ssh "$USER@localhost" -p 8022 "snap get edgexfoundry security -d; printf '\n'" +# Verify that the security is avaliable as a snap option of edgexfoundry within the emulator +remote_call "snap get edgexfoundry security-secret-store -d" + +# Check the status of the device-virtual service within the emulator +remote_call "snap services edgex-device-virtual" + +# List snaps and check edgex-config-provider-example is in the list +remote_call 'snap list' -# check the status of the device-virtual service within the emulator -ssh "$USER@localhost" -p 8022 "snap services edgex-device-virtual; printf '\n'" +# Verify that Device Virtual only has one profile, as configured in the config provider +remote_call 'curl --silent http://localhost:59881/api/v2/deviceprofile/all' | jq '.totalCount' -# verify that device-virtual has the startup message set from the gadget within the emulator -ssh "$USER@localhost" -p 8022 'snap logs -n=all edgex-device-virtual | grep "Startup message"; printf '\n'' +# Verify that Device Virtual has the startup message set from the provider +remote_call 'snap logs -n=all edgex-device-virtual | grep "CONFIG BY EXAMPLE PROVIDER"' -# access the service endpoints via API Gateway outside of the emulator -curl --insecure --show-err https://localhost:8443/core-data/api/v2/ping