Skip to content

Commit 39b65b5

Browse files
Merge pull request #29979 from stbenjam/csi-fix
OCPBUGS-59157: Ensure CSI tests are defined before OTE initialization
2 parents 6251391 + e0a2fbc commit 39b65b5

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

pkg/clioptions/clusterdiscovery/csi.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"github.com/openshift/origin/test/extended/storage/csi"
109
"k8s.io/apimachinery/pkg/util/sets"
1110
"k8s.io/kubernetes/test/e2e/framework/testfiles"
1211
"k8s.io/kubernetes/test/e2e/storage/external"
1312
"sigs.k8s.io/yaml"
13+
14+
"github.com/openshift/origin/test/extended/storage/csi"
1415
)
1516

1617
const (
1718
CSIManifestEnvVar = "TEST_CSI_DRIVER_FILES"
1819
OCPManifestEnvVar = "TEST_OCP_CSI_DRIVER_FILES"
1920
)
2021

21-
// Initialize openshift/csi suite, i.e. define CSI tests from TEST_CSI_DRIVER_FILES.
22-
func initCSITests() error {
22+
// InitCSITests initializes the openshift/csi suite, i.e. define CSI tests from TEST_CSI_DRIVER_FILES.
23+
func InitCSITests() error {
2324
ocpDrivers := sets.New[string]()
2425
upstreamDrivers := sets.New[string]()
2526

pkg/clioptions/clusterdiscovery/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func InitializeTestFramework(context *e2e.TestContextType, config *ClusterConfig
5858
// allow the CSI tests to access test data, but only briefly
5959
// TODO: ideally CSI would not use any of these test methods
6060
var err error
61-
exutil.WithCleanup(func() { err = initCSITests() })
61+
exutil.WithCleanup(func() { err = InitCSITests() })
6262
if err != nil {
6363
return err
6464
}

pkg/test/extensions/binary.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func InitializeOpenShiftTestsExtensionFramework() (*extension.Registry, *extensi
7070
extensionRegistry := extension.NewRegistry()
7171
extensionRegistry.Register(originExtension.Extension)
7272

73+
err := clusterdiscovery.InitCSITests()
74+
if err != nil {
75+
return nil, nil, err
76+
}
77+
7378
// Build our specs from ginkgo
7479
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
7580
if err != nil {
@@ -190,7 +195,22 @@ func (b *TestBinary) Info(ctx context.Context) (*Extension, error) {
190195
logrus.Errorf("Command output for %s: %s", binName, string(infoJson))
191196
return nil, fmt.Errorf("failed running '%s info': %w\nOutput: %s", b.binaryPath, err, infoJson)
192197
}
193-
jsonBegins := bytes.IndexByte(infoJson, '{')
198+
// Some binaries may output logging that includes JSON-like data, so we need to find the first line that starts with '{'
199+
jsonBegins := -1
200+
lines := bytes.Split(infoJson, []byte("\n"))
201+
for i, line := range lines {
202+
trimmed := bytes.TrimSpace(line)
203+
if bytes.HasPrefix(trimmed, []byte("{")) {
204+
// Calculate the byte offset of this line in the original output
205+
jsonBegins = 0
206+
for j := 0; j < i; j++ {
207+
jsonBegins += len(lines[j]) + 1 // +1 for the newline character
208+
}
209+
jsonBegins += len(line) - len(trimmed) // Add any leading whitespace
210+
break
211+
}
212+
}
213+
194214
jsonEnds := bytes.LastIndexByte(infoJson, '}')
195215
if jsonBegins == -1 || jsonEnds == -1 || jsonBegins > jsonEnds {
196216
logrus.Errorf("No valid JSON found in output from %s info command", binName)

0 commit comments

Comments
 (0)