Skip to content

Commit

Permalink
Merge pull request #100 from cloudfoundry-incubator/ignore-stderr
Browse files Browse the repository at this point in the history
runc/client: ignore child process stderr
  • Loading branch information
jfmyers9 committed Sep 15, 2018
2 parents 7cab7f0 + df5d430 commit 9d77927
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bpm/runc/client/client.go
Expand Up @@ -183,7 +183,7 @@ func (c *RuncClient) ListContainers() ([]ContainerState, error) {
"--format", "json",
)

data, err := runcCmd.CombinedOutput()
data, err := runcCmd.Output()
if err != nil {
return []ContainerState{}, err
}
Expand Down
50 changes: 47 additions & 3 deletions src/bpm/runc/client/client_test.go
Expand Up @@ -167,6 +167,50 @@ var _ = Describe("RuncClient", func() {
})
})

Describe("ListContainers", func() {
var (
tempDir string
fakeRuncPath string
)

BeforeEach(func() {
var err error
tempDir, err = ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())

fakeRuncPath = filepath.Join(tempDir, "fakeRunc")

runcClient = client.NewRuncClient(fakeRuncPath, "/path/to/things")
})

AfterEach(func() {
err := os.RemoveAll(tempDir)
Expect(err).NotTo(HaveOccurred())
})

// RunC has a race condition where it will try and put a container in
// the list before it can fetch the state for that container which
// dumps errors in stderr.
Context("when runc returns an error as well as a list", func() {
BeforeEach(func() {
contents := []byte(`#!/bin/sh
echo -n 'error: could not list' >&2
echo -n '[]'
exit 0
`)

err := ioutil.WriteFile(fakeRuncPath, contents, 0700)
Expect(err).NotTo(HaveOccurred())
})

It("ignores the error", func() {
containers, err := runcClient.ListContainers()
Expect(err).NotTo(HaveOccurred())
Expect(containers).To(BeEmpty())
})
})
})

Describe("ContainerState", func() {
var (
tempDir string
Expand Down Expand Up @@ -195,7 +239,7 @@ echo -n 'container "foo" does not exist'
exit 1
`)

err := ioutil.WriteFile(fakeRuncPath, contents, os.ModePerm)
err := ioutil.WriteFile(fakeRuncPath, contents, 0700)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -214,7 +258,7 @@ echo ' container "foo" does not exist '
exit 1
`)

err := ioutil.WriteFile(fakeRuncPath, contents, os.ModePerm)
err := ioutil.WriteFile(fakeRuncPath, contents, 0700)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -234,7 +278,7 @@ echo -n 'some unrelated error'
exit 1
`)

err := ioutil.WriteFile(fakeRuncPath, contents, os.ModePerm)
err := ioutil.WriteFile(fakeRuncPath, contents, 0700)
Expect(err).NotTo(HaveOccurred())
})

Expand Down

0 comments on commit 9d77927

Please sign in to comment.