Skip to content

Commit

Permalink
validate: add Hooks validation
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 Apr 28, 2016
1 parent b31bc93 commit 0daf264
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func bundleValidate(spec rspec.Spec, rootfs string) {
checkSemVer(spec.Version)
checkProcess(spec.Process, rootfs)
checkMounts(spec.Mounts, rootfs)
checkHooks(spec.Hooks, rootfs)
checkLinux(spec.Linux, rootfs)
}

Expand All @@ -106,6 +107,29 @@ func checkMounts(mounts []rspec.Mount, rootfs string) {
}
}

func checkHooks(process rspec.Hooks, rootfs string) {
for _, prestart := range process.Prestart {
binPath := path.Join(rootfs, prestart.Path)
if _, err := os.Stat(binPath); err != nil {
logrus.Fatalf("Cannot find pre-start hook: %v", binPath)
}
}

for _, poststart := range process.Poststart {
binPath := path.Join(rootfs, poststart.Path)
if _, err := os.Stat(binPath); err != nil {
logrus.Fatalf("Cannot find post-start hook: %v", binPath)
}
}

for _, poststop := range process.Poststop {
binPath := path.Join(rootfs, poststop.Path)
if _, err := os.Stat(binPath); err != nil {
logrus.Fatalf("Cannot find post-stop hook: %v", binPath)
}
}
}

func checkProcess(process rspec.Process, rootfs string) {
for index := 0; index < len(process.Capabilities); index++ {
capability := process.Capabilities[index]
Expand Down

0 comments on commit 0daf264

Please sign in to comment.