Skip to content

Commit

Permalink
rootfs readonly test
Browse files Browse the repository at this point in the history
Signed-off-by: liang chenye <liangchenye@huawei.com>
  • Loading branch information
liangchenye committed May 26, 2016
1 parent d8766be commit b5e4b9c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ func mountMatch(specMount rspec.Mount, sysMount rspec.Mount) error {
return nil
}

func containString(opts []string, str string) bool {
for _, opt := range opts {
if opt == str {
return true
}
}

return false
}

func validateMounts(spec *rspec.Spec) error {
fmt.Println("validating mounts")
infos, err := mount.GetMounts()
Expand All @@ -227,11 +237,21 @@ func validateMounts(spec *rspec.Spec) error {

mountsMap := make(map[string]rspec.Mount)
for _, info := range infos {
opts := strings.Split(info.Opts, ",")

if info.Mountpoint == "/" {
if spec.Root.Readonly && !containString(opts, "ro") ||
!spec.Root.Readonly && !containString(opts, "rw") {
return fmt.Errorf("root readonly expected: %v, actual: %v", spec.Root.Readonly, !spec.Root.Readonly)
}
}

mountsMap[info.Mountpoint] = rspec.Mount{
Destination: info.Mountpoint,
Type: info.Fstype,
Source: info.Source,
Options: append(strings.Split(info.Opts, ","), strings.Split(info.VfsOpts, ",")...)}
Options: append(opts, strings.Split(info.VfsOpts, ",")...)}

}

for _, specMount := range spec.Mounts {
Expand Down

0 comments on commit b5e4b9c

Please sign in to comment.