-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial version of runtimetest command: #9
Changes from 2 commits
273b86d
37b9346
5e909b5
7430659
d7f681c
d0eecbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
process= --args=./runtimetest --rootfs=rootfs --read-only=false;--args=./runtimetest --rootfs=rootfs --read-only=true | ||
hostname= --args=./runtimetest --rootfs=rootfs --hostname=zenlin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package config | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/Sirupsen/logrus" | ||
) | ||
|
||
const configPath = "cases.conf" | ||
|
||
var ( | ||
// BundleMap for config, key is the bundlename, value is the params | ||
BundleMap = make(map[string]string) | ||
configLen int | ||
) | ||
|
||
func init() { | ||
f, err := os.Open(configPath) | ||
if err != nil { | ||
logrus.Fatalf("open file %v error %v", configPath, err) | ||
} | ||
defer f.Close() | ||
|
||
rd := bufio.NewReader(f) | ||
count := 0 | ||
|
||
for { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary empty line here. |
||
line, err := rd.ReadString('\n') | ||
if err != nil || io.EOF == err { | ||
break | ||
} | ||
|
||
prefix := strings.Split(line, "=") | ||
caseName := strings.TrimSpace(prefix[0]) | ||
caseArg := strings.TrimPrefix(line, caseName+"=") | ||
for i, arg := range splitArgs(caseArg) { | ||
BundleMap[caseName+strconv.FormatInt(int64(i), 10)] = arg | ||
count = count + 1 | ||
} | ||
} | ||
configLen = count | ||
} | ||
|
||
func splitArgs(args string) []string { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line not required here |
||
argArray := strings.Split(args, ";") | ||
resArray := make([]string, len(argArray)) | ||
for count, arg := range argArray { | ||
resArray[count] = strings.TrimSpace(arg) | ||
} | ||
return resArray | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/codegangsta/cli" | ||
"github.com/opencontainers/ocitools/units" | ||
) | ||
|
||
const bundleCacheDir = "./bundles" | ||
|
||
var runtimetestFlags = []cli.Flag{ | ||
cli.StringFlag{Name: "runtime, r", Usage: "runtime to be tested"}, | ||
cli.StringFlag{Name: "output, o", Usage: "output format, \n" + | ||
"-o=all: ouput sucessful details and statics, -o=err-only: ouput failure details and statics"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/statics/statistics? |
||
cli.BoolFlag{Name: "debug, d", Usage: "switch of debug mode, defaults to false, with '--debug' to enable debug mode"}, | ||
} | ||
|
||
var runtimeTestCommand = cli.Command{ | ||
Name: "runtimetest", | ||
Usage: "test if a runtime is comlpliant to oci specs", | ||
Flags: runtimetestFlags, | ||
Action: func(context *cli.Context) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line not required. |
||
if os.Geteuid() != 0 { | ||
logrus.Fatalln("runtimetest should be run as root") | ||
} | ||
var runtime string | ||
if runtime = context.String("runtime"); runtime != "runc" { | ||
logrus.Fatalf("runtimetest have not support %v\n", runtime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/have not/does not/ |
||
} | ||
output := context.String("output") | ||
setDebugMode(context.Bool("debug")) | ||
|
||
units.LoadTestUnits("./cases.conf") | ||
|
||
if err := os.MkdirAll(bundleCacheDir, os.ModePerm); err != nil { | ||
logrus.Printf("create cache dir for bundle cases err: %v\ns", bundleCacheDir) | ||
return | ||
} | ||
|
||
for _, tu := range *units.Units { | ||
testTask(tu, runtime) | ||
} | ||
|
||
units.OutputResult(output) | ||
|
||
if err := os.RemoveAll(bundleCacheDir); err != nil { | ||
logrus.Fatalf("remove cache dir of bundles %v err: %v\n", bundleCacheDir, err) | ||
} | ||
|
||
if err := os.Remove("./runtime.json"); err != nil { | ||
logrus.Fatalf("remove ./runtime.json err: %v\n", err) | ||
} | ||
|
||
if err := os.Remove("./config.json"); err != nil { | ||
logrus.Fatalf("remove ./config.json err: %v\n", err) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func setDebugMode(debug bool) { | ||
if !debug { | ||
logrus.SetLevel(logrus.InfoLevel) | ||
} else { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
} | ||
|
||
func testTask(unit *units.TestUnit, runtime string) { | ||
logrus.Debugf("test bundle name: %v, Test args: %v\n", unit.Name, unit.Args) | ||
if err := unit.SetRuntime(runtime); err != nil { | ||
logrus.Fatalf("failed to setup runtime %s , error: %v\n", runtime, err) | ||
} else { | ||
unit.Run() | ||
} | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could club the initialization and for loop together without an empty line