8
8
import static oracle .kubernetes .operator .BaseTest .QUICKTEST ;
9
9
import static oracle .kubernetes .operator .BaseTest .logger ;
10
10
11
- import java .lang .reflect .Field ;
12
11
import java .nio .file .Files ;
13
12
import java .nio .file .Paths ;
14
13
import java .util .ArrayList ;
15
14
import java .util .List ;
16
15
import java .util .Map ;
17
16
import java .util .logging .Level ;
18
17
import oracle .kubernetes .operator .utils .Domain ;
19
- import oracle .kubernetes .operator .utils .ExecCommand ;
20
18
import oracle .kubernetes .operator .utils .ExecResult ;
21
19
import oracle .kubernetes .operator .utils .Operator ;
22
20
import oracle .kubernetes .operator .utils .TestUtils ;
36
34
public class ITOperatorUpgrade extends BaseTest {
37
35
38
36
private static final String OP_BASE_REL = "2.0" ;
39
- private static final String OP_TARGET_RELEASE_VERSION = "apiVersion: weblogic.oracle/v4" ;
40
37
private static final String OP_TARGET_RELEASE = "weblogic-kubernetes-operator:latest" ;
38
+ private static final String DOM_TARGET_RELEASE_VERSION = "weblogic.oracle/v4" ;
41
39
private static final String OP_NS = "weblogic-operator" ;
42
40
private static final String OP_DEP_NAME = "operator-upgrade" ;
43
41
private static final String OP_SA = "operator-sa" ;
@@ -58,21 +56,15 @@ public class ITOperatorUpgrade extends BaseTest {
58
56
public static void staticPrepare () throws Exception {
59
57
if (!QUICKTEST ) {
60
58
initialize (APP_PROPS_FILE );
61
- // pullImages();
62
59
opUpgradeTmpDir = BaseTest .getResultDir () + "/operatorupgrade" ;
63
- // findOperatorJar();
64
60
}
65
61
}
66
62
67
63
private void setupOperatorAndDomain (String operatorGitRelease , String operatorRelease )
68
64
throws Exception {
69
65
logger .log (Level .INFO , "+++++++++++++++Beginning Test Setup+++++++++++++++++++++" );
70
66
TestUtils .exec ("rm -rf " + Paths .get (opUpgradeTmpDir ).toString ());
71
- // TestUtils.exec("rm -rf " + Paths.get(opUpgradeTmpDir, "develop").toString());
72
67
Files .createDirectories (Paths .get (opUpgradeTmpDir ));
73
- // Files.createDirectories(Paths.get(opUpgradeTmpDir, "develop"));
74
- // setEnv("IMAGE_NAME_OPERATOR", "oracle/weblogic-kubernetes-operator");
75
- // setEnv("IMAGE_TAG_OPERATOR", operatorRelease);
76
68
Map <String , Object > operatorMap = TestUtils .loadYaml (OPERATOR1_YAML );
77
69
operatorMap .put ("operatorImageName" , "oracle/weblogic-kubernetes-operator" );
78
70
operatorMap .put ("operatorImageTag" , operatorRelease );
@@ -95,7 +87,6 @@ private void setupOperatorAndDomain(String operatorGitRelease, String operatorRe
95
87
// testBasicUseCases(domain);
96
88
// testClusterScaling(operator20, domain);
97
89
printCompVersions ();
98
- // findOperatorJar();
99
90
logger .log (Level .INFO , "+++++++++++++++Ending Test Setup+++++++++++++++++++++" );
100
91
}
101
92
@@ -108,8 +99,10 @@ public void cleanupOperatorAndDomain() throws Exception {
108
99
}
109
100
if (operator20 != null ) {
110
101
operator20 .destroy ();
111
- // operator20 = null;
112
102
}
103
+ ExecResult result = cleanup ();
104
+ logger .log (Level .INFO , "cleanup stdout\n " + result .stdout ());
105
+ logger .log (Level .INFO , "cleanup stderr\n " + result .stderr ());
113
106
TestUtils .ExecAndPrintLog (
114
107
"kubectl delete pods,services,deployments,replicasets,configmaps,services --all --grace-period=0 --force --ignore-not-found -n "
115
108
+ OP_NS );
@@ -120,9 +113,6 @@ public void cleanupOperatorAndDomain() throws Exception {
120
113
"kubectl delete crd --all --grace-period=0 --ignore-not-found --force" );
121
114
TestUtils .ExecAndPrintLog ("kubectl delete ns weblogic-operator --ignore-not-found --force" );
122
115
TestUtils .ExecAndPrintLog ("kubectl delete ns weblogic-domain --ignore-not-found --force" );
123
- ExecResult result = cleanup ();
124
- logger .log (Level .INFO , "cleanup stdout\n " + result .stdout ());
125
- logger .log (Level .INFO , "cleanup stderr\n " + result .stderr ());
126
116
logger .log (Level .INFO , "+++++++++++++++Done AfterTest cleanup+++++++++++++++++++++" );
127
117
}
128
118
@@ -143,19 +133,16 @@ public static void staticUnPrepare() throws Exception {
143
133
}
144
134
145
135
@ Test
146
- public void testOperatorUpgradeFrom2_0ToDevelop () throws Exception {
136
+ public void testOperatorUpgradeFrom2_0 () throws Exception {
147
137
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
148
138
logTestBegin (testMethod );
149
139
setupOperatorAndDomain ("2.0" , "2.0" );
150
- // setEnv("IMAGE_NAME_OPERATOR", "weblogic-kubernetes-operator");
151
- // setEnv("IMAGE_TAG_OPERATOR", "latest");
152
140
upgradeOperator (true );
153
- logger .info (
154
- "+++++++++++++++++++++++++++++++++-SUCCESS--------------------------------+" + testMethod );
141
+ logger .info ("SUCCESS - " + testMethod );
155
142
}
156
143
157
144
@ Test
158
- public void testOperatorUpgradeFrom2_0_1ToDevelop () throws Exception {
145
+ public void testOperatorUpgradeFrom2_0_1 () throws Exception {
159
146
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
160
147
logTestBegin (testMethod );
161
148
setupOperatorAndDomain ("release/2.0.1" , "2.0.1" );
@@ -164,7 +151,7 @@ public void testOperatorUpgradeFrom2_0_1ToDevelop() throws Exception {
164
151
}
165
152
166
153
@ Test
167
- public void testOperatorUpgradeFrom2_1ToDevelop () throws Exception {
154
+ public void testOperatorUpgradeFrom2_1 () throws Exception {
168
155
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
169
156
logTestBegin (testMethod );
170
157
setupOperatorAndDomain ("release/2.1" , "2.1" );
@@ -173,7 +160,7 @@ public void testOperatorUpgradeFrom2_1ToDevelop() throws Exception {
173
160
}
174
161
175
162
@ Test
176
- public void testOperatorUpgradeFrom2_2_0ToDevelop () throws Exception {
163
+ public void testOperatorUpgradeFrom2_2_0 () throws Exception {
177
164
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
178
165
logTestBegin (testMethod );
179
166
setupOperatorAndDomain ("release/2.2" , "2.2.0" );
@@ -182,7 +169,7 @@ public void testOperatorUpgradeFrom2_2_0ToDevelop() throws Exception {
182
169
}
183
170
184
171
@ Test
185
- public void testOperatorUpgradeFrom2_2_1ToDevelop () throws Exception {
172
+ public void testOperatorUpgradeFrom2_2_1 () throws Exception {
186
173
String testMethod = new Object () {}.getClass ().getEnclosingMethod ().getName ();
187
174
logTestBegin (testMethod );
188
175
setupOperatorAndDomain ("release/2.2.1" , "2.2.1" );
@@ -191,60 +178,36 @@ public void testOperatorUpgradeFrom2_2_1ToDevelop() throws Exception {
191
178
}
192
179
193
180
private void upgradeOperator (boolean restart ) throws Exception {
194
- upgradeOperatorHelm (OP_TARGET_RELEASE );
195
- // printCompVersions();
196
- // if (restart) {
197
- // checkDomainRollingRestarted();
198
- // }
199
- printCompVersions ();
200
- checkOperatorVersion (OP_TARGET_RELEASE_VERSION );
181
+ operator20 .callHelmUpgrade ("image=" + OP_TARGET_RELEASE );
182
+ if (restart ) {
183
+ checkDomainRollingRestarted ();
184
+ }
185
+ checkOperatorVersion (DOM_TARGET_RELEASE_VERSION );
201
186
// testBasicUseCases(domain);
202
187
// testClusterScaling(operator20, domain);
203
188
}
204
189
205
- private static void pullImages () throws Exception {
206
- TestUtils .ExecAndPrintLog ("docker pull oracle/weblogic-kubernetes-operator:" + OP_BASE_REL );
207
- }
208
-
209
- private void upgradeOperatorHelm (String upgradeRelease ) throws Exception {
210
- operator20 .callHelmUpgrade ("image=" + upgradeRelease );
211
- logger .log (Level .INFO , "Sleeping for up to 15 minutes" );
190
+ private void checkOperatorVersion (String version ) throws Exception {
191
+ boolean result = false ;
192
+ logger .log (Level .INFO , "Checking for the domain apiVersion in a loop for up to 15 minutes" );
212
193
for (int i = 0 ; i < 900 ; i = i + 10 ) {
213
- Thread .sleep (1000 * 10 );
214
194
TestUtils .ExecAndPrintLog (
215
- "kubectl get domain -n weblogic-domain operator20domain -o jsonpath={.apiVersion}" );
195
+ "kubectl get domain -n " + DOM_NS + " " + DUID + " -o jsonpath={.apiVersion}" );
216
196
ExecResult exec =
217
197
TestUtils .exec (
218
- "kubectl get domain -n weblogic-domain operator20domain -o jsonpath={.apiVersion}" );
219
- if (exec .stdout ().contains ("weblogic.oracle/v4" )) {
198
+ "kubectl get domain -n " + DOM_NS + " " + DUID + " -o jsonpath={.apiVersion}" );
199
+ if (exec .stdout ().contains (DOM_TARGET_RELEASE_VERSION )) {
220
200
logger .log (Level .INFO , "Got the expected apiVersion" );
201
+ result = true ;
221
202
break ;
222
203
}
204
+ Thread .sleep (1000 * 10 );
223
205
}
224
- TestUtils .ExecAndPrintLog ("kubectl get all --all-namespaces" );
225
- }
226
-
227
- private void checkOperatorVersion (String version ) throws Exception {
228
- ExecResult result = ExecCommand .exec ("kubectl get domain " + DUID + " -o yaml -n " + DOM_NS );
229
- if (!result .stdout ().contains (version )) {
230
- logger .log (Level .INFO , result .stdout ());
206
+ if (!result ) {
231
207
throw new RuntimeException ("FAILURE: Didn't get the expected operator version" );
232
208
}
233
209
}
234
210
235
- public static void setEnv (String key , String value ) {
236
- try {
237
- Map <String , String > env = System .getenv ();
238
- Class <?> cl = env .getClass ();
239
- Field field = cl .getDeclaredField ("m" );
240
- field .setAccessible (true );
241
- Map <String , String > writableEnv = (Map <String , String >) field .get (env );
242
- writableEnv .put (key , value );
243
- } catch (Exception e ) {
244
- throw new IllegalStateException ("Failed to set environment variable" , e );
245
- }
246
- }
247
-
248
211
private void checkDomainRollingRestarted () throws Exception {
249
212
domain .verifyAdminServerRestarted ();
250
213
TestUtils .checkPodReady (DUID + "-" + domain .getAdminServerName (), DOM_NS );
@@ -258,12 +221,8 @@ private void checkDomainRollingRestarted() throws Exception {
258
221
}
259
222
260
223
private void printCompVersions () throws Exception {
261
- TestUtils .ExecAndPrintLog ("kubectl get domain " + DUID + " -o yaml -n " + DOM_NS );
262
224
TestUtils .ExecAndPrintLog ("docker images" );
263
225
TestUtils .ExecAndPrintLog ("kubectl get pods -n " + OP_NS + " -o yaml" );
264
- }
265
-
266
- private static void findOperatorJar () throws Exception {
267
- TestUtils .ExecAndPrintLog ("find /scratch -name weblogic-kubernetes-operator-2.3.0.jar" );
226
+ TestUtils .ExecAndPrintLog ("kubectl get domain " + DUID + " -o yaml -n " + DOM_NS );
268
227
}
269
228
}
0 commit comments