Skip to content

Commit 6e77fc0

Browse files
committed
test(snap): add spread integration tests
The integration test suite runs on typical Linux distribution images and ensures that openshell can create a sandbox and execute a hello-world program inside. Tests have two components: 1) The `image-garden` program uses built-in rules, as well as `.image-garden.mk` to prepare virtual machine images for testing. The virtual machines are vanilla cloud images booted once with a cloud-init profile that prepares them for testing. At runtime garden downloads images to ~/.cache/garden/dl or $SNAP_USER_COMMON/cache/dl (when using the snap) and then saves customized differential images in `.image-garden/` in the project directory. In practice the pre-created environment has snapd, the docker snap and the "ghcr.io/nvidia/openshell-community/sandboxes/base:latest" docker image pre-pulled for faster test iteration. 2) The `spread` program uses `spread.yaml` and a collection of `task.yaml` files to run tests. The top-level file defines the set of test systems, contains project wide preparation logic where we install the snap and defines a single test suite which corresponds to the `tests/` directory. An initial smoke test that creates a sandbox and ensures it can run a shell hello world is provided. This ensures that the locally built snap really works on the set of test environments: - centos-cloud-10 - debian-cloud-13 - fedora-cloud-44 - ubuntu-cloud-24.04 - ubuntu-cloud-26.04 Those tests are typically used with the `image-garden` snap, which also includes spread: https://snapcraft.io/image-garden/ Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
1 parent 0a8b35c commit 6e77fc0

5 files changed

Lines changed: 156 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,8 @@ rfc.md
219219
*.snap
220220
*.comp
221221

222+
# Spread reuse files
223+
.spread-reuse.*.yaml
224+
222225
# Markdown/mermaid lint tooling deps
223226
scripts/lint-mermaid/node_modules/

.image-garden.mk

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
default_sandbox_image=ghcr.io/nvidia/openshell-community/sandboxes/base:latest
5+
6+
define UBUNTU_CLOUD_INIT_USER_DATA_TEMPLATE
7+
$(CLOUD_INIT_USER_DATA_TEMPLATE)
8+
- snap wait system seed.loaded
9+
- snap install docker
10+
- snap run docker pull $(default_sandbox_image)
11+
endef
12+
13+
define DEBIAN_CLOUD_INIT_USER_DATA_TEMPLATE
14+
$(CLOUD_INIT_USER_DATA_TEMPLATE)
15+
- systemctl enable --now snapd.socket snapd.service snapd.apparmor.service
16+
- snap wait system seed.loaded
17+
- snap install docker
18+
- snap run docker pull $(default_sandbox_image)
19+
packages:
20+
- snapd
21+
endef
22+
23+
define FEDORA_CLOUD_INIT_USER_DATA_TEMPLATE
24+
$(CLOUD_INIT_USER_DATA_TEMPLATE)
25+
- dnf install -y snapd
26+
- systemctl enable --now snapd.socket
27+
- snap wait system seed.loaded
28+
- sudo ln -s /var/lib/snapd/snap /snap
29+
- snap install docker
30+
- snap run docker pull $(default_sandbox_image)
31+
endef
32+
33+
define CENTOS_CLOUD_INIT_USER_DATA_TEMPLATE
34+
$(CLOUD_INIT_USER_DATA_TEMPLATE)
35+
- yum install -y epel-release
36+
- yum install -y snapd
37+
- systemctl enable --now snapd.socket snapd.service
38+
- snap wait system seed.loaded
39+
- sudo ln -s /var/lib/snapd/snap /snap
40+
- snap install docker
41+
- snap run docker pull $(default_sandbox_image)
42+
endef

.image-garden/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
*.img
5+
*.iso
6+
*.lock
7+
*.log
8+
*.meta-data
9+
*.qcow2
10+
*.run
11+
*.user-data

spread.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
project: openshell
5+
6+
backends:
7+
garden:
8+
type: adhoc
9+
allocate: |
10+
if [ -n "${SPREAD_HOST_PATH-}" ]; then
11+
PATH="${SPREAD_HOST_PATH}"
12+
fi
13+
exec image-garden allocate --spread "$SPREAD_SYSTEM"."$(uname -m)"
14+
discard: |
15+
if [ -n "${SPREAD_HOST_PATH-}" ]; then
16+
PATH="${SPREAD_HOST_PATH}"
17+
fi
18+
image-garden discard "$SPREAD_SYSTEM_ADDRESS"
19+
systems:
20+
- ubuntu-cloud-24.04:
21+
username: ubuntu
22+
password: ubuntu
23+
- ubuntu-cloud-26.04:
24+
username: ubuntu
25+
password: ubuntu
26+
- debian-cloud-13:
27+
username: debian
28+
password: debian
29+
- fedora-cloud-44:
30+
username: fedora
31+
password: fedora
32+
- centos-cloud-10:
33+
username: centos
34+
password: centos
35+
36+
exclude:
37+
- ".cache/*"
38+
- ".image-garden/*"
39+
- "target/*"
40+
41+
path: /root/openshell
42+
43+
prepare: |
44+
# Install the openshell snap that was copied into the test environment.
45+
snap install $(ls ./openshell_*.snap | sort -r | head -n 1) --dangerous
46+
47+
# Connect snap interfaces. When installing from the store this
48+
# is auto-connected by the snap declaration assertion, but locally
49+
# we need to do it manually.
50+
snap connect openshell:docker docker:docker-daemon
51+
snap connect openshell:log-observe
52+
snap connect openshell:system-observe
53+
snap connect openshell:ssh-keys
54+
55+
# Add the local gateway to user configuration.
56+
openshell gateway add http://127.0.0.1:17670 --local --name snap-docker
57+
openshell gateway select snap-docker
58+
openshell status
59+
60+
debug-each: |
61+
echo "Kernel and architecture:"
62+
uname -a
63+
64+
echo "OS release info:"
65+
cat /etc/os-release
66+
67+
echo "Installed snaps:"
68+
snap list
69+
70+
set +e
71+
72+
echo "Snap connections of the openshell snap:"
73+
snap connections openshell
74+
75+
echo "Openshell version:"
76+
snap run openshell --version
77+
78+
suites:
79+
tests/:
80+
summary: Smoke tests for OpenShell snap

tests/smoke/task.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
summary: Smoke test for creating a sandbox
5+
details: |
6+
This test verifies that the openshell snap is properly installed
7+
and that the openshell command is available and functional.
8+
A test sandbox is created on the selected gateway. A hello world program is
9+
then invoked in the sandbox.
10+
11+
prepare: |
12+
snap run openshell sandbox list | MATCH "No sandboxes found."
13+
14+
execute: |
15+
snap run openshell sandbox create -- echo "Hello, OpenShell!" | MATCH "Hello, OpenShell!"
16+
snap run openshell sandbox list | MATCH ".*Ready"
17+
18+
restore: |
19+
snap run openshell sandbox delete --all | MATCH ".*Deleted.*"
20+
snap run openshell sandbox list | MATCH "No sandboxes found."

0 commit comments

Comments
 (0)