|
| 1 | +// Copyright 2019, 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 | + private static Domain domain = null; |
| 28 | + private static Operator operator1; |
| 29 | + |
| 30 | + /** |
| 31 | + * This method gets called only once before any of the test methods are executed. It does the |
| 32 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 33 | + * the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST |
| 34 | + * with admin server and 1 managed server if they are not running |
| 35 | + * |
| 36 | + * @throws Exception |
| 37 | + */ |
| 38 | + @BeforeClass |
| 39 | + public static void staticPrepare() throws Exception { |
| 40 | + // initialize test properties and create the directories |
| 41 | + if (!QUICKTEST) { |
| 42 | + initialize(APP_PROPS_FILE); |
| 43 | + |
| 44 | + logger.info("Checking if operator1 and domain are running, if not creating"); |
| 45 | + if (operator1 == null) { |
| 46 | + operator1 = TestUtils.createOperator(OPERATOR1_YAML); |
| 47 | + } |
| 48 | + |
| 49 | + domain = createPodsRestartdomain(); |
| 50 | + Assert.assertNotNull(domain); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Releases k8s cluster lease, archives result, pv directories |
| 56 | + * |
| 57 | + * @throws Exception |
| 58 | + */ |
| 59 | + @AfterClass |
| 60 | + public static void staticUnPrepare() throws Exception { |
| 61 | + if (!QUICKTEST) { |
| 62 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 63 | + logger.info("BEGIN"); |
| 64 | + logger.info("Run once, release cluster lease"); |
| 65 | + |
| 66 | + destroyPodsRestartdomain(); |
| 67 | + tearDown(); |
| 68 | + |
| 69 | + logger.info("SUCCESS"); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml |
| 75 | + * Verify that all the server pods in the domain got re-started. The property tested is: env: |
| 76 | + * "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true" |
| 77 | + * |
| 78 | + * @throws Exception |
| 79 | + */ |
| 80 | + @Test |
| 81 | + public void testServerPodsRestartByChangingEnvProperty() throws Exception { |
| 82 | + Assume.assumeFalse(QUICKTEST); |
| 83 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 84 | + logTestBegin(testMethodName); |
| 85 | + |
| 86 | + logger.info( |
| 87 | + "About to testDomainServerPodRestart for Domain: " |
| 88 | + + domain.getDomainUid() |
| 89 | + + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); |
| 90 | + domain.testDomainServerPodRestart( |
| 91 | + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); |
| 92 | + |
| 93 | + logger.info("SUCCESS - " + testMethodName); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml |
| 98 | + * Verify that all the server pods in the domain got re-started. The property tested is: |
| 99 | + * logHomeEnabled: true --> logHomeEnabled: false |
| 100 | + * |
| 101 | + * @throws Exception |
| 102 | + */ |
| 103 | + @Test |
| 104 | + public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception { |
| 105 | + Assume.assumeFalse(QUICKTEST); |
| 106 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 107 | + logTestBegin(testMethodName); |
| 108 | + |
| 109 | + logger.info( |
| 110 | + "About to testDomainServerPodRestart for Domain: " |
| 111 | + + domain.getDomainUid() |
| 112 | + + " logHomeEnabled: true --> logHomeEnabled: false"); |
| 113 | + domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false"); |
| 114 | + |
| 115 | + logger.info("SUCCESS - " + testMethodName); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml |
| 120 | + * Verify that all the server pods in the domain got re-started. The property tested is: |
| 121 | + * imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
| 122 | + * |
| 123 | + * @throws Exception |
| 124 | + */ |
| 125 | + @Test |
| 126 | + public void testServerPodsRestartByChangingImagePullPolicy() throws Exception { |
| 127 | + Assume.assumeFalse(QUICKTEST); |
| 128 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 129 | + logTestBegin(testMethodName); |
| 130 | + |
| 131 | + logger.info( |
| 132 | + "About to testDomainServerPodRestart for Domain: " |
| 133 | + + domain.getDomainUid() |
| 134 | + + " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never "); |
| 135 | + domain.testDomainServerPodRestart( |
| 136 | + "imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" "); |
| 137 | + |
| 138 | + logger.info("SUCCESS - " + testMethodName); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml |
| 143 | + * Verify that all the server pods in the domain got re-started. The property tested is: |
| 144 | + * includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
| 145 | + * |
| 146 | + * @throws Exception |
| 147 | + */ |
| 148 | + @Test |
| 149 | + public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exception { |
| 150 | + Assume.assumeFalse(QUICKTEST); |
| 151 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 152 | + logTestBegin(testMethodName); |
| 153 | + |
| 154 | + logger.info( |
| 155 | + "About to testDomainServerPodRestart for Domain: " |
| 156 | + + domain.getDomainUid() |
| 157 | + + " includeServerOutInPodLog: true --> includeServerOutInPodLog: false"); |
| 158 | + domain.testDomainServerPodRestart( |
| 159 | + "includeServerOutInPodLog: true", "includeServerOutInPodLog: false"); |
| 160 | + |
| 161 | + logger.info("SUCCESS - " + testMethodName); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Modify the domain scope property on the domain resource using kubectl apply -f domain.yaml |
| 166 | + * Verify that all the server pods in the domain got re-started .The property tested is: image: |
| 167 | + * "store/oracle/weblogic:12.2.1.3" --> image: "store/oracle/weblogic:duplicate" |
| 168 | + * |
| 169 | + * @throws Exception |
| 170 | + */ |
| 171 | + @Test |
| 172 | + public void testServerPodsRestartByChangingZImage() throws Exception { |
| 173 | + Assume.assumeFalse(QUICKTEST); |
| 174 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 175 | + logTestBegin(testMethodName); |
| 176 | + |
| 177 | + try { |
| 178 | + logger.info( |
| 179 | + "About to testDomainServerPodRestart for Domain: " |
| 180 | + + domain.getDomainUid() |
| 181 | + + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); |
| 182 | + |
| 183 | + TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); |
| 184 | + domain.testDomainServerPodRestart( |
| 185 | + "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); |
| 186 | + } finally { |
| 187 | + TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate"); |
| 188 | + } |
| 189 | + |
| 190 | + logger.info("SUCCESS - " + testMethodName); |
| 191 | + } |
| 192 | + |
| 193 | + private static Domain createPodsRestartdomain() throws Exception { |
| 194 | + |
| 195 | + Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML); |
| 196 | + domainMap.put("domainUID", "domainpodsrestart"); |
| 197 | + domainMap.put("initialManagedServerReplicas", new Integer("1")); |
| 198 | + |
| 199 | + logger.info("Creating Domain domain& verifing the domain creation"); |
| 200 | + domain = TestUtils.createDomain(domainMap); |
| 201 | + domain.verifyDomainCreated(); |
| 202 | + |
| 203 | + return domain; |
| 204 | + } |
| 205 | + |
| 206 | + private static void destroyPodsRestartdomain() throws Exception { |
| 207 | + if (domain != null) { |
| 208 | + domain.destroy(); |
| 209 | + } |
| 210 | + } |
| 211 | +} |
0 commit comments