add tests when prestart/poststart/poststop hooks fail#569
add tests when prestart/poststart/poststop hooks fail#569zhouhao3 merged 1 commit intoopencontainers:masterfrom
Conversation
wking
left a comment
There was a problem hiding this comment.
Some suggestions for poststart_fail.go. Some of these may apply to the other files you're adding too, but I haven't had time to look those over yet.
validation/poststart_fail.go
Outdated
| r.SetID(uuid.NewV4().String()) | ||
| g := util.GetDefaultGenerator() | ||
| poststart := rspec.Hook{ | ||
| Path: fmt.Sprintf("%s/%s/bin/false", r.BundleDir, g.Spec().Root.Path), |
validation/poststart_fail.go
Outdated
| Path: fmt.Sprintf("%s/%s/bin/false", r.BundleDir, g.Spec().Root.Path), | ||
| Args: []string{"false"}, | ||
| } | ||
| g.AddPostStartHook(poststart) |
There was a problem hiding this comment.
I think you also want a second hook which writes to a file, and a post-RuntimeLifecycleValidate check to ensure that file was never written. Similarly with SetProcessArgs, you'll want to set something there so we can confirm that the runtime didn't actually execute the user-specified program.
There was a problem hiding this comment.
+1 for this, I'll update these.
validation/poststart_fail.go
Outdated
| t.Header(0) | ||
|
|
||
| config := util.LifecycleConfig{ | ||
| Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, |
There was a problem hiding this comment.
No need to set util.LifecycleActionDelete or the PreDelete code below, because the start call should exit nonzero after the hook failure. That means RuntimeLifecycleValidate will exit here, before any of its delete-related code fires. You will need to explicitly delete the container in this file, and not rely on RuntimeLifecycleValidate for deletion.
There was a problem hiding this comment.
https://github.com/opencontainers/runtime-spec/blob/master/runtime.md#lifecycle
In poststart fail test, it will continue to work. 'start' should not exit.
Also with 'ActionDelete' set, even there is no chance to get 'r.Delete', the container will be deleted in the 'defer' function.
runtime-tools/validation/util/test.go
Line 294 in 3eba113
|
|
||
| err := util.RuntimeLifecycleValidate(nil, config) | ||
| if err != nil { | ||
| err := specerror.NewError(specerror.PoststartHookFailGenWarn, fmt.Errorf("if any poststart hook fails, the runtime MUST log a warning, but the remaining hooks and lifecycle continue as if the hook had succeeded"), rspec.Version) |
There was a problem hiding this comment.
Instead of assuming any error is the error we're trying to trigger, we should add a PostCreate action that flips a boolean:
successfulCreate := false
config := util.LifecycleConfig{
…
PostCreate: func(r *util.Runtime) error {
successfulCreate = true
return nil
},
}
…
if !successfulCreate {
…fail the test…
} else if err != nil {
…what you have here…
}There was a problem hiding this comment.
The sequence test is covered by 'prestart.go/poststart.go/poststop.go'. Here we just need to verify if the hook and lifecycle after 'poststart' will still work even if 'poststart' fails.
So we just need to verify if 'poststop' hook works.
|
|
One issue found in 'runc': once a hook fail in 'poststart' or 'poststop', the remain hooks will not be excused. One issue found in our generator: we cannot have hooks with a same Path. https://github.com/opencontainers/runtime-tools/blob/master/generate/generate.go#L918 |
validation/poststart_fail.go
Outdated
| Args: []string{ | ||
| "sh", "-c", fmt.Sprintf("echo 'post-stop called' >> %s", output), | ||
| }, | ||
| } |
There was a problem hiding this comment.
I don't think this poststop is needed. If the final output is not post-start called\npost-stop called\n, it's not immediately clear that it's poststart's error, and further judgment is needed. So I think this poststop should be removed to remove unnecessary effects.
There was a problem hiding this comment.
you are right, updated.
validation/poststop_fail.go
Outdated
| } | ||
| g.AddPostStopHook(poststop) | ||
| poststopOK := rspec.Hook{ | ||
| Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/echo"), |
|
updated PTAL @q384566678
|
validation/poststop_fail.go
Outdated
| // if runErr is not nil, it means the runtime generates an error | ||
| // if outputData is not equal to the expected content, it means there is something wrong with the remaining hooks and lifecycle | ||
| // if runErr != nil || string(outputData) != "post-stop called\n" { | ||
| if runErr != nil || string(outputData) != "" { |
There was a problem hiding this comment.
I think the line you commented out is correct.
// if runErr != nil || string(outputData) != "post-stop called\n" {
There was a problem hiding this comment.
ops, big mistake.
Updated
Signed-off-by: Liang Chenye <liangchenye@huawei.com>
4b08dde to
9177741
Compare
Signed-off-by: Liang Chenye liangchenye@huawei.com