Skip to content

Commit 4bb6714

Browse files
committed
Validate container status in volume mount tests
We fixed an issue in CRI-O returning an invalid container status on different mount propagations: cri-o/cri-o#5981 To avoid such failures everywhere, we now also validate the container status in critest. Signed-off-by: Sascha Grunert <[email protected]>
1 parent 8bf6347 commit 4bb6714

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

pkg/framework/test_context.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ var TestContext TestContextType
120120
// DefaultRegistryPrefix specifies the default prefix used for images
121121
const DefaultRegistryPrefix = "docker.io/library"
122122

123+
const DockerShimSockPathUnix = "unix:///var/run/dockershim.sock"
124+
const DockerShimSockPathWindows = "npipe:////./pipe/dockershim"
125+
123126
// RegisterFlags registers flags to e2e test suites.
124127
func RegisterFlags() {
125128
suite, reporter := ginkgo.GinkgoConfiguration()
@@ -139,10 +142,10 @@ func RegisterFlags() {
139142
flag.StringVar(&testImagesFilePath, "test-images-file", "", "Optional path to a YAML file containing references to custom container images to be used in tests.")
140143
flag.DurationVar(&TestContext.ImageServiceTimeout, "image-service-timeout", 300*time.Second, "Timeout when trying to connect to image service.")
141144

142-
svcaddr := "unix:///var/run/dockershim.sock"
145+
svcaddr := DockerShimSockPathUnix
143146
defaultConfigPath := "/etc/crictl.yaml"
144147
if runtime.GOOS == "windows" {
145-
svcaddr = "npipe:////./pipe/dockershim"
148+
svcaddr = DockerShimSockPathWindows
146149
defaultConfigPath = filepath.Join(os.Getenv("USERPROFILE"), ".crictl", "crictl.yaml")
147150
}
148151
flag.StringVar(&TestContext.ConfigPath, "config", defaultConfigPath, "Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well")

pkg/validate/container_linux.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,18 @@ func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.M
211211
return mntSource, propagationSrcDir, propagationMntPoint, clearHostPath
212212
}
213213

214-
// createMountPropagationContainer creates a container with volume and Privileged and fails if it gets error.
215-
func createMountPropagationContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix string, podID string,
216-
podConfig *runtimeapi.PodSandboxConfig, hostPath string, PropagationOpt runtimeapi.MountPropagation) string {
214+
// createMountPropagationContainer creates a container with volume and
215+
// privileged security constraints. It also validates the container status
216+
// after creation and fails if any error occurs.
217+
func createMountPropagationContainer(
218+
rc internalapi.RuntimeService,
219+
ic internalapi.ImageManagerService,
220+
prefix string,
221+
podID string,
222+
podConfig *runtimeapi.PodSandboxConfig,
223+
hostPath string,
224+
propagation runtimeapi.MountPropagation,
225+
) string {
217226
By("create a container with volume and name")
218227
containerName := prefix + framework.NewUUID()
219228
containerConfig := &runtimeapi.ContainerConfig{
@@ -230,12 +239,30 @@ func createMountPropagationContainer(rc internalapi.RuntimeService, ic internala
230239
{
231240
HostPath: hostPath,
232241
ContainerPath: hostPath,
233-
Propagation: PropagationOpt,
242+
Propagation: propagation,
234243
},
235244
},
236245
}
237246

238-
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
247+
containerID := framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
248+
249+
By("verifying container status")
250+
resp, err := rc.ContainerStatus(containerID, true)
251+
framework.ExpectNoError(err, "unable to get container status")
252+
Expect(len(resp.Status.Mounts), 1)
253+
Expect(resp.Status.Mounts[0].ContainerPath).To(Equal(hostPath))
254+
Expect(resp.Status.Mounts[0].HostPath).To(Equal(hostPath))
255+
Expect(resp.Status.Mounts[0].Readonly).To(BeFalse())
256+
Expect(resp.Status.Mounts[0].SelinuxRelabel).To(BeFalse())
257+
258+
// NOTE: dockershim does not populate that field, so we do not have to test it
259+
if framework.TestContext.RuntimeServiceAddr != framework.DockerShimSockPathUnix &&
260+
framework.TestContext.RuntimeServiceAddr != framework.DockerShimSockPathWindows {
261+
By("verifying container status mount propagation")
262+
Expect(resp.Status.Mounts[0].Propagation).To(Equal(propagation))
263+
}
264+
265+
return containerID
239266
}
240267

241268
// createPropagationMountPoint mount "propagationSrcDir" at "propagationMntPoint",

0 commit comments

Comments
 (0)