Skip to content

Commit d58af5f

Browse files
committed
kola: Add isolation=readonly|dynamicuser
Part of my war against duplicative comments in our kola tests. We have a few tests that write a comment like this: ``` # - exclusive: false # - This test doesn't make meaningful changes to the system and # should be able to be combined with other tests. ``` Of course, this comment is already redundant because the meaning of the `exclusive` tag is defined canonically in coreos-assembler (here) and copy-pasting that into every test that uses it would be pointlessly verbose. But - we can do one better. Instead of having a test flag which is mainly an "I promise not to mutate the system in a way which could interfere with other tests", let's add a field that *enforces* this. Then it doesn't need to be commented; we have a variety of tests which are just "system inspection" (e.g. query rpmdb) and run just fine with `DynamicUser=yes` and hence *cannot* affect the system, and hence are inherently isolated from other concurrent tests.
1 parent 6b7a7ba commit d58af5f

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

docs/kola/external-tests.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ is simple and is not expected to conflict with other tests, it should be marked
264264
`exclusive: false`. When the `exclusive` key is not provided, tests are marked
265265
`exclusive: true` by default.
266266

267+
The `isolation` key can take two values: `readonly` and `dynamicuser`. These
268+
are thin wrappers for the equivalent systemd options; `readonly` equals `ProtectSystem=strict`,
269+
and `dynamicuser` means `DynamicUser=yes`. Setting either of these options
270+
also implies `exclusive: false`. Use these for tests that are mostly about
271+
read-only system inspection.
272+
267273
The `conflicts` key takes a list of test names that conflict with this test.
268274
This key can only be specified if `exclusive` is marked `false` since
269275
`exclusive: true` tests are run exclusively in their own VM. At runtime,

mantle/kola/harness.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ type externalTestMeta struct {
826826
AppendKernelArgs string `json:"appendKernelArgs,omitempty"`
827827
AppendFirstbootKernelArgs string `json:"appendFirstbootKernelArgs,omitempty"`
828828
Exclusive bool `json:"exclusive"`
829+
Isolation string `json:"isolation"`
829830
TimeoutMin int `json:"timeoutMin"`
830831
Conflicts []string `json:"conflicts"`
831832
AllowConfigWarnings bool `json:"allowConfigWarnings"`
@@ -952,6 +953,16 @@ func registerExternalTest(testname, executable, dependencydir string, userdata *
952953
return errors.Wrapf(err, "Parsing config.ign")
953954
}
954955

956+
switch targetMeta.Isolation {
957+
case "readonly":
958+
case "dynamicuser":
959+
targetMeta.Exclusive = false
960+
case "":
961+
break
962+
default:
963+
return fmt.Errorf("test %v specifies unknown isolation=%v", testname, targetMeta.Isolation)
964+
}
965+
955966
// Services that are exclusive will be marked by a 0 at the end of the name
956967
num := 0
957968
unitName := fmt.Sprintf("%s.service", KoletExtTestUnit)
@@ -980,6 +991,16 @@ Environment=KOLA_TEST_EXE=%s
980991
Environment=%s=%s
981992
ExecStart=%s
982993
`, unitName, testname, base, kolaExtBinDataEnv, destDataDir, remotepath)
994+
switch targetMeta.Isolation {
995+
case "readonly":
996+
unit += "ProtectSystem=strict\nPrivateTmp=yes\n"
997+
case "dynamicuser":
998+
unit += "DynamicUser=yes\n"
999+
case "":
1000+
break
1001+
default:
1002+
return fmt.Errorf("test %v specifies unknown isolation=%v", testname, targetMeta.Isolation)
1003+
}
9831004
if targetMeta.InjectContainer {
9841005
if CosaBuild == nil {
9851006
return fmt.Errorf("test %v uses injectContainer, but no cosa build found", testname)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# kola: { "isolation": "dynamicuser" }
3+
set -xeuo pipefail
4+
5+
id=$(id -u)
6+
test "$id" '!=' 0
7+
echo "ok dynamicuser"

0 commit comments

Comments
 (0)