Skip to content

Commit

Permalink
runtimetest: add returning validate result
Browse files Browse the repository at this point in the history
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
  • Loading branch information
Ma Shimiao committed Dec 1, 2016
1 parent c151f38 commit 1dbfcf5
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,17 +541,19 @@ func validateMountsExist(spec *rspec.Spec) error {
return nil
}

func validate(context *cli.Context) error {
logLevelString := context.String("log-level")
logLevel, err := logrus.ParseLevel(logLevelString)
if err != nil {
return err
}
logrus.SetLevel(logLevel)
func validateFailed(err error) error {
return fmt.Errorf("Runtime validation failed:\nError: %s", err.Error())
}

func validateSucceed() error {
fmt.Println("Runtime validation succeeded.")
return nil
}

func validate(context *cli.Context) error {
spec, err := loadSpecConfig()
if err != nil {
return err
return validateFailed(err)
}

defaultValidations := []validation{
Expand All @@ -577,19 +579,19 @@ func validate(context *cli.Context) error {

for _, v := range defaultValidations {
if err := v(spec); err != nil {
return err
return validateFailed(err)
}
}

if spec.Platform.OS == "linux" {
for _, v := range linuxValidations {
if err := v(spec); err != nil {
return err
return validateFailed(err)
}
}
}

return nil
return validateSucceed()
}

func main() {
Expand All @@ -599,6 +601,7 @@ func main() {
app.Usage = "Compare the environment with an OCI configuration"
app.Description = "runtimetest compares its current environment with an OCI runtime configuration read from config.json in its current working directory. The tests are fairly generic and cover most configurations used by the runtime validation suite, but there are corner cases where a container launched by a valid runtime would not satisfy runtimetest."
app.UsageText = "runtimetest [options]"
app.Before = before
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "log-level",
Expand All @@ -612,3 +615,14 @@ func main() {
logrus.Fatal(err)
}
}

func before(context *cli.Context) error {
logLevelString := context.GlobalString("log-level")
logLevel, err := logrus.ParseLevel(logLevelString)
if err != nil {
logrus.Fatalf(err.Error())
}
logrus.SetLevel(logLevel)

return nil
}

0 comments on commit 1dbfcf5

Please sign in to comment.