Skip to content

Commit 5ce8b9f

Browse files
committed
Refactor ClusterFromClone test
Change-Id: I7c23bcb630cef108f4ff98fdf6763321fe10b387
1 parent 40bcc7e commit 5ce8b9f

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

mysqloperator/controller/innodbcluster/initdb.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def start_clone_seed_pod(session: 'ClassicSession',
6464

6565
with SessionWrap(donor_co) as donor:
6666
logger.info(f"Starting server clone from {clone_spec.uri}")
67-
return mysqlutils.clone_server(donor_co, donor, session, logger)
67+
ret = mysqlutils.clone_server(donor_co, donor, session, logger)
68+
logger.info("Cloning finished")
69+
return ret
6870
except mysqlsh.Error as e:
6971
if mysqlutils.is_client_error(e.code) or e.code == mysqlsh.mysql.ErrorCode.ER_ACCESS_DENIED_ERROR:
7072
# TODO check why are we still getting access denied here, the container should have all accounts ready by now

tests/e2e/mysqloperator/cluster/initdb_t.py

+56-50
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,28 @@
2222

2323
class ClusterFromClone(tutil.OperatorTest):
2424
default_allowed_op_errors = COMMON_OPERATOR_ERRORS
25+
instances = 3
26+
cluster_name = "mycluster"
27+
copycluster_name = "copycluster"
28+
copycluster_ns = "clone"
29+
copycluster_wantedinstances = 2
30+
cloned_cluster_ns = "clone"
2531

2632
@classmethod
2733
def setUpClass(cls):
2834
cls.logger = logging.getLogger(__name__+":"+cls.__name__)
2935
super().setUpClass()
3036

31-
g_full_log.watch_mysql_pod("cloned", "mycluster-0")
32-
g_full_log.watch_mysql_pod(cls.ns, "mycluster-0")
33-
g_full_log.watch_mysql_pod(cls.ns, "mycluster-1")
34-
g_full_log.watch_mysql_pod(cls.ns, "mycluster-2")
37+
g_full_log.watch_mysql_pod(cls.copycluster_ns, f"{cls.copycluster_name}-0")
38+
for instance in range(0, cls.instances):
39+
g_full_log.watch_mysql_pod(cls.ns, f"{cls.cluster_name}-{instance}")
40+
3541

3642
@classmethod
3743
def tearDownClass(cls):
38-
g_full_log.stop_watch(cls.ns, "mycluster-2")
39-
g_full_log.stop_watch(cls.ns, "mycluster-1")
40-
g_full_log.stop_watch(cls.ns, "mycluster-0")
41-
g_full_log.stop_watch("cloned", "mycluster-0")
44+
for instance in reversed(range(0, cls.instances)):
45+
g_full_log.stop_watch(cls.ns, f"{cls.cluster_name}-{instance}")
46+
g_full_log.stop_watch(cls.copycluster_ns, f"{cls.copycluster_name}-0")
4247

4348
super().tearDownClass()
4449

@@ -47,41 +52,40 @@ def test_0_create(self):
4752
self.ns, "mypwds", root_user="root", root_host="%", root_pass="sakila")
4853

4954
# create cluster with mostly default configs
50-
yaml = """
51-
apiVersion: mysql.oracle.com/v2
52-
kind: InnoDBCluster
53-
metadata:
54-
name: mycluster
55-
spec:
56-
instances: 3
57-
secretName: mypwds
58-
tlsUseSelfSigned: true
59-
"""
55+
yaml = f"""
56+
apiVersion: mysql.oracle.com/v2
57+
kind: InnoDBCluster
58+
metadata:
59+
name: {self.cluster_name}
60+
spec:
61+
instances: {self.instances}
62+
secretName: mypwds
63+
tlsUseSelfSigned: true
64+
"""
6065

6166
kutil.apply(self.ns, yaml)
6267

63-
self.wait_pod("mycluster-0", "Running")
64-
self.wait_pod("mycluster-1", "Running")
65-
self.wait_pod("mycluster-2", "Running")
68+
self.wait_ic(self.cluster_name, ["PENDING", "INITIALIZING", "ONLINE"])
69+
70+
for instance in range(0, self.instances):
71+
self.wait_pod(f"{self.cluster_name}-{instance}", "Running")
6672

67-
self.wait_ic("mycluster", "ONLINE", 3)
73+
self.wait_ic(self.cluster_name, "ONLINE", self.instances)
6874

6975
script = open(tutil.g_test_data_dir+"/sql/sakila-schema.sql").read()
7076
script += open(tutil.g_test_data_dir+"/sql/sakila-data.sql").read()
7177

72-
mutil.load_script(self.ns, ["mycluster-0", "mysql"], script)
78+
mutil.load_script(self.ns, [f"{self.cluster_name}-0", "mysql"], script)
7379

74-
with mutil.MySQLPodSession(self.ns, "mycluster-0", "root", "sakila") as s:
80+
with mutil.MySQLPodSession(self.ns, f"{self.cluster_name}-0", "root", "sakila") as s:
7581
s.exec_sql("create user clone@'%' identified by 'clonepass'")
7682
s.exec_sql("grant backup_admin on *.* to clone@'%'")
7783

7884
def test_1_create_clone(self):
7985
# TODO add support for using different root password between clusters
80-
kutil.create_ns("clone", g_ts_cfg.get_custom_test_ns_labels())
81-
kutil.create_user_secrets(
82-
"clone", "pwds", root_user="root", root_host="%", root_pass="sakila")
83-
kutil.create_user_secrets(
84-
"clone", "donorpwds", root_user="root", root_host="%", root_pass="sakila")
86+
kutil.create_ns(self.cloned_cluster_ns, g_ts_cfg.get_custom_test_ns_labels())
87+
kutil.create_user_secrets(self.cloned_cluster_ns, "pwds", root_user="root", root_host="%", root_pass="sakila")
88+
kutil.create_user_secrets(self.cloned_cluster_ns, "donorpwds", root_user="root", root_host="%", root_pass="sakila")
8589

