Skip to content

Commit 018cc39

Browse files
Merge pull request #28425 from stbenjam/skip-function
TRT-1347: Add ability to indicate a monitor test was skipped
2 parents c782a30 + 1e6c579 commit 018cc39

File tree

8 files changed

+216
-100
lines changed

8 files changed

+216
-100
lines changed

pkg/monitortestframework/errors.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package monitortestframework
2+
3+
import "fmt"
4+
5+
// NotSupportedError represents an error when a monitor test is unsupported for the given environment.
6+
type NotSupportedError struct {
7+
Reason string
8+
}
9+
10+
func (e *NotSupportedError) Error() string {
11+
return fmt.Sprintf("not supported: %s", e.Reason)
12+
}

pkg/monitortestframework/impl.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package monitortestframework
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"os"
78
"strings"
@@ -94,6 +95,17 @@ func (r *monitorTestRegistry) StartCollection(ctx context.Context, adminRESTConf
9495
end := time.Now()
9596
duration := end.Sub(start)
9697
if err != nil {
98+
var nsErr *NotSupportedError
99+
if errors.As(err, &nsErr) {
100+
junitCh <- &junitapi.JUnitTestCase{
101+
Name: testName,
102+
Duration: duration.Seconds(),
103+
SkipMessage: &junitapi.SkipMessage{
104+
Message: nsErr.Reason,
105+
},
106+
}
107+
return
108+
}
97109
errCh <- err
98110
junitCh <- &junitapi.JUnitTestCase{
99111
Name: testName,
@@ -149,6 +161,19 @@ func (r *monitorTestRegistry) CollectData(ctx context.Context, storageDir string
149161
end := time.Now()
150162
duration := end.Sub(start)
151163
if err != nil {
164+
var nsErr *NotSupportedError
165+
if errors.As(err, &nsErr) {
166+
junitCh <- []*junitapi.JUnitTestCase{
167+
{
168+
Name: testName,
169+
Duration: duration.Seconds(),
170+
SkipMessage: &junitapi.SkipMessage{
171+
Message: nsErr.Reason,
172+
},
173+
},
174+
}
175+
return
176+
}
152177
junitCh <- []*junitapi.JUnitTestCase{
153178
{
154179
Name: testName,
@@ -206,6 +231,18 @@ func (r *monitorTestRegistry) ConstructComputedIntervals(ctx context.Context, st
206231
end := time.Now()
207232
duration := end.Sub(start)
208233
if err != nil {
234+
var nsErr *NotSupportedError
235+
if errors.As(err, &nsErr) {
236+
junits = append(junits, &junitapi.JUnitTestCase{
237+
Name: testName,
238+
Duration: duration.Seconds(),
239+
SkipMessage: &junitapi.SkipMessage{
240+
Message: nsErr.Reason,
241+
},
242+
})
243+
continue
244+
}
245+
209246
errs = append(errs, err)
210247
junits = append(junits, &junitapi.JUnitTestCase{
211248
Name: testName,
@@ -240,6 +277,18 @@ func (r *monitorTestRegistry) EvaluateTestsFromConstructedIntervals(ctx context.
240277
end := time.Now()
241278
duration := end.Sub(start)
242279
if err != nil {
280+
var nsErr *NotSupportedError
281+
if errors.As(err, &nsErr) {
282+
junits = append(junits, &junitapi.JUnitTestCase{
283+
Name: testName,
284+
Duration: duration.Seconds(),
285+
SkipMessage: &junitapi.SkipMessage{
286+
Message: nsErr.Reason,
287+
},
288+
})
289+
continue
290+
}
291+
243292
errs = append(errs, err)
244293
junits = append(junits, &junitapi.JUnitTestCase{
245294
Name: testName,
@@ -282,6 +331,18 @@ func (r *monitorTestRegistry) WriteContentToStorage(ctx context.Context, storage
282331
end := time.Now()
283332
duration := end.Sub(start)
284333
if err != nil {
334+
var nsErr *NotSupportedError
335+
if errors.As(err, &nsErr) {
336+
junits = append(junits, &junitapi.JUnitTestCase{
337+
Name: testName,
338+
Duration: duration.Seconds(),
339+
SkipMessage: &junitapi.SkipMessage{
340+
Message: nsErr.Reason,
341+
},
342+
})
343+
continue
344+
}
345+
285346
errs = append(errs, err)
286347
junits = append(junits, &junitapi.JUnitTestCase{
287348
Name: testName,
@@ -315,6 +376,18 @@ func (r *monitorTestRegistry) Cleanup(ctx context.Context) ([]*junitapi.JUnitTes
315376
end := time.Now()
316377
duration := end.Sub(start)
317378
if err != nil {
379+
var nsErr *NotSupportedError
380+
if errors.As(err, &nsErr) {
381+
junits = append(junits, &junitapi.JUnitTestCase{
382+
Name: testName,
383+
Duration: duration.Seconds(),
384+
SkipMessage: &junitapi.SkipMessage{
385+
Message: nsErr.Reason,
386+
},
387+
})
388+
continue
389+
}
390+
318391
errs = append(errs, err)
319392
junits = append(junits, &junitapi.JUnitTestCase{
320393
Name: testName,

pkg/monitortests/imageregistry/disruptionimageregistry/monitortest.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import (
1212

1313
routev1 "github.com/openshift/api/route/v1"
1414
routeclient "github.com/openshift/client-go/route/clientset/versioned"
15-
"github.com/openshift/origin/pkg/monitor/backenddisruption"
16-
"github.com/openshift/origin/pkg/monitor/monitorapi"
17-
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
18-
"github.com/openshift/origin/test/extended/util/imageregistryutil"
1915
apierrors "k8s.io/apimachinery/pkg/api/errors"
2016
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2117
"k8s.io/client-go/kubernetes"
2218
"k8s.io/client-go/rest"
19+
20+
"github.com/openshift/origin/pkg/monitor/backenddisruption"
21+
"github.com/openshift/origin/pkg/monitor/monitorapi"
22+
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
23+
"github.com/openshift/origin/test/extended/util/imageregistryutil"
2324
)
2425

2526
const (
@@ -33,7 +34,7 @@ type availability struct {
3334
imageRegistryRoute *routev1.Route
3435

3536
disruptionChecker *disruptionlibrary.Availability
36-
notSupportedReason string
37+
notSupportedReason error
3738
suppressJunit bool
3839
}
3940

@@ -51,6 +52,7 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
5152
var err error
5253

5354
namespace := "openshift-image-registry"
55+
imageRegistryDeploymentName := "image-registry"
5456

5557
w.kubeClient, err = kubernetes.NewForConfig(adminRESTConfig)
5658
if err != nil {
@@ -59,13 +61,22 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
5961

6062
_, err = w.kubeClient.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
6163
if apierrors.IsNotFound(err) {
62-
w.notSupportedReason = "namespace openshift-image-registry not present"
63-
return nil
64+
w.notSupportedReason = &monitortestframework.NotSupportedError{Reason: "namespace openshift-image-registry not present"}
65+
return w.notSupportedReason
6466
}
6567
if err != nil {
6668
return err
6769
}
6870

71+
deployment, err := w.kubeClient.AppsV1().Deployments(namespace).Get(ctx, imageRegistryDeploymentName, metav1.GetOptions{})
72+
if err != nil {
73+
return err
74+
}
75+
if deployment.Spec.Replicas != nil && *deployment.Spec.Replicas == 1 {
76+
w.notSupportedReason = &monitortestframework.NotSupportedError{Reason: "image-registry only has a single replica"}
77+
return w.notSupportedReason
78+
}
79+
6980
w.routeClient, err = routeclient.NewForConfig(adminRESTConfig)
7081
if err != nil {
7182
return err
@@ -104,8 +115,8 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
104115
}
105116

106117
func (w *availability) CollectData(ctx context.Context, storageDir string, beginning, end time.Time) (monitorapi.Intervals, []*junitapi.JUnitTestCase, error) {
107-
if len(w.notSupportedReason) > 0 {
108-
return nil, nil, nil
118+
if w.notSupportedReason != nil {
119+
return nil, nil, w.notSupportedReason
109120
}
110121
// we failed and indicated it during setup.
111122
if w.disruptionChecker == nil {
@@ -120,8 +131,8 @@ func (*availability) ConstructComputedIntervals(ctx context.Context, startingInt
120131
}
121132

122133
func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context, finalIntervals monitorapi.Intervals) ([]*junitapi.JUnitTestCase, error) {
123-
if len(w.notSupportedReason) > 0 {
124-
return nil, nil
134+
if w.notSupportedReason != nil {
135+
return nil, w.notSupportedReason
125136
}
126137
if w.suppressJunit {
127138
return nil, nil
@@ -134,8 +145,8 @@ func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context
134145
return w.disruptionChecker.EvaluateTestsFromConstructedIntervals(ctx, finalIntervals)
135146
}
136147

137-
func (*availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
138-
return nil
148+
func (w *availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
149+
return w.notSupportedReason
139150
}
140151

141152
func (w *availability) Cleanup(ctx context.Context) error {
@@ -146,5 +157,5 @@ func (w *availability) Cleanup(ctx context.Context) error {
146157
}
147158
}
148159

149-
return nil
160+
return w.notSupportedReason
150161
}

pkg/monitortests/kubeapiserver/disruptionlegacyapiservers/monitortest.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ import (
88

99
"github.com/openshift/origin/pkg/monitortestframework"
1010

11-
"github.com/openshift/origin/pkg/monitor/monitorapi"
12-
"github.com/openshift/origin/pkg/monitortestlibrary/disruptionlibrary"
13-
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
1411
apierrors "k8s.io/apimachinery/pkg/api/errors"
1512
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1613
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1714
"k8s.io/client-go/kubernetes"
1815
"k8s.io/client-go/rest"
16+
17+
"github.com/openshift/origin/pkg/monitor/monitorapi"
18+
"github.com/openshift/origin/pkg/monitortestlibrary/disruptionlibrary"
19+
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
1920
)
2021

2122
type availability struct {
2223
disruptionCheckers []*disruptionlibrary.Availability
2324

24-
notSupportedReason string
25+
notSupportedReason error
2526
suppressJunit bool
2627
}
2728

@@ -157,16 +158,20 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
157158

158159
_, err = kubeClient.CoreV1().Namespaces().Get(context.Background(), "openshift-apiserver", metav1.GetOptions{})
159160
if apierrors.IsNotFound(err) {
160-
w.notSupportedReason = "namespace openshift-apiserver not present"
161-
return nil
161+
w.notSupportedReason = &monitortestframework.NotSupportedError{
162+
Reason: "namespace openshift-apiserver not present",
163+
}
164+
return w.notSupportedReason
162165
}
163166
if err != nil {
164167
return err
165168
}
166169
_, err = kubeClient.CoreV1().Namespaces().Get(context.Background(), "openshift-oauth-apiserver", metav1.GetOptions{})
167170
if apierrors.IsNotFound(err) {
168-
w.notSupportedReason = "namespace openshift-oauth-apiserver not present"
169-
return nil
171+
w.notSupportedReason = &monitortestframework.NotSupportedError{
172+
Reason: "namespace openshift-oauth-apiserver not present",
173+
}
174+
return w.notSupportedReason
170175
}
171176
if err != nil {
172177
return err
@@ -217,6 +222,10 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
217222
}
218223

219224
func (w *availability) CollectData(ctx context.Context, storageDir string, beginning, end time.Time) (monitorapi.Intervals, []*junitapi.JUnitTestCase, error) {
225+
if w.notSupportedReason != nil {
226+
return nil, nil, w.notSupportedReason
227+
}
228+
220229
intervals := monitorapi.Intervals{}
221230
junits := []*junitapi.JUnitTestCase{}
222231
errs := []error{}
@@ -238,11 +247,15 @@ func (w *availability) CollectData(ctx context.Context, storageDir string, begin
238247
return intervals, junits, utilerrors.NewAggregate(errs)
239248
}
240249

241-
func (*availability) ConstructComputedIntervals(ctx context.Context, startingIntervals monitorapi.Intervals, recordedResources monitorapi.ResourcesMap, beginning, end time.Time) (monitorapi.Intervals, error) {
242-
return nil, nil
250+
func (w *availability) ConstructComputedIntervals(ctx context.Context, startingIntervals monitorapi.Intervals, recordedResources monitorapi.ResourcesMap, beginning, end time.Time) (monitorapi.Intervals, error) {
251+
return nil, w.notSupportedReason
243252
}
244253

245254
func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context, finalIntervals monitorapi.Intervals) ([]*junitapi.JUnitTestCase, error) {
255+
if w.notSupportedReason != nil {
256+
return nil, w.notSupportedReason
257+
}
258+
246259
if w.suppressJunit {
247260
return nil, nil
248261
}
@@ -266,10 +279,10 @@ func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context
266279
return junits, utilerrors.NewAggregate(errs)
267280
}
268281

269-
func (*availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
270-
return nil
282+
func (w *availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
283+
return w.notSupportedReason
271284
}
272285

273286
func (w *availability) Cleanup(ctx context.Context) error {
274-
return nil
287+
return w.notSupportedReason
275288
}

0 commit comments

Comments
 (0)