Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Extend the UC testing workflow to add config provider snap #178

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions test/suites/ubuntu-core-edgex-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,47 @@ Once you see the SSH command and the IP address, open a new terminal to test the

```
$ USER=<your-username> ./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=<your-username>
+ SSH_PORT=8022
+ remote_call 'snap install curl'
+ ssh <your-username>@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 <your-username>@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 <your-username>@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 <your-username>@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 <your-username>@localhost -p 8022 'snap get edgexfoundry security-secret-store -d'
{
"security-secret-store": "off"
}
+ remote_call 'snap services edgex-device-virtual'
+ ssh <your-username>@localhost -p 8022 'snap services edgex-device-virtual'
Service Startup Current Notes
edgex-device-virtual.device-virtual enabled active -
+ remote_call 'snap list'
+ ssh <your-username>@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 <your-username>@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 <your-username>@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!"
```
47 changes: 35 additions & 12 deletions test/suites/ubuntu-core-edgex-image/build.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
#!/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"
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
},
"AmKuVTOfsN0uEKsyJG34M8CaMfnIqxc0": {
"autostart": true,
"app-options": true,
"apps": {
"device-virtual": {
"config": {
"service-startupmsg": "Startup message from gadget!",
"edgex-security-secret-store": false
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}' 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)
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
29 changes: 29 additions & 0 deletions test/suites/ubuntu-core-edgex-image/kernel-options/cmdline.full
Original file line number Diff line number Diff line change
@@ -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
[email protected]

# 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

4 changes: 4 additions & 0 deletions test/suites/ubuntu-core-edgex-image/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/suites/ubuntu-core-edgex-image/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


36 changes: 24 additions & 12 deletions test/suites/ubuntu-core-edgex-image/test.sh
Original file line number Diff line number Diff line change
@@ -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