22
22
23
23
class ClusterFromClone (tutil .OperatorTest ):
24
24
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"
25
31
26
32
@classmethod
27
33
def setUpClass (cls ):
28
34
cls .logger = logging .getLogger (__name__ + ":" + cls .__name__ )
29
35
super ().setUpClass ()
30
36
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
+
35
41
36
42
@classmethod
37
43
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" )
42
47
43
48
super ().tearDownClass ()
44
49
@@ -47,41 +52,40 @@ def test_0_create(self):
47
52
self .ns , "mypwds" , root_user = "root" , root_host = "%" , root_pass = "sakila" )
48
53
49
54
# 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
+ """
60
65
61
66
kutil .apply (self .ns , yaml )
62
67
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" )
66
72
67
- self .wait_ic ("mycluster" , "ONLINE" , 3 )
73
+ self .wait_ic (self . cluster_name , "ONLINE" , self . instances )
68
74
69
75
script = open (tutil .g_test_data_dir + "/sql/sakila-schema.sql" ).read ()
70
76
script += open (tutil .g_test_data_dir + "/sql/sakila-data.sql" ).read ()
71
77
72
- mutil .load_script (self .ns , ["mycluster -0" , "mysql" ], script )
78
+ mutil .load_script (self .ns , [f" { self . cluster_name } -0" , "mysql" ], script )
73
79
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 :
75
81
s .exec_sql ("create user clone@'%' identified by 'clonepass'" )
76
82
s .exec_sql ("grant backup_admin on *.* to clone@'%'" )
77
83
78
84
def test_1_create_clone (self ):
79
85
# 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" )
85
89
86
90
# create cluster with mostly default configs
87
91
yaml = f"""
@@ -98,27 +102,28 @@ def test_1_create_clone(self):
98
102
baseServerId: 2000
99
103
initDB:
100
104
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
102
106
secretKeyRef:
103
107
name: donorpwds
104
108
"""
105
109
106
- kutil .apply ("clone" , yaml )
110
+ kutil .apply (self . cloned_cluster_ns , yaml )
107
111
108
- self .wait_pod ("copycluster -0" , "Running" , ns = "clone" )
112
+ self .wait_pod (f" { self . copycluster_name } -0" , "Running" , ns = self . cloned_cluster_ns )
109
113
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 )
111
115
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 :
113
117
orig_tables = [r [0 ] for r in s .query_sql (
114
118
"show tables in sakila" ).fetch_all ()]
115
119
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 :
117
121
clone_tables = [r [0 ] for r in s .query_sql (
118
122
"show tables in sakila" ).fetch_all ()]
119
123
120
124
# add some data with binlog disabled to make sure that all members of this
121
125
# cluster are cloned
126
+
122
127
s .exec_sql ("set autocommit=1" )
123
128
s .exec_sql ("set session sql_log_bin=0" )
124
129
s .exec_sql ("create schema unlogged_db" )
@@ -131,39 +136,40 @@ def test_1_create_clone(self):
131
136
# with mutil.MySQLPodSession("clone", "copycluster-0", "root", "sakila") as s:
132
137
# pass
133
138
134
- check_routing .check_pods (self , "clone" , "copycluster" , 1 )
139
+ check_routing .check_pods (self , self . cloned_cluster_ns , self . copycluster_name , 1 )
135
140
136
141
# TODO also make sure the source field in the ic says clone and not blank
137
142
138
143
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" )
141
146
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 )
143
149
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 )
145
151
146
152
# 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 :
148
154
self .assertEqual (
149
155
str (s .query_sql ("select * from unlogged_db.tbl" ).fetch_all ()), str ([(42 ,)]))
150
156
151
157
def test_3_routing (self ):
152
158
pass # TODO
153
159
154
160
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 )
160
167
161
168
kutil .delete_ic (self .ns , "mycluster" )
162
169
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 )
167
173
168
174
169
175
# class ClusterFromCloneErrors(tutil.OperatorTest):
0 commit comments