11package disruptionpodnetwork
22
33import (
4- "bytes"
54 "context"
65 "errors"
76 "fmt"
7+ "github.com/openshift/origin/pkg/test/extensions"
88 "io/ioutil"
99 "os"
10- "os/exec"
1110 "strings"
1211 "time"
1312
1413 "github.com/sirupsen/logrus"
1514
16- configclient "github.com/openshift/client-go/config/clientset/versioned"
1715 exutil "github.com/openshift/origin/test/extended/util"
1816 apierrors "k8s.io/apimachinery/pkg/api/errors"
1917 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -24,35 +22,25 @@ import (
2422// IN ginkgo environment, oc needs to be created before BeforeEach and passed in
2523func GetOpenshiftTestsImagePullSpec (ctx context.Context , adminRESTConfig * rest.Config , suggestedPayloadImage string , oc * exutil.CLI ) (string , error ) {
2624 if len (suggestedPayloadImage ) == 0 {
27- configClient , err := configclient .NewForConfig (adminRESTConfig )
25+ var err error
26+ suggestedPayloadImage , err = extensions .DetermineReleasePayloadImage ()
2827 if err != nil {
2928 return "" , err
3029 }
31- clusterVersion , err := configClient .ConfigV1 ().ClusterVersions ().Get (ctx , "version" , metav1.GetOptions {})
32- if apierrors .IsNotFound (err ) {
33- return "" , fmt .Errorf ("clusterversion/version not found and no image pull spec specified" )
34- }
35- if err != nil {
36- return "" , err
37- }
38- suggestedPayloadImage = clusterVersion .Status .History [0 ].Image
3930 }
4031
4132 logrus .Infof ("payload image reported by CV: %v\n " , suggestedPayloadImage )
4233 // runImageExtract extracts src from specified image to dst
43- cmd := exec .Command ("oc" , "adm" , "release" , "info" , suggestedPayloadImage , "--image-for=tests" )
44- out := & bytes.Buffer {}
45- outStr := ""
46- errOut := & bytes.Buffer {}
47- cmd .Stdout = out
48- cmd .Stderr = errOut
49- if err := cmd .Run (); err != nil {
50- logrus .WithError (err ).Errorf ("unable to determine openshift-tests image through exec: %v" , errOut .String ())
34+
35+ // Extract the openshift-tests image from the release payload
36+ openshiftTestsImagePullSpec , err := extensions .ExtractImageFromReleasePayload (suggestedPayloadImage , "tests" )
37+ if err != nil {
38+ logrus .WithError (err ).Errorf ("unable to determine openshift-tests image through ExtractImageFromReleasePayload: %v" , err )
5139 // Now try the wrapper to see if it makes a difference
5240 if oc == nil {
5341 oc = exutil .NewCLIWithoutNamespace ("openshift-tests" )
5442 }
55- outStr , err = oc .Run ("adm" , "release" , "info" , suggestedPayloadImage ).Args ("--image-for=tests" ).Output ()
43+ outStr , err : = oc .Run ("adm" , "release" , "info" , suggestedPayloadImage ).Args ("--image-for=tests" ).Output ()
5644 if err != nil {
5745 logrus .WithError (err ).Errorf ("unable to determine openshift-tests image through oc wrapper with default ps: %v" , outStr )
5846
@@ -130,11 +118,9 @@ func GetOpenshiftTestsImagePullSpec(ctx context.Context, adminRESTConfig *rest.C
130118 } else {
131119 logrus .Infof ("successfully getting image for test with oc wrapper with default ps: %s\n " , outStr )
132120 }
133- } else {
134- outStr = out .String ()
135- }
136121
137- openshiftTestsImagePullSpec := strings .TrimSpace (outStr )
122+ openshiftTestsImagePullSpec = strings .TrimSpace (outStr )
123+ }
138124 fmt .Printf ("openshift-tests image pull spec is %v\n " , openshiftTestsImagePullSpec )
139125
140126 return openshiftTestsImagePullSpec , nil
0 commit comments