|
| 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.Properties; |
| 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.Assume; |
| 13 | +import org.junit.BeforeClass; |
| 14 | +import org.junit.Test; |
| 15 | + |
| 16 | +/** |
| 17 | + * Simple JUnit test file used for testing Operator. |
| 18 | + * |
| 19 | + * <p>This test is used for creating Operator and a single domain which the Operator manages and |
| 20 | + * verifies both. |
| 21 | + */ |
| 22 | +public class ITFourthDomain extends BaseTest { |
| 23 | + public static final String TESTWEBAPP = "testwebapp"; |
| 24 | + |
| 25 | + // property file used to customize operator properties for operator inputs yaml |
| 26 | + private static String opPropsFile = "ITSecondOperator.properties"; |
| 27 | + |
| 28 | + // property file used to customize domain properties for domain inputs yaml |
| 29 | + private static String domainPropsFile = "ITFourthDomain.properties"; |
| 30 | + |
| 31 | + // property file used to configure constants for integration tests |
| 32 | + private static String appPropsFile = "OperatorIT.properties"; |
| 33 | + |
| 34 | + private static Operator operator; |
| 35 | + private static Domain domain; |
| 36 | + |
| 37 | + // properties of operator/domain to use in the test methods |
| 38 | + private static Properties operatorProps; |
| 39 | + private static Properties domainProps; |
| 40 | + |
| 41 | + private static String domainUid, domainNS; |
| 42 | + /** |
| 43 | + * This method gets called only once before any of the test methods are executed. It does the |
| 44 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 45 | + * the resultRoot, pvRoot and projectRoot attributes. It also creates the Operator and domain. |
| 46 | + * |
| 47 | + * @throws Exception |
| 48 | + */ |
| 49 | + @BeforeClass |
| 50 | + public static void staticPrepare() throws Exception { |
| 51 | + Assume.assumeTrue( |
| 52 | + System.getenv("QUICKTEST") == null || System.getenv("QUICKTEST").equalsIgnoreCase("false")); |
| 53 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 54 | + logger.info("BEGIN"); |
| 55 | + |
| 56 | + // initialize test properties and create the directories |
| 57 | + initialize(appPropsFile); |
| 58 | + // renew lease at the begining for every test method, leaseId is set only for Wercker |
| 59 | + TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId()); |
| 60 | + |
| 61 | + logger.info("Run once, Creating Operator & " + "waiting for the script to complete execution"); |
| 62 | + // create operator |
| 63 | + operator = TestUtils.createOperator(opPropsFile); |
| 64 | + operatorProps = operator.getOperatorProps(); |
| 65 | + |
| 66 | + // create domain |
| 67 | + domain = TestUtils.createDomain(domainPropsFile); |
| 68 | + domainProps = domain.getDomainProps(); |
| 69 | + |
| 70 | + // initialize attributes to use in the tests |
| 71 | + domainUid = domainProps.getProperty("domainUID"); |
| 72 | + domainNS = domainProps.getProperty("namespace"); |
| 73 | + // logger.info("Domain props "+domainProps); |
| 74 | + logger.info("SUCCESS"); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Shutdown operator and domain |
| 79 | + * |
| 80 | + * @throws Exception |
| 81 | + */ |
| 82 | + @AfterClass |
| 83 | + public static void staticUnPrepare() throws Exception { |
| 84 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 85 | + logger.info("BEGIN"); |
| 86 | + logger.info("Run once, release cluster lease"); |
| 87 | + |
| 88 | + if (getLeaseId() != "") { |
| 89 | + logger.info("Release the k8s cluster lease"); |
| 90 | + TestUtils.releaseLease(getProjectRoot(), getLeaseId()); |
| 91 | + } |
| 92 | + |
| 93 | + logger.info("SUCCESS"); |
| 94 | + } |
| 95 | + /** |
| 96 | + * verify domain1 is unaffected |
| 97 | + * |
| 98 | + * @throws Exception |
| 99 | + */ |
| 100 | + public void verifyDomain1() throws Exception { |
| 101 | + ITFirstDomain.getDomain().verifyDomainCreated(); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Access Operator REST endpoint using admin node host and node port |
| 106 | + * |
| 107 | + * @throws Exception |
| 108 | + */ |
| 109 | + @Test |
| 110 | + public void testAdminServerExternalService() throws Exception { |
| 111 | + logTestBegin("testAdminServerExternalService"); |
| 112 | + domain.verifyAdminServerExternalService(getUsername(), getPassword()); |
| 113 | + logger.info("SUCCESS"); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Verify t3channel port by deploying webapp using the port |
| 118 | + * |
| 119 | + * @throws Exception |
| 120 | + */ |
| 121 | + @Test |
| 122 | + public void testAdminT3Channel() throws Exception { |
| 123 | + logTestBegin("testAdminT3Channel"); |
| 124 | + // check if the property is set to true |
| 125 | + Boolean exposeAdmint3Channel = new Boolean(domainProps.getProperty("exposeAdminT3Channel")); |
| 126 | + |
| 127 | + if (exposeAdmint3Channel != null && exposeAdmint3Channel.booleanValue()) { |
| 128 | + domain.deployWebAppViaWLST( |
| 129 | + TESTWEBAPP, |
| 130 | + getProjectRoot() + "/src/integration-tests/apps/testwebapp.war", |
| 131 | + getUsername(), |
| 132 | + getPassword()); |
| 133 | + } else { |
| 134 | + throw new RuntimeException("FAILURE: exposeAdminT3Channel is not set or false"); |
| 135 | + } |
| 136 | + domain.verifyWebAppLoadBalancing(TESTWEBAPP); |
| 137 | + logger.info("SUCCESS"); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Scale the cluster up/down using Operator REST endpoint, load balancing should adjust |
| 142 | + * accordingly. |
| 143 | + * |
| 144 | + * @throws Exception |
| 145 | + */ |
| 146 | + @Test |
| 147 | + public void testClusterScaling() throws Exception { |
| 148 | + logTestBegin("testClusterScaling"); |
| 149 | + String managedServerNameBase = domainProps.getProperty("managedServerNameBase"); |
| 150 | + int replicas = 3; |
| 151 | + String podName = domainUid + "-" + managedServerNameBase + replicas; |
| 152 | + String clusterName = domainProps.getProperty("clusterName"); |
| 153 | + |
| 154 | + logger.info("Scale domain " + domainUid + " Up to " + replicas + " managed servers"); |
| 155 | + operator.scale(domainUid, domainProps.getProperty("clusterName"), replicas); |
| 156 | + |
| 157 | + logger.info("Checking if managed pod(" + podName + ") is Running"); |
| 158 | + TestUtils.checkPodCreated(podName, domainNS); |
| 159 | + |
| 160 | + logger.info("Checking if managed server (" + podName + ") is Running"); |
| 161 | + TestUtils.checkPodReady(podName, domainNS); |
| 162 | + |
| 163 | + logger.info("Checking if managed service(" + podName + ") is created"); |
| 164 | + TestUtils.checkServiceCreated(podName, domainNS); |
| 165 | + |
| 166 | + int replicaCnt = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS); |
| 167 | + if (replicaCnt != replicas) { |
| 168 | + throw new RuntimeException( |
| 169 | + "FAILURE: Cluster replica doesn't match with scaled up size " |
| 170 | + + replicaCnt |
| 171 | + + "/" |
| 172 | + + replicas); |
| 173 | + } |
| 174 | + |
| 175 | + domain.verifyWebAppLoadBalancing(TESTWEBAPP); |
| 176 | + |
| 177 | + replicas = 2; |
| 178 | + podName = domainUid + "-" + managedServerNameBase + (replicas + 1); |
| 179 | + logger.info("Scale down to " + replicas + " managed servers"); |
| 180 | + operator.scale(domainUid, clusterName, replicas); |
| 181 | + |
| 182 | + logger.info("Checking if managed pod(" + podName + ") is deleted"); |
| 183 | + TestUtils.checkPodDeleted(podName, domainNS); |
| 184 | + |
| 185 | + replicaCnt = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS); |
| 186 | + if (replicaCnt != replicas) { |
| 187 | + throw new RuntimeException( |
| 188 | + "FAILURE: Cluster replica doesn't match with scaled down size " |
| 189 | + + replicaCnt |
| 190 | + + "/" |
| 191 | + + replicas); |
| 192 | + } |
| 193 | + |
| 194 | + domain.verifyWebAppLoadBalancing(TESTWEBAPP); |
| 195 | + |
| 196 | + // verfiy scaling has no impact on domains1 |
| 197 | + ITFirstDomain.getDomain().verifyDomainCreated(); |
| 198 | + logger.info("SUCCESS"); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * test delete and recreate domain1 has no impact on domain4 |
| 203 | + * |
| 204 | + * @throws Exception |
| 205 | + */ |
| 206 | + @Test |
| 207 | + public void testDeleteAndRecreteDomain1() throws Exception { |
| 208 | + |
| 209 | + Domain domain1 = ITFirstDomain.getDomain(); |
| 210 | + domain1.destroy(); |
| 211 | + domain1.create(); |
| 212 | + |
| 213 | + // verify domain4 has no impact |
| 214 | + domain.verifyDomainCreated(); |
| 215 | + } |
| 216 | + |
| 217 | + public static Domain getDomain() { |
| 218 | + return domain; |
| 219 | + } |
| 220 | +} |
0 commit comments