Skip to content

Commit

Permalink
validation/util/container: Use a local UUID for stdout/stderr
Browse files Browse the repository at this point in the history
So validation/create.t gives:

  ok 4 - create MUST generate an error if the ID provided is not unique
    ---
    {
      "error": "exit status 1",
      "reference": "https://github.com/opencontainers/runtime-spec/blob/v1.0.0/runtime.md#create",
      "stderr": "container with id exists: 4a142dd0-e5bc-48b3-9abd-49c1a8f7c498\n"
    }
    ...

instead of:

  ok 4 - create MUST generate an error if the ID provided is not unique
    ---
    {
      "error": "open /tmp/ocitest842577116/stdout-178f8311-9cc7-42c5-b91e-abbe29eaf582: file exists",
      "reference": "https://github.com/opencontainers/runtime-spec/blob/v1.0.0/runtime.md#create"
    }
    ...

The old code hit the internal error, while the new code is checking
for a runtime error.

Signed-off-by: W. Trevor King <[email protected]>
  • Loading branch information
wking committed Dec 4, 2017
1 parent 1e0b8b9 commit a55d234
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions validation/util/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

rspecs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/satori/go.uuid"
)

// Runtime represents the basic requirement of a container runtime
Expand Down Expand Up @@ -63,12 +64,13 @@ func (r *Runtime) Create() (stderr []byte, err error) {
// }
cmd := exec.Command(r.RuntimeCommand, args...)
cmd.Dir = r.BundleDir
r.stdout, err = os.OpenFile(filepath.Join(r.BundleDir, fmt.Sprintf("stdout-%s", r.ID)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
id := uuid.NewV4().String()
r.stdout, err = os.OpenFile(filepath.Join(r.BundleDir, fmt.Sprintf("stdout-%s", id)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err != nil {
return []byte(""), err
}
cmd.Stdout = r.stdout
r.stderr, err = os.OpenFile(filepath.Join(r.BundleDir, fmt.Sprintf("stderr-%s", r.ID)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
r.stderr, err = os.OpenFile(filepath.Join(r.BundleDir, fmt.Sprintf("stderr-%s", id)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err != nil {
return []byte(""), err
}
Expand Down

0 comments on commit a55d234

Please sign in to comment.