File: config_updates_without_affect.go

package info (click to toggle)
golang-github-opencontainers-runtime-tools 0.9.0%2Bgit20220423.g0105384-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,160 kB
  • sloc: sh: 558; makefile: 90
file content (88 lines) | stat: -rw-r--r-- 1,991 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	"github.com/google/uuid"
	tap "github.com/mndrix/tap-go"
	"github.com/mrunalp/fileutils"
	rspec "github.com/opencontainers/runtime-spec/specs-go"
	"github.com/opencontainers/runtime-tools/generate"
	"github.com/opencontainers/runtime-tools/specerror"
	"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
	t := tap.New()
	t.Header(0)

	bundleDir, err := util.PrepareBundle()
	if err != nil {
		util.Fatal(err)
	}
	defer os.RemoveAll(bundleDir)

	r, err := util.NewRuntime(util.RuntimeCommand, bundleDir)
	if err != nil {
		util.Fatal(err)
	}

	testPath := filepath.Join(bundleDir, "test.json")
	r.SetID(uuid.NewString())
	// generate a config has all the testing properties
	g, err := util.GetDefaultGenerator()
	if err != nil {
		util.Fatal(err)
	}
	g.SetProcessArgs([]string{"/runtimetest", "--path=/test.json"})
	g.AddLinuxMaskedPaths("/proc/kcore")
	g.AddLinuxReadonlyPaths("/proc/fs")
	g.AddLinuxSysctl("net.ipv4.ip_forward", "1")
	g.SetProcessOOMScoreAdj(100)
	g.AddProcessRlimits("RLIMIT_NOFILE", 1024, 1024)
	g.SetLinuxRootPropagation("shared")

	err = r.SetConfig(g)
	if err != nil {
		util.Fatal(err)
	}

	err = g.SaveToFile(testPath, generate.ExportOptions{})
	if err != nil {
		util.Fatal(err)
	}

	err = fileutils.CopyFile("runtimetest", filepath.Join(r.BundleDir, "runtimetest"))
	if err != nil {
		util.Fatal(err)
	}

	err = r.Create()
	if err != nil {
		util.Fatal(err)
	}

	g.Config = &rspec.Spec{
		Version: "1.0.0",
	}
	err = r.SetConfig(g)
	if err != nil {
		util.Fatal(err)
	}

	err = r.Start()
	util.SpecErrorOK(t, err == nil, specerror.NewError(specerror.ConfigUpdatesWithoutAffect, fmt.Errorf("Any updates to config.json after this step MUST NOT affect the container"), rspec.Version), nil)

	err = util.WaitingForStatus(r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
	if err == nil {
		err = r.Delete()
	}
	if err != nil {
		t.Fail(err.Error())
	}

	t.AutoPlan()
}