24
24
import org .junit .Test ;
25
25
import org .junit .runners .MethodSorters ;
26
26
27
- /**
28
- * Simple JUnit test file used for testing Operator.
29
- *
30
- * <p>This test is used for testing Helm install for Operator(s)
31
- */
27
+ /** Operator upgrade JUnit test file testing the operator upgrade from older releases to develop. */
32
28
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
33
29
public class ITOperatorUpgrade extends BaseTest {
34
30
@@ -44,6 +40,15 @@ public class ITOperatorUpgrade extends BaseTest {
44
40
private Domain domain = null ;
45
41
private static Operator operator ;
46
42
43
+ /**
44
+ * Creates operator based on operatorRelease passed to it and then creates a Weblogic domain
45
+ * controlled by that operator
46
+ *
47
+ * @param operatorGitRelease Git branch name of the operator release version
48
+ * @param operatorRelease Operator release version from the
49
+ * https://hub.docker.com/r/oracle/weblogic-kubernetes-operator/tags
50
+ * @throws Exception when operator or domain creation fails
51
+ */
47
52
private void setupOperatorAndDomain (String operatorGitRelease , String operatorRelease )
48
53
throws Exception {
49
54
logger .log (Level .INFO , "+++++++++++++++Beginning Test Setup+++++++++++++++++++++" );
@@ -62,21 +67,26 @@ private void setupOperatorAndDomain(String operatorGitRelease, String operatorRe
62
67
List <String > dom_ns = new ArrayList <String >();
63
68
dom_ns .add (DOM_NS );
64
69
operatorMap .put ("domainNamespaces" , dom_ns );
65
- operator = TestUtils .createOperator (operatorMap , Operator .RESTCertType .LEGACY );
66
- TestUtils .ExecAndPrintLog ("kubectl get all --all-namespaces" );
70
+ operator = TestUtils .createOperator (operatorMap , Operator .RestCertType .LEGACY );
71
+ TestUtils .exec ("kubectl get all --all-namespaces" , true );
67
72
68
73
Map <String , Object > wlstDomainMap = TestUtils .loadYaml (DOMAININIMAGE_WLST_YAML );
69
74
wlstDomainMap .put ("domainUID" , DUID );
70
75
wlstDomainMap .put ("namespace" , DOM_NS );
71
76
wlstDomainMap .put ("projectRoot" , opUpgradeTmpDir + "/weblogic-kubernetes-operator" );
72
77
domain = TestUtils .createDomain (wlstDomainMap );
73
- TestUtils .ExecAndPrintLog ("kubectl get all --all-namespaces" );
78
+ TestUtils .exec ("kubectl get all --all-namespaces" , true );
74
79
domain .verifyPodsCreated ();
75
80
domain .verifyServicesCreated ();
76
81
domain .verifyServersReady ();
77
82
logger .log (Level .INFO , "+++++++++++++++Ending Test Setup+++++++++++++++++++++" );
78
83
}
79
84
85
+ /**
86
+ * cleanup the domain and operator after every test
87
+ *
88
+ * @throws Exception when domain and operator cleanup fails
89
+ */
80
90
@ After
81
91
public void cleanupOperatorAndDomain () throws Exception {
82
92
logger .log (Level .INFO , "+++++++++++++++Beginning AfterTest cleanup+++++++++++++++++++++" );
@@ -87,23 +97,23 @@ public void cleanupOperatorAndDomain() throws Exception {
87
97
operator .destroy ();
88
98
}
89
99
ExecResult result = cleanup ();
90
- TestUtils .ExecAndPrintLog (
100
+ TestUtils .exec (
91
101
"kubectl delete pods,services,deployments,replicasets,configmaps,services --all --ignore-not-found -n "
92
102
+ OP_NS );
93
- TestUtils .ExecAndPrintLog (
103
+ TestUtils .exec (
94
104
"kubectl delete pods,services,deployments,replicasets,configmaps,services --all --ignore-not-found -n "
95
105
+ DOM_NS );
96
- TestUtils .ExecAndPrintLog ("kubectl delete crd --all --ignore-not-found" );
97
- TestUtils .ExecAndPrintLog ("kubectl delete ns " + OP_NS + " --ignore-not-found" );
98
- TestUtils .ExecAndPrintLog ("kubectl delete ns " + DOM_NS + " --ignore-not-found" );
99
- TestUtils .ExecAndPrintLog ("kubectl get all --all-namespaces" );
106
+ TestUtils .exec ("kubectl delete crd --all --ignore-not-found" );
107
+ TestUtils .exec ("kubectl delete ns " + OP_NS + " --ignore-not-found" );
108
+ TestUtils .exec ("kubectl delete ns " + DOM_NS + " --ignore-not-found" );
109
+ TestUtils .exec ("kubectl get all --all-namespaces" );
100
110
logger .log (Level .INFO , "+++++++++++++++Done AfterTest cleanup+++++++++++++++++++++" );
101
111
}
102
112
103
113
/**
104
114
* Releases k8s cluster lease, archives result, pv directories
105
115
*
106
- * @throws Exception
116
+ * @throws Exception when deleting pv directories or other tearDown tasks fail.
107
117
*/
108
118
@ AfterClass
109
119
public static void staticUnPrepare () throws Exception {
@@ -116,6 +126,11 @@ public static void staticUnPrepare() throws Exception {
116
126
}
117
127
}
118
128
129
+ /**
130
+ * Test for upgrading Operator from release 2.0 to develop branch
131
+ *
132
+ * @throws Exception when upgrade fails
133
+ */
119
134
@ Test
120
135
public void testOperatorUpgradeFrom2_0 () throws Exception {
121
136
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
@@ -130,6 +145,11 @@ public void testOperatorUpgradeFrom2_0() throws Exception {
130
145
logger .info ("SUCCESS - " + testMethod );
131
146
}
132
147
148
+ /**
149
+ * Test for upgrading Operator from release 2.0.1 to develop branch
150
+ *
151
+ * @throws Exception when upgrade fails
152
+ */
133
153
@ Test
134
154
public void testOperatorUpgradeFrom2_0_1 () throws Exception {
135
155
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
@@ -144,6 +164,11 @@ public void testOperatorUpgradeFrom2_0_1() throws Exception {
144
164
logger .info ("SUCCESS - " + testMethod );
145
165
}
146
166
167
+ /**
168
+ * Test for upgrading Operator from release 2.1 to develop branch
169
+ *
170
+ * @throws Exception when upgrade fails
171
+ */
147
172
@ Test
148
173
public void testOperatorUpgradeFrom2_1 () throws Exception {
149
174
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
@@ -158,6 +183,11 @@ public void testOperatorUpgradeFrom2_1() throws Exception {
158
183
logger .info ("SUCCESS - " + testMethod );
159
184
}
160
185
186
+ /**
187
+ * Test for upgrading Operator from release 2.2.0 to develop branch
188
+ *
189
+ * @throws Exception when upgrade fails
190
+ */
161
191
@ Test
162
192
public void testOperatorUpgradeFrom2_2_0 () throws Exception {
163
193
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
@@ -172,6 +202,11 @@ public void testOperatorUpgradeFrom2_2_0() throws Exception {
172
202
logger .info ("SUCCESS - " + testMethod );
173
203
}
174
204
205
+ /**
206
+ * Test for upgrading Operator from release 2.2.1 to develop branch
207
+ *
208
+ * @throws Exception when upgrade fails
209
+ */
175
210
@ Test
176
211
public void testOperatorUpgradeFrom2_2_1 () throws Exception {
177
212
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
@@ -186,25 +221,35 @@ public void testOperatorUpgradeFrom2_2_1() throws Exception {
186
221
logger .info ("SUCCESS - " + testMethod );
187
222
}
188
223
224
+ /**
225
+ * Upgrades operator to develop branch by using the helm upgrade
226
+ *
227
+ * @param restart boolean parameter used to determine if a restart of domain is checked
228
+ * @throws Exception when upgrade fails or basic usecase testing or scaling fails.
229
+ */
189
230
private void upgradeOperator (boolean restart ) throws Exception {
190
231
operator .callHelmUpgrade ("image=" + OP_TARGET_RELEASE );
191
232
if (restart ) {
192
233
checkDomainRollingRestarted ();
193
234
}
194
- checkOperatorVersion (DOM_TARGET_RELEASE_VERSION );
235
+ checkOperatorVersion ();
195
236
testBasicUseCases (domain );
196
237
testClusterScaling (operator , domain );
197
238
}
198
239
199
- private void checkOperatorVersion (String version ) throws Exception {
240
+ /**
241
+ * checks the expected version of the upgraded operator in a loop. In Jenkins it takes nearly 8
242
+ * minutes to show the updated value of the domain CRD
243
+ *
244
+ * @throws Exception when version does not match
245
+ */
246
+ private void checkOperatorVersion () throws Exception {
200
247
boolean result = false ;
201
248
logger .log (Level .INFO , "Checking for the domain apiVersion in a loop for up to 15 minutes" );
202
249
for (int i = 0 ; i < 900 ; i = i + 10 ) {
203
- TestUtils .ExecAndPrintLog (
204
- "kubectl get domain -n " + DOM_NS + " " + DUID + " -o jsonpath={.apiVersion}" );
205
250
ExecResult exec =
206
251
TestUtils .exec (
207
- "kubectl get domain -n " + DOM_NS + " " + DUID + " -o jsonpath={.apiVersion}" );
252
+ "kubectl get domain -n " + DOM_NS + " " + DUID + " -o jsonpath={.apiVersion}" , true );
208
253
if (exec .stdout ().contains (DOM_TARGET_RELEASE_VERSION )) {
209
254
logger .log (Level .INFO , "Got the expected apiVersion" );
210
255
result = true ;
@@ -217,6 +262,11 @@ private void checkOperatorVersion(String version) throws Exception {
217
262
}
218
263
}
219
264
265
+ /**
266
+ * Check whether the weblogic server instances are rolling restarted
267
+ *
268
+ * @throws Exception If restart fails or not restarted
269
+ */
220
270
private void checkDomainRollingRestarted () throws Exception {
221
271
domain .verifyAdminServerRestarted ();
222
272
TestUtils .checkPodReady (DUID + "-" + domain .getAdminServerName (), DOM_NS );
@@ -228,10 +278,4 @@ private void checkDomainRollingRestarted() throws Exception {
228
278
TestUtils .checkPodReady (DUID + "-managed-server" + i , DOM_NS );
229
279
}
230
280
}
231
-
232
- private void printCompVersions () throws Exception {
233
- TestUtils .ExecAndPrintLog ("docker images" );
234
- TestUtils .ExecAndPrintLog ("kubectl get pods -n " + OP_NS + " -o yaml" );
235
- TestUtils .ExecAndPrintLog ("kubectl get domain " + DUID + " -o yaml -n " + DOM_NS );
236
- }
237
281
}
0 commit comments