forked from NVIDIA/aistore
/
skip.go
118 lines (107 loc) · 3.19 KB
/
skip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Package tools provides common tools and utilities for all unit and integration tests
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package tools
import (
"fmt"
"testing"
"github.com/artashesbalabekyan/aistore/api"
"github.com/artashesbalabekyan/aistore/cluster/meta"
"github.com/artashesbalabekyan/aistore/cmn"
"github.com/artashesbalabekyan/aistore/tools/docker"
"github.com/artashesbalabekyan/aistore/tools/tassert"
)
type SkipTestArgs struct {
Bck cmn.Bck
RequiredDeployment ClusterType
MinTargets int
MinProxies int
MinMountpaths int
RequiresRemoteCluster bool
RequiresAuth bool
Long bool
RemoteBck bool
CloudBck bool
K8s bool
Local bool
}
const fmtSkippingShort = "skipping %s in short mode"
func ShortSkipf(tb testing.TB, a ...any) {
var msg string
if len(a) > 0 {
msg = fmt.Sprint(a...) + ": "
}
msg += fmt.Sprintf(fmtSkippingShort, tb.Name())
tb.Skip(msg)
}
func CheckSkip(tb testing.TB, args SkipTestArgs) {
var smap *meta.Smap
if args.RequiresRemoteCluster && RemoteCluster.UUID == "" {
tb.Skipf("%s requires remote cluster", tb.Name())
}
if args.RequiresAuth && LoggedUserToken == "" {
tb.Skipf("%s requires authentication token", tb.Name())
}
if args.Long && testing.Short() {
tb.Skipf(fmtSkippingShort, tb.Name())
}
if args.RemoteBck {
proxyURL := GetPrimaryURL()
if !isRemoteBucket(tb, proxyURL, args.Bck) {
tb.Skipf("%s requires a remote bucket (have %q)", tb.Name(), args.Bck)
}
}
if args.CloudBck {
proxyURL := GetPrimaryURL()
if !isCloudBucket(tb, proxyURL, args.Bck) {
tb.Skipf("%s requires a cloud bucket", tb.Name())
}
}
switch args.RequiredDeployment {
case ClusterTypeK8s:
// NOTE: The test suite doesn't have to be deployed on K8s, the cluster has to be.
isK8s, err := isClusterK8s()
if err != nil {
tb.Fatalf("Unrecognized error upon checking K8s deployment; err: %v", err)
}
if !isK8s {
tb.Skipf("%s requires Kubernetes", tb.Name())
}
case ClusterTypeLocal:
isLocal, err := isClusterLocal()
tassert.CheckFatal(tb, err)
if !isLocal {
tb.Skipf("%s requires local deployment", tb.Name())
}
case ClusterTypeDocker:
if !docker.IsRunning() {
tb.Skipf("%s requires docker deployment", tb.Name())
}
}
if args.MinTargets > 0 || args.MinMountpaths > 0 || args.MinProxies > 0 {
smap = GetClusterMap(tb, GetPrimaryURL())
}
if args.MinTargets > 0 {
if smap.CountTargets() < args.MinTargets {
tb.Skipf("%s requires at least %d targets (have %d)",
tb.Name(), args.MinTargets, smap.CountTargets())
}
}
if args.MinProxies > 0 {
if smap.CountProxies() < args.MinProxies {
tb.Skipf("%s requires at least %d proxies (have %d)",
tb.Name(), args.MinProxies, smap.CountProxies())
}
}
if args.MinMountpaths > 0 {
targets := smap.Tmap.ActiveNodes()
proxyURL := GetPrimaryURL()
bp := BaseAPIParams(proxyURL)
mpList, err := api.GetMountpaths(bp, targets[0])
tassert.CheckFatal(tb, err)
if l := len(mpList.Available); l < args.MinMountpaths {
tb.Skipf("%s requires at least %d mountpaths (have %d)", tb.Name(), args.MinMountpaths, l)
}
}
}