forked from zenlint/ocitools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Liang Chenye <[email protected]>
- Loading branch information
1 parent
8e52e10
commit 78f41b5
Showing
3 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
tap "github.com/mndrix/tap-go" | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
t := tap.New() | ||
t.Header(0) | ||
|
||
var lifecycle util.LifecycleFuncs | ||
tempFile, err := ioutil.TempFile("", "oci-pidfile") | ||
if err != nil { | ||
util.Fatal(err) | ||
} else if err := tempFile.Close(); err != nil { | ||
util.Fatal(err) | ||
} | ||
tempPidFile := tempFile.Name() | ||
lifecycle.Setup = func(r *util.Runtime) error { | ||
r.SetPidFile(tempPidFile) | ||
return nil | ||
} | ||
defer os.Remove(tempPidFile) | ||
|
||
lifecycle.PreStart = func(r *util.Runtime) error { | ||
pidData, err := ioutil.ReadFile(tempPidFile) | ||
if err != nil { | ||
return err | ||
} | ||
pid, err := strconv.Atoi(string(pidData)) | ||
if err != nil { | ||
return err | ||
} | ||
state, err := r.State() | ||
if err != nil { | ||
return err | ||
} | ||
if state.Pid != pid { | ||
return errors.New("Wrong pid in the pidfile") | ||
} | ||
return nil | ||
} | ||
|
||
lifecycle.PostStart = func(r *util.Runtime) error { | ||
time.Sleep(1 * time.Second) | ||
return nil | ||
} | ||
|
||
lifecycle.PostStop = nil | ||
|
||
g := util.GetDefaultGenerator() | ||
g.SetProcessArgs([]string{"ls"}) | ||
err = util.RuntimeLifecycleValidate(g, &lifecycle) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
|
||
t.AutoPlan() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters