Skip to content

Commit

Permalink
Fix nonroot tests
Browse files Browse the repository at this point in the history
Signed-off-by: L. Pivarc <[email protected]>
  • Loading branch information
xpivarc committed Oct 26, 2022
1 parent 097521a commit 6932d31
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/host-disk/host-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func shouldSkipVolumeSource(passthoughFSVolumes map[string]struct{}, hotplugVolu

volumeStatus, ok := pvcVolume[volumeName]
if !ok || types.IsPVCBlock(volumeStatus.PersistentVolumeClaimInfo.VolumeMode) {

log.Log.V(4).Infof("this volume %s is block, will not be replaced by HostDisk", volumeName)
// This is not a disk on a file system, so skip it.
return true
}
Expand Down
25 changes: 15 additions & 10 deletions tests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,15 +1753,20 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
Context("[Serial] migration to nonroot", func() {
var dv *cdiv1.DataVolume
size := "256Mi"
var clusterIsRoot bool

BeforeEach(func() {
if !checks.HasFeature(virtconfig.NonRoot) {
Skip("Test specific to NonRoot featureGate that is not enabled")
clusterIsRoot = checks.HasFeature(virtconfig.Root)
if !clusterIsRoot {
tests.EnableFeatureGate(virtconfig.Root)
}
tests.DisableFeatureGate(virtconfig.NonRoot)
})
AfterEach(func() {
tests.EnableFeatureGate(virtconfig.NonRoot)
if !clusterIsRoot {
tests.DisableFeatureGate(virtconfig.Root)
} else {
tests.EnableFeatureGate(virtconfig.Root)
}
libstorage.DeleteDataVolume(&dv)
})

Expand All @@ -1779,7 +1784,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
By("Checking that the launcher is running as root")
Expect(tests.GetIdOfLauncher(vmi)).To(Equal("0"))

tests.EnableFeatureGate(virtconfig.NonRoot)
tests.DisableFeatureGate(virtconfig.Root)

By("Starting new migration and waiting for it to succeed")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
Expand Down Expand Up @@ -1833,16 +1838,16 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
size := "256Mi"

BeforeEach(func() {
clusterIsRoot = !checks.HasFeature(virtconfig.NonRoot)
clusterIsRoot = checks.HasFeature(virtconfig.Root)
if clusterIsRoot {
tests.EnableFeatureGate(virtconfig.NonRoot)
tests.DisableFeatureGate(virtconfig.Root)
}
})
AfterEach(func() {
if clusterIsRoot {
tests.DisableFeatureGate(virtconfig.NonRoot)
tests.EnableFeatureGate(virtconfig.Root)
} else {
tests.EnableFeatureGate(virtconfig.NonRoot)
tests.DisableFeatureGate(virtconfig.Root)
}
if dv != nil {
libstorage.DeleteDataVolume(&dv)
Expand All @@ -1864,7 +1869,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
By("Checking that the launcher is running as root")
Expect(tests.GetIdOfLauncher(vmi)).To(Equal("107"))

tests.DisableFeatureGate(virtconfig.NonRoot)
tests.EnableFeatureGate(virtconfig.Root)

By("Starting new migration and waiting for it to succeed")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
Expand Down
2 changes: 1 addition & 1 deletion tests/security_features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var _ = Describe("[Serial][sig-compute]SecurityFeatures", func() {
}
}
caps := *container.SecurityContext.Capabilities
if checks.HasFeature(virtconfig.NonRoot) {
if !checks.HasFeature(virtconfig.Root) {
Expect(caps.Add).To(HaveLen(2), fmt.Sprintf("Found capabilities %s, expected NET_BIND_SERVICE and SYS_PTRACE", caps.Add))
Expect(caps.Add).To(ContainElements(k8sv1.Capability("NET_BIND_SERVICE"), k8sv1.Capability("SYS_PTRACE")))
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ func CreateHostDiskImage(diskPath string) *k8sv1.Pod {
dir := filepath.Dir(diskPath)

command := fmt.Sprintf(`dd if=/dev/zero of=%s bs=1 count=0 seek=1G && ls -l %s`, diskPath, dir)
if checks.HasFeature(virtconfig.NonRoot) {
if !checks.HasFeature(virtconfig.Root) {
command = command + fmt.Sprintf(" && chown 107:107 %s", diskPath)
}

Expand Down

0 comments on commit 6932d31

Please sign in to comment.