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 3 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
47 changes: 38 additions & 9 deletions test/suites/ubuntu-core-edgex-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,44 @@ 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
# }
# Install curl on host:
curl 8.0.1 from Wouter van Bommel (woutervb) installed

# Service Startup Current Notes
# edgex-device-virtual.device-virtual enabled active -
# Check status of core services inside of the emulator:
{"apiVersion":"v2","timestamp":"Thu Mar 30 13:36:10 UTC 2023","serviceName":"core-data"}
{"apiVersion":"v2","timestamp":"Thu Mar 30 13:36:10 UTC 2023","serviceName":"core-metadata"}
{"apiVersion":"v2","timestamp":"Thu Mar 30 13:36:10 UTC 2023","serviceName":"core-command"}

# 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!"
# Verify that the security is avaliable as a snap option of edgexfoundry within the emulator:
{
"security": false
}

# Check the status of the device-virtual service within the emulator:
Service Startup Current Notes
edgex-device-virtual.device-virtual enabled active -

# Access the service endpoints via API Gateway outside of the emulator:
{"message":"Unauthorized"}

# List snaps and check edgex-config-provider-example is in the 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/edge 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

# Verify that Device Virtual only has one profile, as configured in the config provider:
1

# Verify that Device Virtual has the startup message set from the provider:
2023-03-30T12:47:58Z edgex-device-virtual.device-virtual[3965]: level=INFO ts=2023-03-30T12:47:58.514769034Z app=device-virtual source=message.go:55 msg="CONFIG BY EXAMPLE PROVIDER"

# Query the metadata of Device Virtual from your host machine:
{"message":"Unauthorized"}
```
35 changes: 23 additions & 12 deletions test/suites/ubuntu-core-edgex-image/build.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
#!/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
}' 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

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
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/edge
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
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,hostfwd=tcp::8443-:8443


36 changes: 25 additions & 11 deletions test/suites/ubuntu-core-edgex-image/test.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
#!/bin/bash -e
#!/bin/bash -ex

ssh "$USER@localhost" -p 8022 "snap install curl"
SSH_USER="$USER"
SSH_PORT="8022"

# check status of core services inside of the emulator
# Install curl on host
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'"
ssh "$SSH_USER@localhost" -p $SSH_PORT "curl -s http://localhost:$port/api/v2/ping"
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
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
ssh "$SSH_USER@localhost" -p $SSH_PORT "snap get edgexfoundry security -d"

# check the status of the device-virtual service within the emulator
ssh "$USER@localhost" -p 8022 "snap services edgex-device-virtual; printf '\n'"
# Check the status of the device-virtual service within the emulator
ssh "$SSH_USER@localhost" -p $SSH_PORT "snap services edgex-device-virtual"

# 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''

# access the service endpoints via API Gateway outside of the emulator
# Access the service endpoints via API Gateway outside of the emulator
curl --insecure --show-err https://localhost:8443/core-data/api/v2/ping

# List snaps and check edgex-config-provider-example is in the list
ssh "$SSH_USER@localhost" -p $SSH_PORT 'snap list'

# Verify that Device Virtual only has one profile, as configured in the config provider
ssh "$SSH_USER@localhost" -p $SSH_PORT 'curl --silent http://localhost:59881/api/v2/deviceprofile/all' | jq '.totalCount'

# Verify that Device Virtual has the startup message set from the provider
ssh "$SSH_USER@localhost" -p $SSH_PORT 'snap logs -n=all edgex-device-virtual | grep "CONFIG BY EXAMPLE PROVIDER"'

# Query the metadata of Device Virtual from your host machine
curl --insecure --silent --show-err https://localhost:8443/core-data/api/v2/reading/all
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved