Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ type containerTestArgs struct {
}

const (
testCtr = "TestCtr"
testCrictl = "TestCrictl"
testDocker = "TestDocker"
testNerdctl = "TestNerdctl"
testCtr = "TestCtr"
testCrictl = "TestCrictl"
testDocker = "TestDocker"
testNerdctl = "TestNerdctl"
testNamespace = "urunc-test"
)

var errToolDoesNotSupport = errors.New("Operation not support")
Expand Down
17 changes: 9 additions & 8 deletions tests/e2e/ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

const ctrName = "ctr"
const ctrCmd = ctrName + " --namespace " + testNamespace

type ctrInfo struct {
testArgs containerTestArgs
Expand Down Expand Up @@ -90,7 +91,7 @@ func (i *ctrInfo) createPod() (string, error) {
}

func (i *ctrInfo) createContainer() (string, error) {
cmdBase := ctrName
cmdBase := ctrCmd
cmdBase += " c create "
cmdBase += ctrNewContainerCmd(i.testArgs)
return commonCmdExec(cmdBase)
Expand All @@ -106,11 +107,11 @@ func (i *ctrInfo) startContainer(detach bool) (string, error) {
if detach {
i.detached = true
}
return commonStart(ctrName+" t", i.containerID, detach)
return commonStart(ctrCmd+" t", i.containerID, detach)
}

func (i *ctrInfo) runContainer(detach bool) (string, error) {
cmdBase := ctrName
cmdBase := ctrCmd
cmdBase += " run "
if detach {
cmdBase += "-d "
Expand All @@ -124,7 +125,7 @@ func (i *ctrInfo) stopContainer() error {
if !i.detached {
return nil
}
cmdBase := ctrName
cmdBase := ctrCmd
cmdBase += " t kill "
cmdBase += i.containerID
output, err := commonCmdExec(cmdBase)
Expand All @@ -141,12 +142,12 @@ func (i *ctrInfo) stopPod() error {
}

func (i *ctrInfo) rmContainer() error {
output, err := commonRmContainer(ctrName+" c", i.containerID)
output, err := commonRmContainer(ctrCmd+" c", i.containerID)
err = checkExpectedOut("", output, err)
if err != nil {
return fmt.Errorf("Failed to remove %s: %v", i.containerID, err)
}
output, err = commonRmContainer(ctrName+" s", i.testArgs.Name)
output, err = commonRmContainer(ctrCmd+" s", i.testArgs.Name)
err = checkExpectedOut("", output, err)
if err != nil {
return fmt.Errorf("Failed to remove snapshot %s: %v", i.testArgs.Name, err)
Expand All @@ -168,7 +169,7 @@ func (i *ctrInfo) logContainer() (string, error) {
}

func (i *ctrInfo) searchContainer(cID string) (bool, error) {
cmd := ctrName + " c ls -q"
cmd := ctrCmd + " c ls -q"

output, err := commonCmdExec(cmd)
if err != nil {
Expand All @@ -183,7 +184,7 @@ func (i *ctrInfo) searchPod(string) (bool, error) {
}

func (i *ctrInfo) inspectCAndGet(key string) (string, error) {
cmdBase := ctrName
cmdBase := ctrCmd
cmdBase += " c info "
cmdBase += i.containerID
output, err := commonCmdExec(cmdBase)
Expand Down
17 changes: 9 additions & 8 deletions tests/e2e/nerdctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

const nerdctlName = "nerdctl"
const nerdctlCmd = nerdctlName + " --namespace " + testNamespace

type nerdctlInfo struct {
testArgs containerTestArgs
Expand Down Expand Up @@ -63,7 +64,7 @@ func (i *nerdctlInfo) createPod() (string, error) {
}

func (i *nerdctlInfo) createContainer() (string, error) {
return commonCreate(nerdctlName, i.testArgs)
return commonCreate(nerdctlCmd, i.testArgs)
}

// nolint:unused
Expand All @@ -73,15 +74,15 @@ func (i *nerdctlInfo) startPod() (string, error) {
}

func (i *nerdctlInfo) startContainer(detach bool) (string, error) {
return commonStart(nerdctlName, i.containerID, detach)
return commonStart(nerdctlCmd, i.containerID, detach)
}

func (i *nerdctlInfo) runContainer(detach bool) (string, error) {
return commonRun(nerdctlName, i.testArgs, detach)
return commonRun(nerdctlCmd, i.testArgs, detach)
}

func (i *nerdctlInfo) stopContainer() error {
output, err := commonStopContainer(nerdctlName, i.containerID)
output, err := commonStopContainer(nerdctlCmd, i.containerID)
err = checkExpectedOut(i.containerID, output, err)
if err != nil {
return fmt.Errorf("Failed to stop %s: %v", i.containerID, err)
Expand All @@ -95,7 +96,7 @@ func (i *nerdctlInfo) stopPod() error {
}

func (i *nerdctlInfo) rmContainer() error {
output, err := commonRmContainer(nerdctlName, i.containerID)
output, err := commonRmContainer(nerdctlCmd, i.containerID)
err = checkExpectedOut(i.containerID, output, err)
if err != nil {
return fmt.Errorf("Failed to stop %s: %v", i.containerID, err)
Expand All @@ -109,11 +110,11 @@ func (i *nerdctlInfo) rmPod() error {
}

func (i *nerdctlInfo) logContainer() (string, error) {
return commonLogs(nerdctlName, i.containerID)
return commonLogs(nerdctlCmd, i.containerID)
}

func (i *nerdctlInfo) searchContainer(cID string) (bool, error) {
return commonSearchContainer(nerdctlName, cID)
return commonSearchContainer(nerdctlCmd, cID)
}

func (i *nerdctlInfo) searchPod(string) (bool, error) {
Expand All @@ -122,7 +123,7 @@ func (i *nerdctlInfo) searchPod(string) (bool, error) {
}

func (i *nerdctlInfo) inspectCAndGet(key string) (string, error) {
return commonInspectCAndGet(nerdctlName, i.containerID, key)
return commonInspectCAndGet(nerdctlCmd, i.containerID, key)
}

func (i *nerdctlInfo) inspectPAndGet(string) (string, error) {
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ const (
defaultInterval = 1 * time.Second
)

var _ = BeforeSuite(func() {
_, err := commonCmdExec("ctr namespaces create " + testNamespace)
if err != nil {
GinkgoLogr.Info("namespace setup: " + err.Error())
}
})

var _ = AfterSuite(func() {
_, err := commonCmdExec("ctr namespaces remove " + testNamespace)
if err != nil {
GinkgoLogr.Error(err, "failed to remove namespace "+testNamespace+"; manual cleanup may be required")
}
})

func TestE2E(t *testing.T) {
format.MaxLength = 0 // Do not truncate failure output
RegisterFailHandler(Fail)
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/test_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,19 @@ func namespaceTest(tool testTool) error {
// We need to retrieve the container's config, in order to get
// the namespaces that the container should have joined.
containerID := tool.getContainerID()
// Try /run/containerd/io.containerd.runtime.v2.task/default/containerID first
configPath := filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/default/", containerID, "/config.json")
// Try testNamespace first, then fall back to default, k8s.io, and moby.
configPath := filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/"+testNamespace+"/", containerID, "/config.json")
_, err := os.Stat(configPath)
if os.IsNotExist(err) {
configPath = filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/k8s.io/", containerID, "/config.json")
configPath = filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/default/", containerID, "/config.json")
_, err = os.Stat(configPath)
if os.IsNotExist(err) {
configPath = filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/moby/", containerID, "/config.json")
configPath = filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/k8s.io/", containerID, "/config.json")
_, err = os.Stat(configPath)
if os.IsNotExist(err) {
configPath = filepath.Join("/var/run/containerd/io.containerd.runtime.v2.task/moby/", containerID, "/config.json")
_, err = os.Stat(configPath)
}
}
}
if err != nil {
Expand Down
15 changes: 11 additions & 4 deletions tests/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func pullImageForTest(testFunc string, image string) error {
}
return nil
case testNerdctl:
return commonPull(nerdctlName, image)
return commonPull(nerdctlCmd, image)
case testDocker:
return commonPull(dockerName, image)
default:
return commonPull(ctrName, image)
return commonPull(ctrCmd, image)
}
}

Expand All @@ -106,11 +106,11 @@ func removeImageForTest(testFunc string, image string) error {
}
return nil
case testNerdctl:
return commonRmImage(nerdctlName, image)
return commonRmImage(nerdctlCmd, image)
case testDocker:
return commonRmImage(dockerName, image)
default:
return commonRmImage(ctrName, image)
return commonRmImage(ctrCmd, image)
}
}

Expand Down Expand Up @@ -224,6 +224,13 @@ func verifyNoStaleFiles(containerID string) error {
return fmt.Errorf("bundle directory %s still exists", dirPath)
}

// Check /run/containerd/io.containerd.runtime.v2.task/urunc-test/containerID directory does not exist
dirPath = "/run/containerd/io.containerd.runtime.v2.task/" + testNamespace + "/" + containerID
_, err = os.Stat(dirPath)
if !os.IsNotExist(err) {
return fmt.Errorf("bundle directory %s still exists", dirPath)
}

return nil
}

Expand Down