Skip to content

Commit bd13d3c

Browse files
committed
kola: Add support for injectContainer
Closes: #2952 For quite a while we've been generating a "base image" container as part of our builds, but it has basically been entirely untested outside of its processing and use by the ostree stack. This adds a base framework such that external tests can request the injection of the container (`.ociarchive`). Now, we can (and *definitely* should) also pursue "natively" testing this container image outside of kola, which is very virtual-machine focused. However, that will also require a lot of pipeline changes; this approach allows us to natively "bridge" the worlds of cosa/kola to test the container image.
1 parent a1fc483 commit bd13d3c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/kola/external-tests.md

+6
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ In the example above, the test would only run if `--tag special` was provided.
229229
The `additionalDisks` key has the same semantics as the `--add-disk` argument
230230
to `qemuexec`. It is currently only supported on `qemu-unpriv`.
231231

232+
The `injectContainer` boolean if set will cause the framework to inject
233+
the ostree base image container into the target system; the path can be
234+
found in the environment variable `KOLA_OSTREE_OCIARCHIVE`. This will be
235+
an `.ociarchive` file that can be e.g. loaded into the containers storage
236+
via `skopeo copy oci-archive:$KOLA_OSTREE_OCIARCHIVE containers-storage:localhost/os`.
237+
232238
The `minDisk` key takes a size in GB and ensures that an instance type with at
233239
least the specified amount of primary disk space is used. On QEMU, this is
234240
equivalent to the `--qemu-size` argument to `qemuexec`. This is currently only

mantle/kola/harness.go

+23
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ const (
194194
// kolaExtBinDataEnv is an environment variable pointing to the above
195195
kolaExtBinDataEnv = "KOLA_EXT_DATA"
196196

197+
// kolaExtContainerDataEnv includes the path to the ostree base container image in oci-archive format.
198+
kolaExtContainerDataEnv = "KOLA_EXT_OSTREE_OCIARCHIVE"
199+
197200
// kolaExtBinDataName is the name for test dependency data
198201
kolaExtBinDataName = "data"
199202
)
@@ -765,6 +768,7 @@ type externalTestMeta struct {
765768
Tags string `json:"tags,omitempty"`
766769
RequiredTag string `json:"requiredTag,omitempty"`
767770
AdditionalDisks []string `json:"additionalDisks,omitempty"`
771+
InjectContainer bool `json:"injectContainer,omitempty"`
768772
MinMemory int `json:"minMemory,omitempty"`
769773
MinDiskSize int `json:"minDisk,omitempty"`
770774
AdditionalNics int `json:"additionalNics,omitempty"`
@@ -925,6 +929,13 @@ Environment=KOLA_TEST_EXE=%s
925929
Environment=%s=%s
926930
ExecStart=%s
927931
`, unitName, testname, base, kolaExtBinDataEnv, destDataDir, remotepath)
932+
if targetMeta.InjectContainer {
933+
if CosaBuild == nil {
934+
return fmt.Errorf("test %v uses injectContainer, but no cosa build found", testname)
935+
}
936+
ostreeContainer := CosaBuild.Meta.BuildArtifacts.Ostree
937+
unit += fmt.Sprintf("Environment=%s=/home/core/%s\n", kolaExtContainerDataEnv, ostreeContainer.Path)
938+
}
928939
config.AddSystemdUnit(unitName, unit, conf.NoState)
929940

930941
// Architectures using 64k pages use slightly more memory, ask for more than requested
@@ -944,6 +955,7 @@ ExecStart=%s
944955
Tags: []string{"external"},
945956

946957
AdditionalDisks: targetMeta.AdditionalDisks,
958+
InjectContainer: targetMeta.InjectContainer,
947959
MinMemory: targetMeta.MinMemory,
948960
MinDiskSize: targetMeta.MinDiskSize,
949961
AdditionalNics: targetMeta.AdditionalNics,
@@ -1459,6 +1471,17 @@ func runTest(h *harness.H, t *register.Test, pltfrm string, flight platform.Flig
14591471
}
14601472
}
14611473

1474+
if t.InjectContainer {
1475+
if CosaBuild == nil {
1476+
h.Fatalf("Test %s uses injectContainer, but no cosa build found", t.Name)
1477+
}
1478+
ostreeContainer := CosaBuild.Meta.BuildArtifacts.Ostree
1479+
ostreeContainerPath := filepath.Join(CosaBuild.Dir, ostreeContainer.Path)
1480+
if err := cluster.DropFile(tcluster.Machines(), ostreeContainerPath); err != nil {
1481+
h.Fatal(err)
1482+
}
1483+
}
1484+
14621485
if t.ExternalTest != "" {
14631486
setupExternalTest(h, t, tcluster)
14641487
// Collect the journal logs after execution is finished

mantle/kola/register/register.go

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type Test struct {
7878
// "5G:mpath,foo,bar"]) -- defaults to none.
7979
AdditionalDisks []string
8080

81+
// InjectContainer will cause the ostree base image to be injected into the target
82+
InjectContainer bool
83+
8184
// Minimum amount of memory in MB required for test.
8285
MinMemory int
8386

0 commit comments

Comments
 (0)