Skip to content

Commit

Permalink
validation: Implement ConfigUpdatesWithoutAffect
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
  • Loading branch information
Zhou Hao committed Mar 20, 2018
1 parent 3f64e51 commit 36b24c7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Binary file added config_updates_without_affect
Binary file not shown.
86 changes: 86 additions & 0 deletions validation/config_updates_without_affect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package main

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

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"
uuid "github.com/satori/go.uuid"
)

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("/", "test", "config.json")
r.SetID(uuid.NewV4().String())
// generate a config has all the testing properties
g := util.GetDefaultGenerator()
g.SetProcessArgs([]string{"/runtimetest", "--path=" + testPath})
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)
}

spec := &rspec.Spec{
Version: "1.0.0",
}
g.SetSpec(spec)
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 {
util.Fatal(err)
}

t.AutoPlan()
}

0 comments on commit 36b24c7

Please sign in to comment.