Skip to content

Commit f3e8114

Browse files
committed
Shorten long directory names
1 parent d52c1ca commit f3e8114

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

openshift-hack/e2e/annotate/generated/zz_generated.annotations.go

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/storage/csimock/csi_selinux_mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
9191
m := newMockDriverSetup(f)
9292
recursive := v1.SELinuxChangePolicyRecursive
9393
mount := v1.SELinuxChangePolicyMountOption
94-
f.Context("SELinuxMount [LinuxOnly]", feature.SELinux, func() {
94+
f.Context("SELinuxMount [LinuxOnly] with a really really really really really really really long test name with ~160 characters to check how the directory shortening works", feature.SELinux, func() {
9595
processLabel, fileLabel := getDefaultContainerSELinuxLabels()
9696
// Make sure all options are set so system specific defaults are not used.
9797
seLinuxOpts1 := v1.SELinuxOptions{

test/e2e/storage/utils/pod.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package utils
1919
import (
2020
"context"
2121
"fmt"
22+
"hash/crc32"
2223
"io"
2324
"os"
2425
"path"
26+
"path/filepath"
2527
"regexp"
26-
"strings"
2728

2829
"github.com/onsi/ginkgo/v2"
2930
"github.com/onsi/gomega"
@@ -68,6 +69,19 @@ func StartPodLogs(ctx context.Context, f *framework.Framework, driverNamespace *
6869
testName = append(testName, reg.ReplaceAllString(test.LeafNodeText, "_"))
6970
}
7071
}
72+
73+
// Make sure each directory name is short enough for Linux + Windows
74+
const maxDirectoryLength = 255
75+
for i, testNameComponent := range testName {
76+
if len(testNameComponent) > maxDirectoryLength {
77+
hash := crc32.ChecksumIEEE([]byte(testNameComponent))
78+
hashString := fmt.Sprintf("%x", hash)
79+
hashLen := len(hashString)
80+
newTestNameComponent := fmt.Sprintf("%s-%s", testName[:maxDirectoryLength-1-hashLen-1], hashString)
81+
testName[i] = newTestNameComponent
82+
}
83+
}
84+
7185
// We end the prefix with a slash to ensure that all logs
7286
// end up in a directory named after the current test.
7387
//
@@ -76,7 +90,7 @@ func StartPodLogs(ctx context.Context, f *framework.Framework, driverNamespace *
7690
// keeps each directory name smaller (the full test
7791
// name at one point exceeded 256 characters, which was
7892
// too much for some filesystems).
79-
logDir := framework.TestContext.ReportDir + "/" + strings.Join(testName, "/")
93+
logDir := filepath.Join(framework.TestContext.ReportDir, filepath.Join(testName...))
8094
to.LogPathPrefix = logDir + "/"
8195

8296
err := os.MkdirAll(logDir, 0755)

0 commit comments

Comments
 (0)