Skip to content

Commit

Permalink
list: Don't fail if rootfs doesn't exist
Browse files Browse the repository at this point in the history
If it is not possible to determine the owner of the rootfs, do not fail
the entire `list` operation, just mark the container owner field with a
question mark.

Fixes clearcontainers#906.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Jan 8, 2018
1 parent 9014fe3 commit 5ed8237
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
10 changes: 6 additions & 4 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,15 @@ func getContainers(context *cli.Context) ([]fullContainerState, error) {
ociState := oci.StatusToOCIState(container)
staleAssets := getStaleAssets(currentHypervisorDetails, latestHypervisorDetails)

var owner string

uid, err := getDirOwner(container.RootFs)
if err != nil {
return nil, err
if err == nil {
owner = fmt.Sprintf("#%v", uid)
} else {
owner = "?"
}

owner := fmt.Sprintf("#%v", uid)

s = append(s, fullContainerState{
containerState: containerState{
Version: ociState.Version,
Expand Down
64 changes: 64 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,70 @@ func TestListGetContainers(t *testing.T) {
assert.Equal(state, []fullContainerState(nil))
}

func TestListGetContainersMissingRootfs(t *testing.T) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

pod := &vcMock.Pod{
MockID: testPodID,
}

rootfs := filepath.Join(tmpdir, "rootfs")

container := vc.ContainerStatus{
ID: pod.ID(),
State: vc.State{
State: vc.StateRunning,
},
PID: 1,

// rootfs specified, but it doesn't exist
RootFs: rootfs,
}

testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) {
return []vc.PodStatus{
{
ID: pod.ID(),
ContainersStatus: []vc.ContainerStatus{
container,
},
},
}, nil
}

defer func() {
testingImpl.ListPodFunc = nil
}()

app := cli.NewApp()
ctx := cli.NewContext(app, nil, nil)
app.Name = "foo"

runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true)

assert.NoError(err)

ctx.App.Metadata = map[string]interface{}{
"runtimeConfig": runtimeConfig,
}

states, err := getContainers(ctx)
assert.NoError(err)

assert.True(len(states) == 1)

state := states[0]

assert.Equal(state.Rootfs, container.RootFs)

// since rootfs doesn't exist
assert.Equal(state.Owner, "?")
}

func TestListGetContainersPodWithoutContainers(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 5ed8237

Please sign in to comment.