Skip to content

Commit 064565a

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 064565a

5 files changed

Lines changed: 159 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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
- 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+
- 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+
- 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+
- docker pull $(default_sandbox_image)
42+
endef
43+

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