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"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"time"
tap "github.com/mndrix/tap-go"
"github.com/mrunalp/fileutils"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"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)
// Create a cgroup
cgPath := "/sys/fs/cgroup"
testPath := filepath.Join(cgPath, "pids", "cgrouptest")
os.Mkdir(testPath, 0755)
defer os.RemoveAll(testPath)
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)
}
r.SetID(uuid.NewV4().String())
g, err := util.GetDefaultGenerator()
if err != nil {
util.Fatal(err)
}
err = r.SetConfig(g)
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)
}
state, err := r.State()
if err != nil {
util.Fatal(err)
}
// Add the container to the cgroup
err = ioutil.WriteFile(filepath.Join(testPath, "tasks"), []byte(strconv.Itoa(state.Pid)), 0644)
if err != nil {
util.Fatal(err)
}
err = r.Start()
if err != nil {
util.Fatal(err)
}
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())
}
_, err = os.Stat(testPath)
fmt.Println(err)
util.SpecErrorOK(t, err == nil, specerror.NewError(specerror.DeleteOnlyCreatedRes, fmt.Errorf("Note that resources associated with the container, but not created by this container, MUST NOT be deleted"), rspec.Version), nil)
t.AutoPlan()
}
|