Skip to content
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

Carry 232: fix issue #228 replace start to run #285

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func validateLinuxProcess(spec *rspec.Spec) error {
return fmt.Errorf("NoNewPrivileges expected: false, actual: true")
}

return nil
return validateSucceed("container process validation passed.")
}

func validateCapabilities(spec *rspec.Spec) error {
Expand Down Expand Up @@ -182,7 +182,7 @@ func validateCapabilities(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("capabilities validation passed.")
}

func validateHostname(spec *rspec.Spec) error {
Expand All @@ -194,7 +194,7 @@ func validateHostname(spec *rspec.Spec) error {
if spec.Hostname != "" && hostname != spec.Hostname {
return fmt.Errorf("Hostname expected: %v, actual: %v", spec.Hostname, hostname)
}
return nil
return validateSucceed("hostname validation passed.")
}

func validateRlimits(spec *rspec.Spec) error {
Expand All @@ -217,7 +217,7 @@ func validateRlimits(spec *rspec.Spec) error {
return fmt.Errorf("%v rlimit hard expected: %v, actual: %v", r.Type, r.Hard, rlimit.Max)
}
}
return nil
return validateSucceed("rlimits validation passed.")
}

func validateSysctls(spec *rspec.Spec) error {
Expand All @@ -233,7 +233,7 @@ func validateSysctls(spec *rspec.Spec) error {
return fmt.Errorf("Sysctl %v value expected: %v, actual: %v", k, v, value)
}
}
return nil
return validateSucceed("sysctls validation passed.")
}

func testWriteAccess(path string) error {
Expand All @@ -257,7 +257,7 @@ func validateRootFS(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("root filesystem validation passed.")
}

func validateDefaultFS(spec *rspec.Spec) error {
Expand All @@ -279,7 +279,7 @@ func validateDefaultFS(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("linkx default filesystem validation passed.")
}

func validateLinuxDevices(spec *rspec.Spec) error {
Expand Down Expand Up @@ -338,7 +338,7 @@ func validateLinuxDevices(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("linux devices validation passed.")
}

func validateDefaultDevices(spec *rspec.Spec) error {
Expand All @@ -357,7 +357,7 @@ func validateDefaultDevices(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("linux default devices validation passed.")
}

func validateMaskedPaths(spec *rspec.Spec) error {
Expand All @@ -374,7 +374,7 @@ func validateMaskedPaths(spec *rspec.Spec) error {
return fmt.Errorf("%v should not be readable", maskedPath)
}
}
return nil
return validateSucceed("maskedPaths validation passed.")
}

func validateROPaths(spec *rspec.Spec) error {
Expand All @@ -386,7 +386,7 @@ func validateROPaths(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("readonlyPaths validation passed.")
}

func validateOOMScoreAdj(spec *rspec.Spec) error {
Expand Down Expand Up @@ -415,7 +415,7 @@ func validateOOMScoreAdj(spec *rspec.Spec) error {
}
}

return nil
return validateSucceed("oomScoreAdj validation passed.")
}

func getIDMappings(path string) ([]rspec.IDMapping, error) {
Expand Down Expand Up @@ -482,13 +482,21 @@ func validateIDMappings(mappings []rspec.IDMapping, path string, property string
func validateUIDMappings(spec *rspec.Spec) error {
logrus.Debugf("validating uidMappings")

return validateIDMappings(spec.Linux.UIDMappings, "/proc/self/uid_map", "linux.uidMappings")
err := validateIDMappings(spec.Linux.UIDMappings, "/proc/self/uid_map", "linux.uidMappings")
if err != nil {
return err
}
return validateSucceed("uidMappings validation passed.")
}

func validateGIDMappings(spec *rspec.Spec) error {
logrus.Debugf("validating gidMappings")

return validateIDMappings(spec.Linux.GIDMappings, "/proc/self/gid_map", "linux.gidMappings")
err := validateIDMappings(spec.Linux.GIDMappings, "/proc/self/gid_map", "linux.gidMappings")
if err != nil {
return err
}
return validateSucceed("gidMappings validation passed.")
}

func mountMatch(specMount rspec.Mount, sysMount rspec.Mount) error {
Expand Down Expand Up @@ -538,20 +546,22 @@ func validateMountsExist(spec *rspec.Spec) error {
}
}

return validateSucceed("mounts exist validation passed.")
}

func validateFailed(err error) error {
return fmt.Errorf("-----------------------------------------------------------------------------------\nRuntime validation failed:\nError: %s", err.Error())
}

func validateSucceed(msg string) error {
fmt.Println(msg)
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)

spec, err := loadSpecConfig()
if err != nil {
return err
return validateFailed(err)
}

defaultValidations := []validation{
Expand All @@ -577,19 +587,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("Runtime validation succeeded.")
}

func main() {
Expand All @@ -599,6 +609,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 +623,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
}
19 changes: 13 additions & 6 deletions test_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,23 @@ cleanup() {
}
trap cleanup EXIT

die() {
echo $1
exit 1
}

tar -xf rootfs.tar.gz -C ${TESTDIR}
cp runtimetest ${TESTDIR}

oci-runtime-tool generate --output "${TESTDIR}/config.json" "${TEST_ARGS[@]}" --rootfs-path '.'

TESTCMD="${RUNTIME} start $(uuidgen)"
CONID=$(uuidgen)

CREATECMD="${RUNTIME} create ${CONID}"
TESTCMD="${RUNTIME} start ${CONID}"
DELCMD="${RUNTIME} delete ${CONID}"
pushd $TESTDIR > /dev/null
if ! ${TESTCMD}; then
error "Runtime ${RUNTIME} failed validation"
else
info "Runtime ${RUNTIME} passed validation"
fi
${CREATECMD} || die "failed to create ${CONID}"
${TESTCMD} || die "failed to start ${CONID}"
sleep 1 && ${DELCMD} || die "failed to delete ${CONID}"
popd > /dev/null