Skip to content

Commit

Permalink
add mounts validate in runtimetest; using mount package in docker
Browse files Browse the repository at this point in the history
Signed-off-by: liang chenye <liangchenye@huawei.com>
  • Loading branch information
liangchenye committed Jun 1, 2016
1 parent 5130deb commit 9f5bb68
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/mount"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/syndtr/gocapability/capability"
)
Expand Down Expand Up @@ -191,6 +192,61 @@ func validateSysctls(spec *rspec.Spec) error {
return nil
}

func mountMatch(specMount rspec.Mount, sysMount rspec.Mount) error {
if specMount.Destination != sysMount.Destination {
return fmt.Errorf("mount destination expected: %v, actual: %v", specMount.Destination, sysMount.Destination)
}

if specMount.Type != sysMount.Type {
return fmt.Errorf("mount %v type expected: %v, actual: %v", specMount.Destination, specMount.Type, sysMount.Type)
}

if specMount.Source != sysMount.Source {
return fmt.Errorf("mount %v source expected: %v, actual: %v", specMount.Destination, specMount.Source, sysMount.Source)
}

optMap := make(map[string]bool)
for _, opt := range sysMount.Options {
optMap[opt] = true
}
for _, option := range specMount.Options {
if _, ok := optMap[option]; !ok {
return fmt.Errorf("mount %v option %v does not exist", specMount.Destination, option)
}
}

return nil
}

func validateMounts(spec *rspec.Spec) error {
fmt.Println("validating mounts")
infos, err := mount.GetMounts()
if err != nil {
return err
}

mountsMap := make(map[string]rspec.Mount)
for _, info := range infos {
mountsMap[info.Mountpoint] = rspec.Mount{
Destination: info.Mountpoint,
Type: info.Fstype,
Source: info.Source,
Options: append(strings.Split(info.Opts, ","), strings.Split(info.VfsOpts, ",")...)}
}

for _, specMount := range spec.Mounts {
if sysMount, ok := mountsMap[specMount.Destination]; ok {
if err := mountMatch(specMount, sysMount); err != nil {
return err
}
} else {
return fmt.Errorf("Expected mount %v does not exist", specMount.Destination)
}
}

return nil
}

func main() {
spec, err := loadSpecConfig()
if err != nil {
Expand All @@ -203,6 +259,7 @@ func main() {
validateHostname,
validateRlimits,
validateSysctls,
validateMounts,
}

for _, v := range validations {
Expand Down

0 comments on commit 9f5bb68

Please sign in to comment.