8690
# create cluster with mostly default configs
8791
yaml = f"""
@@ -98,27 +102,28 @@ def test_1_create_clone(self):
98102
baseServerId: 2000
99103
initDB:
100104
clone:
101-
donorUrl: root@mycluster-0.mycluster-instances.{self.ns}.svc.cluster.local:3306
105+
donorUrl: root@{self.cluster_name}-0.{self.cluster_name}-instances.{self.ns}.svc.cluster.local:3306
102106
secretKeyRef:
103107
name: donorpwds
104108
"""
105109

106-
kutil.apply("clone", yaml)
110+
kutil.apply(self.cloned_cluster_ns, yaml)
107111

108-
self.wait_pod("copycluster-0", "Running", ns="clone")
112+
self.wait_pod(f"{self.copycluster_name}-0", "Running", ns=self.cloned_cluster_ns)
109113

110-
self.wait_ic("copycluster", "ONLINE", 1, ns="clone", timeout=300)
114+
self.wait_ic(self.copycluster_name, "ONLINE", 1, ns=self.cloned_cluster_ns, timeout=300)
111115

112-
with mutil.MySQLPodSession(self.ns, "mycluster-0", "root", "sakila") as s:
116+
with mutil.MySQLPodSession(self.ns, f"{self.cluster_name}-0", "root", "sakila") as s:
113117
orig_tables = [r[0] for r in s.query_sql(
114118
"show tables in sakila").fetch_all()]
115119

116-
with mutil.MySQLPodSession("clone", "copycluster-0", "root", "sakila") as s:
120+
with mutil.MySQLPodSession(self.cloned_cluster_ns, f"{self.copycluster_name}-0", "root", "sakila") as s:
117121
clone_tables = [r[0] for r in s.query_sql(
118122
"show tables in sakila").fetch_all()]
119123

120124
# add some data with binlog disabled to make sure that all members of this
121125
# cluster are cloned
126+
122127
s.exec_sql("set autocommit=1")
123128
s.exec_sql("set session sql_log_bin=0")
124129
s.exec_sql("create schema unlogged_db")
@@ -131,39 +136,40 @@ def test_1_create_clone(self):
131136
# with mutil.MySQLPodSession("clone", "copycluster-0", "root", "sakila") as s:
132137
# pass
133138

134-
check_routing.check_pods(self, "clone", "copycluster", 1)
139+
check_routing.check_pods(self, self.cloned_cluster_ns, self.copycluster_name, 1)
135140

136141
# TODO also make sure the source field in the ic says clone and not blank
137142

138143
def test_2_grow(self):
139-
kutil.patch_ic("clone", "copycluster", {
140-
"spec": {"instances": 2}}, type="merge")
144+
kutil.patch_ic(self.cloned_cluster_ns, self.copycluster_name, {
145+
"spec": {"instances": self.copycluster_wantedinstances}}, type="merge")
141146

142-
self.wait_pod("copycluster-1", "Running", ns="clone")
147+
for instance in range(1, self.copycluster_wantedinstances):
148+
self.wait_pod(f"{self.copycluster_name}-{instance}", "Running", ns=self.cloned_cluster_ns)
143149

144-
self.wait_ic("copycluster", "ONLINE", 2, ns="clone")
150+
self.wait_ic(self.copycluster_name, "ONLINE", self.copycluster_wantedinstances, ns=self.cloned_cluster_ns)
145151

146152
# check that the new instance was cloned
147-
with mutil.MySQLPodSession("clone", "copycluster-1", "root", "sakila") as s:
153+
with mutil.MySQLPodSession(self.cloned_cluster_ns, f"{self.copycluster_name}-1", "root", "sakila") as s:
148154
self.assertEqual(
149155
str(s.query_sql("select * from unlogged_db.tbl").fetch_all()), str([(42,)]))
150156

151157
def test_3_routing(self):
152158
pass # TODO
153159

154160
def test_9_destroy(self):
155-
kutil.delete_ic("clone", "copycluster")
156-
self.wait_pod_gone("copycluster-1", ns="clone")
157-
self.wait_pod_gone("copycluster-0", ns="clone")
158-
self.wait_ic_gone("copycluster", ns="clone")
159-
kutil.delete_ns("clone")
161+
kutil.delete_ic(self.cloned_cluster_ns, self.copycluster_name)
162+
for instance in reversed(range(0, self.copycluster_wantedinstances)):
163+
self.wait_pod_gone(f"{self.copycluster_name}-{instance}", ns=self.cloned_cluster_ns)
164+
self.wait_pod_gone(f"{self.copycluster_name}-0", ns=self.cloned_cluster_ns)
165+
self.wait_ic_gone(self.copycluster_name, ns=self.cloned_cluster_ns)
166+
kutil.delete_ns(self.cloned_cluster_ns)
160167

161168
kutil.delete_ic(self.ns, "mycluster")
162169

163-
self.wait_pod_gone("mycluster-2")
164-
self.wait_pod_gone("mycluster-1")
165-
self.wait_pod_gone("mycluster-0")
166-
self.wait_ic_gone("mycluster")
170+
for instance in reversed(range(0, self.instances)):
171+
self.wait_pod_gone(f"{self.cluster_name}-{instance}")
172+
self.wait_ic_gone(self.cluster_name)
167173

168174

169175
# class ClusterFromCloneErrors(tutil.OperatorTest):

0 commit comments

Comments
 (0)