Skip to content

Commit 65ed835

Browse files
author
Nikolas De Giorgis
authored
E2E test fixes (#82)
1 parent 46ab5df commit 65ed835

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

cmd/testrunner/main.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ import (
3030
)
3131

3232
type flags struct {
33-
deployDir string
34-
namespace string
35-
operatorImage string
36-
preHookImage string
37-
testImage string
38-
test string
39-
skipCleanup string
33+
deployDir string
34+
namespace string
35+
operatorImage string
36+
preHookImage string
37+
testImage string
38+
test string
39+
performCleanup string
4040
}
4141

4242
func parseFlags() flags {
43-
var namespace, deployDir, operatorImage, preHookImage, testImage, test, skipCleanup *string
43+
var namespace, deployDir, operatorImage, preHookImage, testImage, test, performCleanup *string
4444
namespace = flag.String("namespace", "default", "the namespace the operator and tests should be deployed in")
4545
deployDir = flag.String("deployDir", "deploy/", "the path to the directory which contains the yaml deployment files")
4646
operatorImage = flag.String("operatorImage", "quay.io/mongodb/community-operator-dev:latest", "the image which should be used for the operator deployment")
4747
preHookImage = flag.String("preHookImage", "quay.io/mongodb/community-operator-prehook:latest", "the prestophook image")
4848
testImage = flag.String("testImage", "quay.io/mongodb/community-operator-e2e:latest", "the image which should be used for the operator e2e tests")
4949
test = flag.String("test", "", "test e2e test that should be run. (name of folder containing the test)")
50-
skipCleanup = flag.String("skipCleanup", "1", "specifies whether to skip cleaning up the context or not")
50+
performCleanup = flag.String("performCleanup", "1", "specifies whether to performing a cleanup the context or not")
5151
flag.Parse()
5252

5353
return flags{
54-
deployDir: *deployDir,
55-
namespace: *namespace,
56-
operatorImage: *operatorImage,
57-
preHookImage: *preHookImage,
58-
testImage: *testImage,
59-
test: *test,
60-
skipCleanup: *skipCleanup,
54+
deployDir: *deployDir,
55+
namespace: *namespace,
56+
operatorImage: *operatorImage,
57+
preHookImage: *preHookImage,
58+
testImage: *testImage,
59+
test: *test,
60+
performCleanup: *performCleanup,
6161
}
6262
}
6363

@@ -97,7 +97,7 @@ func runCmd(f flags) error {
9797
fmt.Println("Successfully deployed the operator")
9898

9999
testToRun := "test/operator-sdk-test.yaml"
100-
if err := buildKubernetesResourceFromYamlFile(c, testToRun, &corev1.Pod{}, withNamespace(f.namespace), withTestImage(f.testImage), withTest(f.test), withEnvVar("SKIP_CLEANUP", f.skipCleanup)); err != nil {
100+
if err := buildKubernetesResourceFromYamlFile(c, testToRun, &corev1.Pod{}, withNamespace(f.namespace), withTestImage(f.testImage), withTest(f.test), withEnvVar("PERFORM_CLEANUP", f.performCleanup)); err != nil {
101101
return fmt.Errorf("error deploying test: %v", err)
102102
}
103103

scripts/dev/e2e.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def create_test_runner_pod(
139139
test: str,
140140
config_file: str,
141141
tag: str,
142-
skip_cleanup: str,
142+
perform_cleanup: str,
143143
test_runner_image_name: str,
144144
):
145145
"""
@@ -148,7 +148,7 @@ def create_test_runner_pod(
148148
dev_config = load_config(config_file)
149149
corev1 = client.CoreV1Api()
150150
pod_body = _get_testrunner_pod_body(
151-
test, config_file, tag, skip_cleanup, test_runner_image_name
151+
test, config_file, tag, perform_cleanup, test_runner_image_name
152152
)
153153

154154
if not k8s_conditions.wait(
@@ -183,7 +183,7 @@ def _get_testrunner_pod_body(
183183
test: str,
184184
config_file: str,
185185
tag: str,
186-
skip_cleanup: str,
186+
perform_cleanup: str,
187187
test_runner_image_name: str,
188188
) -> Dict:
189189
dev_config = load_config(config_file)
@@ -216,7 +216,7 @@ def _get_testrunner_pod_body(
216216
),
217217
"--test={}".format(test),
218218
"--namespace={}".format(dev_config.namespace),
219-
"--skipCleanup={}".format(skip_cleanup),
219+
"--performCleanup={}".format(perform_cleanup),
220220
],
221221
}
222222
],
@@ -228,12 +228,12 @@ def parse_args():
228228
parser = argparse.ArgumentParser()
229229
parser.add_argument("--test", help="Name of the test to run")
230230
parser.add_argument(
231-
"--skip-operator-install",
232-
help="Do not install the Operator, assumes one is installed already",
233-
action="store_false",
231+
"--install-operator",
232+
help="Install the operator instead of assuming one already exists",
233+
action="store_true",
234234
)
235235
parser.add_argument(
236-
"--skip-image-build", help="Skip building images", action="store_false",
236+
"--build-images", help="Build testrunner, e2e and prestop-hook images", action="store_true",
237237
)
238238
parser.add_argument(
239239
"--tag",
@@ -242,46 +242,46 @@ def parse_args():
242242
default="latest",
243243
)
244244
parser.add_argument(
245-
"--dump_diagnostic",
246-
help="Dump diagnostic information into files",
247-
action="store_false",
245+
"--skip-dump-diagnostic",
246+
help="Skip the dump of diagnostic information into files",
247+
action="store_true",
248248
)
249249
parser.add_argument(
250-
"--skip-cleanup",
251-
help="skip the context cleanup when the test ends",
252-
action="store_false",
250+
"--perform-cleanup",
251+
help="Cleanup the context after executing the tests",
252+
action="store_true",
253253
)
254254
parser.add_argument("--config_file", help="Path to the config file")
255255
return parser.parse_args()
256256

257257

258258
def build_and_push_images(args, dev_config):
259259
test_runner_name = dev_config.testrunner_image
260-
if not args.skip_operator_install:
260+
if args.install_operator:
261261
build_and_push_operator(
262262
dev_config.repo_url,
263263
"{}/{}:{}".format(dev_config.repo_url, dev_config.operator_image, args.tag),
264264
".",
265265
)
266266
deploy_operator()
267-
if not args.skip_image_build:
268-
build_and_push_testrunner(
269-
dev_config.repo_url,
270-
"{}/{}:{}".format(dev_config.repo_url, test_runner_name, args.tag),
271-
".",
272-
)
273-
build_and_push_e2e(
274-
dev_config.repo_url,
275-
"{}/{}:{}".format(dev_config.repo_url, dev_config.e2e_image, args.tag),
276-
".",
277-
)
278-
build_and_push_prehook(
279-
dev_config.repo_url,
280-
"{}/{}:{}".format(
281-
dev_config.repo_url, dev_config.prestop_hook_image, args.tag
282-
),
283-
".",
284-
)
267+
if args.build_images:
268+
build_and_push_testrunner(
269+
dev_config.repo_url,
270+
"{}/{}:{}".format(dev_config.repo_url, test_runner_name, args.tag),
271+
".",
272+
)
273+
build_and_push_e2e(
274+
dev_config.repo_url,
275+
"{}/{}:{}".format(dev_config.repo_url, dev_config.e2e_image, args.tag),
276+
".",
277+
)
278+
build_and_push_prehook(
279+
dev_config.repo_url,
280+
"{}/{}:{}".format(
281+
dev_config.repo_url, dev_config.prestop_hook_image, args.tag
282+
),
283+
".",
284+
)
285285

286286

287287
def prepare_and_run_testrunner(args, dev_config):
@@ -292,7 +292,7 @@ def prepare_and_run_testrunner(args, dev_config):
292292
args.test,
293293
args.config_file,
294294
args.tag,
295-
args.skip_cleanup,
295+
args.perform_cleanup,
296296
test_runner_name,
297297
)
298298
corev1 = client.CoreV1Api()
@@ -318,11 +318,11 @@ def main():
318318
try:
319319
build_and_push_images(args, dev_config)
320320
prepare_and_run_testrunner(args, dev_config)
321-
test_runner_pod=k8s_request_data.get_pod_namespaced(dev_config.namespace,TEST_RUNNER_NAME)
322321
finally:
323-
if args.dump_diagnostic:
322+
if not args.skip_dump_diagnostic:
324323
dump_diagnostic.dump_all(dev_config.namespace)
325324

325+
test_runner_pod=k8s_request_data.get_pod_namespaced(dev_config.namespace,TEST_RUNNER_NAME)
326326
if test_runner_pod.status.phase != "Succeeded":
327327
sys.exit(1)
328328

test/e2e/e2eutil.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/statefulset"
10-
119
mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/pkg/apis/mongodb/v1"
10+
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/statefulset"
1211
f "github.com/operator-framework/operator-sdk/pkg/test"
1312
appsv1 "k8s.io/api/apps/v1"
1413
corev1 "k8s.io/api/core/v1"

test/e2e/replica_set_readiness_probe/replica_set_readiness_probe_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func TestMain(m *testing.M) {
1818

1919
func TestReplicaSetReadinessProbeScaling(t *testing.T) {
2020

21+
rand.Seed(time.Now().Unix())
22+
2123
ctx, shouldCleanup := setup.InitTest(t)
2224

2325
if shouldCleanup {
@@ -31,7 +33,7 @@ func TestReplicaSetReadinessProbeScaling(t *testing.T) {
3133
t.Run("Stateful Set Reaches Ready State", mongodbtests.StatefulSetIsReady(&mdb))
3234
t.Run("MongoDB is reachable", mongodbtests.IsReachableDuring(&mdb, time.Second*10,
3335
func() {
34-
t.Run("Delete Random Pod", mongodbtests.DeletePod(&mdb, rand.Intn(mdb.Spec.Members-1)))
36+
t.Run("Delete Random Pod", mongodbtests.DeletePod(&mdb, rand.Intn(mdb.Spec.Members)))
3537
t.Run("Test Replica Set Recovers", mongodbtests.StatefulSetIsReady(&mdb))
3638
t.Run("MongoDB Reaches Running Phase", mongodbtests.MongoDBReachesRunningPhase(&mdb))
3739
t.Run("Test Status Was Updated", mongodbtests.Status(&mdb,

test/e2e/setup/setup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
skipCleanup = "SKIP_CLEANUP"
15+
performCleanup = "PERFORM_CLEANUP"
1616
)
1717

1818
func InitTest(t *testing.T) (*f.Context, bool) {
@@ -22,9 +22,9 @@ func InitTest(t *testing.T) (*f.Context, bool) {
2222
t.Fatal(err)
2323
}
2424

25-
skip := os.Getenv(skipCleanup)
25+
clean := os.Getenv(performCleanup)
2626

27-
return ctx, skip != "True"
27+
return ctx, clean == "True"
2828
}
2929

3030
func registerTypesWithFramework(newTypes ...runtime.Object) error {

0 commit comments

Comments
 (0)