|
| 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.ExecCommand; |
| 10 | +import oracle.kubernetes.operator.utils.ExecResult; |
| 11 | +import oracle.kubernetes.operator.utils.Operator; |
| 12 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 13 | +import org.junit.AfterClass; |
| 14 | +import org.junit.Assume; |
| 15 | +import org.junit.BeforeClass; |
| 16 | +import org.junit.FixMethodOrder; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.runners.MethodSorters; |
| 19 | + |
| 20 | +/** |
| 21 | + * Simple JUnit test file used for testing Operator. |
| 22 | + * |
| 23 | + * <p>This test is used for creating Operator(s) and multiple domains which are managed by the |
| 24 | + * Operator(s). |
| 25 | + */ |
| 26 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 27 | +public class ITOperatorLifecycle extends BaseTest { |
| 28 | + |
| 29 | + // property file used to customize operator properties for operator inputs yaml |
| 30 | + |
| 31 | + private static String operator1File = "operator1.yaml"; |
| 32 | + private static String operator2File = "operator2.yaml"; |
| 33 | + private static final String operator_bcFile = "operator_bc.yaml"; |
| 34 | + private static final String operator_chainFile = "operator_chain.yaml"; |
| 35 | + |
| 36 | + // file used to customize domain properties for domain, PV and LB inputs yaml |
| 37 | + private static String domainonpvwlstFile = "domainonpvwlst.yaml"; |
| 38 | + private static String domainonpvwdtFile = "domainonpvwdt.yaml"; |
| 39 | + private static String domainadminonlyFile = "domainadminonly.yaml"; |
| 40 | + private static String domainrecyclepolicyFile = "domainrecyclepolicy.yaml"; |
| 41 | + private static String domainsampledefaultsFile = "domainsampledefaults.yaml"; |
| 42 | + private static String domaininimagewlstFile = "domaininimagewlst.yaml"; |
| 43 | + private static String domaininimagewdtFile = "domaininimagewdt.yaml"; |
| 44 | + |
| 45 | + // property file used to configure constants for integration tests |
| 46 | + private static String appPropsFile = "OperatorIT.properties"; |
| 47 | + |
| 48 | + private static Operator operator1, operator2; |
| 49 | + |
| 50 | + private static Operator operatorForBackwardCompatibility; |
| 51 | + private static Operator operatorForRESTCertChain; |
| 52 | + |
| 53 | + private static boolean QUICKTEST; |
| 54 | + private static boolean SMOKETEST; |
| 55 | + private static boolean JENKINS; |
| 56 | + private static boolean INGRESSPERDOMAIN = true; |
| 57 | + |
| 58 | + // Set QUICKTEST env var to true to run a small subset of tests. |
| 59 | + // Set SMOKETEST env var to true to run an even smaller subset |
| 60 | + // of tests, plus leave domain1 up and running when the test completes. |
| 61 | + // set INGRESSPERDOMAIN to false to create LB's ingress by kubectl yaml file |
| 62 | + static { |
| 63 | + QUICKTEST = |
| 64 | + System.getenv("QUICKTEST") != null && System.getenv("QUICKTEST").equalsIgnoreCase("true"); |
| 65 | + SMOKETEST = |
| 66 | + System.getenv("SMOKETEST") != null && System.getenv("SMOKETEST").equalsIgnoreCase("true"); |
| 67 | + if (SMOKETEST) QUICKTEST = true; |
| 68 | + if (System.getenv("JENKINS") != null) { |
| 69 | + JENKINS = new Boolean(System.getenv("JENKINS")).booleanValue(); |
| 70 | + } |
| 71 | + if (System.getenv("INGRESSPERDOMAIN") != null) { |
| 72 | + INGRESSPERDOMAIN = new Boolean(System.getenv("INGRESSPERDOMAIN")).booleanValue(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * This method gets called only once before any of the test methods are executed. It does the |
| 78 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 79 | + * the resultRoot, pvRoot and projectRoot attributes. |
| 80 | + * |
| 81 | + * @throws Exception |
| 82 | + */ |
| 83 | + @BeforeClass |
| 84 | + public static void staticPrepare() throws Exception { |
| 85 | + // initialize test properties and create the directories |
| 86 | + initialize(appPropsFile); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Releases k8s cluster lease, archives result, pv directories |
| 91 | + * |
| 92 | + * @throws Exception |
| 93 | + */ |
| 94 | + @AfterClass |
| 95 | + public static void staticUnPrepare() throws Exception { |
| 96 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 97 | + logger.info("BEGIN"); |
| 98 | + logger.info("Run once, release cluster lease"); |
| 99 | + |
| 100 | + StringBuffer cmd = |
| 101 | + new StringBuffer("export RESULT_ROOT=$RESULT_ROOT && export PV_ROOT=$PV_ROOT && "); |
| 102 | + cmd.append(BaseTest.getProjectRoot()) |
| 103 | + .append("/integration-tests/src/test/resources/statedump.sh"); |
| 104 | + logger.info("Running " + cmd); |
| 105 | + |
| 106 | + ExecResult result = ExecCommand.exec(cmd.toString()); |
| 107 | + if (result.exitValue() == 0) logger.info("Executed statedump.sh " + result.stdout()); |
| 108 | + else |
| 109 | + logger.info("Execution of statedump.sh failed, " + result.stderr() + "\n" + result.stdout()); |
| 110 | + |
| 111 | + if (JENKINS) { |
| 112 | + cleanup(); |
| 113 | + } |
| 114 | + |
| 115 | + if (getLeaseId() != "") { |
| 116 | + logger.info("Release the k8s cluster lease"); |
| 117 | + TestUtils.releaseLease(getProjectRoot(), getLeaseId()); |
| 118 | + } |
| 119 | + |
| 120 | + logger.info("SUCCESS"); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Create Operator1 and domainOnPVUsingWLST with admin server and 1 managed server if they are not |
| 125 | + * running. After verifying the domain is created properly. Change some properties on domain |
| 126 | + * resources that would cause servers to be restarted and verify that server are indeed restarted. |
| 127 | + * The properties tested here are: env: "-Dweblogic.StdoutDebugEnabled=false"--> |
| 128 | + * "-Dweblogic.StdoutDebugEnabled=false" logHomeEnabled: true --> logHomeEnabled: false |
| 129 | + * includeServerOutInPodLog: true --> includeServerOutInPodLog: false |
| 130 | + * imagePullPolicy: IfNotPresent --> imagePullPolicy: Never |
| 131 | + * |
| 132 | + * @throws Exception |
| 133 | + */ |
| 134 | + @Test |
| 135 | + public void testServerRestartByDomainOnPVUsingWLST() throws Exception { |
| 136 | + Assume.assumeFalse(QUICKTEST); |
| 137 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 138 | + logTestBegin(testMethodName); |
| 139 | + |
| 140 | + logger.info("Checking if operator1 and domain are running, if not creating"); |
| 141 | + if (operator1 == null) { |
| 142 | + operator1 = TestUtils.createOperator(operator1File); |
| 143 | + } |
| 144 | + |
| 145 | + Domain domain = null; |
| 146 | + boolean testCompletedSuccessfully = false; |
| 147 | + try { |
| 148 | + // load input yaml to map and add configOverrides |
| 149 | + Map<String, Object> domainMap = TestUtils.loadYaml(domainonpvwlstFile); |
| 150 | + domainMap.put("domainUID", "domainlifecycle"); |
| 151 | + domainMap.put("adminNodePort", new Integer("30707")); |
| 152 | + domainMap.put("t3ChannelPort", new Integer("30081")); |
| 153 | + domainMap.put("initialManagedServerReplicas", new Integer("1")); |
| 154 | + |
| 155 | + logger.info("Creating Domain domain& verifing the domain creation"); |
| 156 | + domain = TestUtils.createDomain(domainMap); |
| 157 | + domain.verifyDomainCreated(); |
| 158 | + // TODO add some comments |
| 159 | + logger.info( |
| 160 | + "About to testDomainServerRestart for Domain: " |
| 161 | + + domainMap.get("domainUID") |
| 162 | + + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); |
| 163 | + domain.testDomainServerRestart( |
| 164 | + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); |
| 165 | + logger.info( |
| 166 | + "About to testDomainServerRestart for Domain: " |
| 167 | + + domainMap.get("domainUID") |
| 168 | + + " logHomeEnabled: true --> logHomeEnabled: false"); |
| 169 | + domain.testDomainServerRestart("logHomeEnabled: true", "logHomeEnabled: false"); |
| 170 | + logger.info( |
| 171 | + "About to testDomainServerRestart for Domain: " |
| 172 | + + domainMap.get("domainUID") |
| 173 | + + " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never "); |
| 174 | + domain.testDomainServerRestart(" imagePullPolicy: IfNotPresent", "imagePullPolicy: Never "); |
| 175 | + logger.info( |
| 176 | + "About to testDomainServerRestart for Domain: " |
| 177 | + + domainMap.get("domainUID") |
| 178 | + + " includeServerOutInPodLog: true --> includeServerOutInPodLog: false"); |
| 179 | + domain.testDomainServerRestart( |
| 180 | + "includeServerOutInPodLog: true", "includeServerOutInPodLog: false"); |
| 181 | + } finally { |
| 182 | + String domainUidsToBeDeleted = ""; |
| 183 | + |
| 184 | + if (domain != null && (JENKINS || testCompletedSuccessfully)) { |
| 185 | + domainUidsToBeDeleted = domain.getDomainUid(); |
| 186 | + } |
| 187 | + |
| 188 | + if (!domainUidsToBeDeleted.equals("")) { |
| 189 | + logger.info("About to delete domains: " + domainUidsToBeDeleted); |
| 190 | + TestUtils.deleteWeblogicDomainResources(domainUidsToBeDeleted); |
| 191 | + TestUtils.verifyAfterDeletion(domain); |
| 192 | + } |
| 193 | + } |
| 194 | + logger.info("SUCCESS - " + testMethodName); |
| 195 | + } |
| 196 | +} |
0 commit comments