|
| 1 | +// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at |
| 3 | +// http://oss.oracle.com/licenses/upl. |
| 4 | + |
| 5 | +package oracle.kubernetes.operator; |
| 6 | + |
| 7 | +import java.util.Map; |
| 8 | +import oracle.kubernetes.operator.utils.Domain; |
| 9 | +import oracle.kubernetes.operator.utils.Operator; |
| 10 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 11 | +import org.junit.AfterClass; |
| 12 | +import org.junit.Assert; |
| 13 | +import org.junit.Assume; |
| 14 | +import org.junit.BeforeClass; |
| 15 | +import org.junit.FixMethodOrder; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.runners.MethodSorters; |
| 18 | + |
| 19 | +/** |
| 20 | + * Simple JUnit test file used for testing Operator. |
| 21 | + * |
| 22 | + * <p>This test is used for testing pods being restarted by some properties change. |
| 23 | + */ |
| 24 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 25 | +public class ITPodsRestart extends BaseTest { |
| 26 | + |
| 27 | + // property file used to customize operator properties for operator inputs yaml |
| 28 | + private static String operator1File = "operator1.yaml"; |
| 29 | + |
| 30 | + // file used to customize domain properties for domain, PV and LB inputs yaml |
| 31 | + private static Domain domain = null; |
| 32 | + private static String domainonpvwlstFile = "domainonpvwlst.yaml"; |
| 33 | + |
| 34 | + // property file used to configure constants for integration tests |
| 35 | + private static String appPropsFile = "OperatorIT.properties"; |
| 36 | + |
| 37 | + private static Operator operator1; |
| 38 | + |
| 39 | + private static boolean QUICKTEST; |
| 40 | + private static boolean SMOKETEST; |
| 41 | + private static boolean JENKINS; |
| 42 | + private static boolean INGRESSPERDOMAIN = true; |
| 43 | + |
| 44 | + // Set QUICKTEST env var to true to run a small subset of tests. |
| 45 | + // Set SMOKETEST env var to true to run an even smaller subset |
| 46 | + // of tests, plus leave domain1 up and running when the test completes. |
| 47 | + // set INGRESSPERDOMAIN to false to create LB's ingress by kubectl yaml file |
| 48 | + static { |
| 49 | + QUICKTEST = |
| 50 | + System.getenv("QUICKTEST") != null && System.getenv("QUICKTEST").equalsIgnoreCase("true"); |
| 51 | + SMOKETEST = |
| 52 | + System.getenv("SMOKETEST") != null && System.getenv("SMOKETEST").equalsIgnoreCase("true"); |
| 53 | + if (SMOKETEST) QUICKTEST = true; |
| 54 | + if (System.getenv("JENKINS") != null) { |
| 55 | + JENKINS = new Boolean(System.getenv("JENKINS")).booleanValue(); |
| 56 | + } |
| 57 | + if (System.getenv("INGRESSPERDOMAIN") != null) { |
| 58 | + INGRESSPERDOMAIN = new Boolean(System.getenv("INGRESSPERDOMAIN")).booleanValue(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * This method gets called only once before any of the test methods are executed. It does the |
| 64 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 65 | + * the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST |
| 66 | + * with admin server and 1 managed server if they are not running |
| 67 | + * |
| 68 | + * @throws Exception |
| 69 | + */ |
| 70 | + @BeforeClass |
| 71 | + public static void staticPrepare() throws Exception { |
| 72 | + // initialize test properties and create the directories |
| 73 | + if (!QUICKTEST) { |
| 74 | + initialize(appPropsFile); |
| 75 | + |
| 76 | + logger.info("Checking if operator1 and domain are running, if not creating"); |
| 77 | + if (operator1 == null) { |
| 78 | + operator1 = TestUtils.createOperator(operator1File); |
| 79 | + } |
| 80 | + |
| 81 | + domain = createPodsRestartdomain(); |
| 82 | + Assert.assertNotNull(domain); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Releases k8s cluster lease, archives result, pv directories |
| 88 | + * |
| 89 | + * @throws Exception |
| 90 | + */ |
| 91 | + @AfterClass |
| 92 | + public static void staticUnPrepare() throws Exception { |
| 93 | + if (!QUICKTEST) { |
| 94 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 95 | + logger.info("BEGIN"); |
| 96 | + logger.info("Run once, release cluster lease"); |
| 97 | + |
| 98 | + // destroyPodsRestartdomain(); |
| 99 | + // tearDown(); |
| 100 | + |
| 101 | + if (!"".equals(getLeaseId())) { |
| 102 | + logger.info("Release the k8s cluster lease"); |
| 103 | + TestUtils.releaseLease(getProjectRoot(), getLeaseId()); |
| 104 | + } |
| 105 | + |
| 106 | + logger.info("SUCCESS"); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * The properties tested is: env: "-Dweblogic.StdoutDebugEnabled=false"--> |
| 112 | + * "-Dweblogic.StdoutDebugEnabled=true" |
| 113 | + * |
| 114 | + * @throws Exception |
| 115 | + */ |
| 116 | + @Test |
| 117 | + public void testServerRestartByChangingEnvProperty() throws Exception { |
| 118 | + Assume.assumeFalse(QUICKTEST); |
| 119 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 120 | + logTestBegin(testMethodName); |
| 121 | + |
| 122 | + boolean testCompletedSuccessfully = false; |
| 123 | + logger.info( |
| 124 | + "About to testDomainServerRestart for Domain: " |
| 125 | + + domain.getDomainUid() |
| 126 | + + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); |
| 127 | + domain.testDomainServerRestart( |
| 128 | + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); |
| 129 | + |
| 130 | + logger.info("SUCCESS - " + testMethodName); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * The properties tested is: logHomeEnabled: true --> logHomeEnabled: false |
| 135 | + * |
| 136 | + * @throws Exception |
| 137 | + */ |
| 138 | + @Test |
| 139 | + public void testServerRestartByChangingLogHomeEnabled() throws Exception { |
| 140 | + Assume.assumeFalse(QUICKTEST); |
| 141 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 142 | + logTestBegin(testMethodName); |
| 143 | + |
| 144 | + boolean testCompletedSuccessfully = false; |
| 145 | + |
| 146 | + logger.info( |
| 147 | + "About to testDomainServerRestart for Domain: " |
| 148 | + + domain.getDomainUid() |
| 149 | + + " logHomeEnabled: true --> logHomeEnabled: false"); |
| 150 | + domain.testDomainServerRestart("logHomeEnabled: true", "logHomeEnabled: false"); |
| 151 | + |
| 152 | + logger.info("SUCCESS - " + testMethodName); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * The properties tested is: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
| 157 | + * |
| 158 | + * @throws Exception |
| 159 | + */ |
| 160 | + @Test |
| 161 | + public void testServerRestartByChangingImagePullPolicy() throws Exception { |
| 162 | + Assume.assumeFalse(QUICKTEST); |
| 163 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 164 | + logTestBegin(testMethodName); |
| 165 | + |
| 166 | + boolean testCompletedSuccessfully = false; |
| 167 | + |
| 168 | + logger.info( |
| 169 | + "About to testDomainServerRestart for Domain: " |
| 170 | + + domain.getDomainUid() |
| 171 | + + " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never "); |
| 172 | + domain.testDomainServerRestart( |
| 173 | + "imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" "); |
| 174 | + |
| 175 | + logger.info("SUCCESS - " + testMethodName); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * The properties tested is: includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
| 180 | + * |
| 181 | + * @throws Exception |
| 182 | + */ |
| 183 | + @Test |
| 184 | + public void testServerRestartByChangingIncludeServerOutInPodLog() throws Exception { |
| 185 | + Assume.assumeFalse(QUICKTEST); |
| 186 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 187 | + logTestBegin(testMethodName); |
| 188 | + |
| 189 | + boolean testCompletedSuccessfully = false; |
| 190 | + |
| 191 | + logger.info( |
| 192 | + "About to testDomainServerRestart for Domain: " |
| 193 | + + domain.getDomainUid() |
| 194 | + + " includeServerOutInPodLog: true --> includeServerOutInPodLog: false"); |
| 195 | + domain.testDomainServerRestart( |
| 196 | + "includeServerOutInPodLog: true", "includeServerOutInPodLog: false"); |
| 197 | + |
| 198 | + logger.info("SUCCESS - " + testMethodName); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * The properties tested is: image: "store/oracle/weblogic:12.2.1.3" --> image: |
| 203 | + * "store/oracle/weblogic:duplicate" |
| 204 | + * |
| 205 | + * @throws Exception |
| 206 | + */ |
| 207 | + @Test |
| 208 | + public void testServerRestartByChangingImage() throws Exception { |
| 209 | + Assume.assumeFalse(QUICKTEST); |
| 210 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 211 | + logTestBegin(testMethodName); |
| 212 | + |
| 213 | + boolean testCompletedSuccessfully = false; |
| 214 | + |
| 215 | + logger.info( |
| 216 | + "About to testDomainServerRestart for Domain: " |
| 217 | + + domain.getDomainUid() |
| 218 | + + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); |
| 219 | + TestUtils.dockerTagImage("store/oracle/weblogic:12.2.1.3", "store/oracle/weblogic:duplicate"); |
| 220 | + domain.testDomainServerRestart( |
| 221 | + "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); |
| 222 | + TestUtils.dockerRemoveImage("store/oracle/weblogic:duplicate"); |
| 223 | + |
| 224 | + logger.info("SUCCESS - " + testMethodName); |
| 225 | + } |
| 226 | + |
| 227 | + private static Domain createPodsRestartdomain() throws Exception { |
| 228 | + |
| 229 | + Map<String, Object> domainMap = TestUtils.loadYaml(domainonpvwlstFile); |
| 230 | + domainMap.put("domainUID", "domainpodsrestart"); |
| 231 | + domainMap.put("adminNodePort", new Integer("30707")); |
| 232 | + domainMap.put("t3ChannelPort", new Integer("30081")); |
| 233 | + domainMap.put("initialManagedServerReplicas", new Integer("1")); |
| 234 | + |
| 235 | + logger.info("Creating Domain domain& verifing the domain creation"); |
| 236 | + domain = TestUtils.createDomain(domainMap); |
| 237 | + domain.verifyDomainCreated(); |
| 238 | + |
| 239 | + return domain; |
| 240 | + } |
| 241 | + |
| 242 | + private static void destroyPodsRestartdomain() throws Exception { |
| 243 | + if (domain != null) { |
| 244 | + domain.destroy(); |
| 245 | + } |
| 246 | + } |
| 247 | +} |
0 commit comments