mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 17:22:33 +00:00
cli: do not fail on list when some containers bust
kata-runtime list command should list all valid container, not fail when some containers information uncorrent, like rootfs not found. Fixes: #1592 Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
parent
437b3cb2f7
commit
b7f51be8ce
@ -331,7 +331,8 @@ func getContainers(ctx context.Context, context *cli.Context) ([]fullContainerSt
|
|||||||
|
|
||||||
uid, err := getDirOwner(container.RootFs)
|
uid, err := getDirOwner(container.RootFs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
fmt.Fprintf(os.Stderr, "WARNING: failed to get container %s rootfs: %s\n", ociState.ID, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
owner := fmt.Sprintf("#%v", uid)
|
owner := fmt.Sprintf("#%v", uid)
|
||||||
|
@ -590,11 +590,6 @@ func TestListCLIFunctionFormatFail(t *testing.T) {
|
|||||||
|
|
||||||
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||||
|
|
||||||
_ = os.Remove(rootfs)
|
|
||||||
|
|
||||||
err = fn(ctx)
|
|
||||||
assert.Error(err)
|
|
||||||
|
|
||||||
err = os.MkdirAll(rootfs, testDirMode)
|
err = os.MkdirAll(rootfs, testDirMode)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -730,3 +725,61 @@ func TestListGetDirOwner(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(dirUID, uid)
|
assert.Equal(dirUID, uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListWithRootfsMissShouldSuccess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir(testDir, "")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
sandbox := &vcmock.Sandbox{
|
||||||
|
MockID: testSandboxID,
|
||||||
|
}
|
||||||
|
|
||||||
|
rootfs := filepath.Join(tmpdir, "rootfs")
|
||||||
|
err = os.MkdirAll(rootfs, testDirMode)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||||
|
return []vc.SandboxStatus{
|
||||||
|
{
|
||||||
|
ID: sandbox.ID(),
|
||||||
|
ContainersStatus: []vc.ContainerStatus{
|
||||||
|
{
|
||||||
|
ID: sandbox.ID(),
|
||||||
|
Annotations: map[string]string{
|
||||||
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
|
},
|
||||||
|
RootFs: rootfs,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
testingImpl.ListSandboxFunc = nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.String("format", "table", "")
|
||||||
|
ctx := createCLIContext(set)
|
||||||
|
ctx.App.Name = "foo"
|
||||||
|
|
||||||
|
runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||||
|
|
||||||
|
fn, ok := listCLICommand.Action.(func(context *cli.Context) error)
|
||||||
|
assert.True(ok)
|
||||||
|
|
||||||
|
err = fn(ctx)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// remove container rootfs, check list command should also work
|
||||||
|
assert.NoError(os.RemoveAll(rootfs))
|
||||||
|
err = fn(ctx)
|
||||||
|
assert.NoError(err)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user