|
| 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 | +package oracle.kubernetes.operator; |
| 5 | + |
| 6 | +import static oracle.kubernetes.operator.BaseTest.initialize; |
| 7 | +import static oracle.kubernetes.operator.BaseTest.logger; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.nio.charset.Charset; |
| 11 | +import java.nio.charset.StandardCharsets; |
| 12 | +import java.nio.file.Files; |
| 13 | +import java.nio.file.Path; |
| 14 | +import java.nio.file.Paths; |
| 15 | +import java.util.Map; |
| 16 | +import java.util.logging.Level; |
| 17 | +import oracle.kubernetes.operator.utils.Domain; |
| 18 | +import oracle.kubernetes.operator.utils.ExecResult; |
| 19 | +import oracle.kubernetes.operator.utils.Operator; |
| 20 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 21 | +import org.junit.AfterClass; |
| 22 | +import org.junit.Assert; |
| 23 | +import org.junit.Assume; |
| 24 | +import org.junit.BeforeClass; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +/** JUnit test class used for testing configuration override use cases. */ |
| 28 | +public class ITSitConfig extends BaseTest { |
| 29 | + |
| 30 | + private static String TEST_RES_DIR; |
| 31 | + private static String ADMINPODNAME; |
| 32 | + private static final String DOMAINUID = "customsitconfigdomain"; |
| 33 | + private static final String ADMINPORT = "30710"; |
| 34 | + private static final int T3CHANNELPORT = 30091; |
| 35 | + private static final String MYSQL_DB_PORT = "31306"; |
| 36 | + private static String fqdn; |
| 37 | + private static String JDBC_URL; |
| 38 | + private static String KUBE_EXEC_CMD; |
| 39 | + private static Domain domain; |
| 40 | + private static Operator operator1; |
| 41 | + private static String sitconfigTmpDir = ""; |
| 42 | + private static String mysqltmpDir = ""; |
| 43 | + private static String configOverrideDir = ""; |
| 44 | + private static String mysqlYamlFile = ""; |
| 45 | + |
| 46 | + /** |
| 47 | + * This method gets called only once before any of the test methods are executed. It does the |
| 48 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 49 | + * the resultRoot, pvRoot and projectRoot attributes. |
| 50 | + * |
| 51 | + * @throws Exception when the initialization, creating directories , copying files and domain |
| 52 | + * creation fails. |
| 53 | + */ |
| 54 | + @BeforeClass |
| 55 | + public static void staticPrepare() throws Exception { |
| 56 | + // initialize test properties and create the directories |
| 57 | + if (!QUICKTEST) { |
| 58 | + // initialize test properties and create the directories |
| 59 | + initialize(APP_PROPS_FILE); |
| 60 | + if (operator1 == null) { |
| 61 | + operator1 = TestUtils.createOperator(OPERATOR1_YAML); |
| 62 | + } |
| 63 | + TEST_RES_DIR = BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/"; |
| 64 | + sitconfigTmpDir = BaseTest.getResultDir() + "/sitconfigtemp"; |
| 65 | + mysqltmpDir = sitconfigTmpDir + "/mysql"; |
| 66 | + configOverrideDir = sitconfigTmpDir + "/configoverridefiles"; |
| 67 | + mysqlYamlFile = mysqltmpDir + "/mysql-dbservices.yml"; |
| 68 | + Files.createDirectories(Paths.get(sitconfigTmpDir)); |
| 69 | + Files.createDirectories(Paths.get(configOverrideDir)); |
| 70 | + Files.createDirectories(Paths.get(mysqltmpDir)); |
| 71 | + // Create the MySql db container |
| 72 | + copyMySqlFile(); |
| 73 | + ExecResult result = TestUtils.exec("kubectl create -f " + mysqlYamlFile); |
| 74 | + Assert.assertEquals(0, result.exitValue()); |
| 75 | + |
| 76 | + fqdn = TestUtils.getHostName(); |
| 77 | + JDBC_URL = "jdbc:mysql://" + fqdn + ":" + MYSQL_DB_PORT + "/"; |
| 78 | + // copy the configuration override files to replacing the JDBC_URL token |
| 79 | + copySitConfigFiles(); |
| 80 | + // create weblogic domain with configOverrides |
| 81 | + domain = createSitConfigDomain(); |
| 82 | + Assert.assertNotNull(domain); |
| 83 | + // copy the jmx test client file the administratioin server weblogic server pod |
| 84 | + ADMINPODNAME = domain.getDomainUid() + "-" + domain.getAdminServerName(); |
| 85 | + TestUtils.copyFileViaCat( |
| 86 | + TEST_RES_DIR + "sitconfig/java/SitConfigTests.java", |
| 87 | + "SitConfigTests.java", |
| 88 | + ADMINPODNAME, |
| 89 | + domain.getDomainNS()); |
| 90 | + TestUtils.copyFileViaCat( |
| 91 | + TEST_RES_DIR + "sitconfig/scripts/runSitConfigTests.sh", |
| 92 | + "runSitConfigTests.sh", |
| 93 | + ADMINPODNAME, |
| 94 | + domain.getDomainNS()); |
| 95 | + KUBE_EXEC_CMD = |
| 96 | + "kubectl -n " + domain.getDomainNS() + " exec -it " + ADMINPODNAME + " -- bash -c"; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Destroy domain, delete the MySQL DB container and teardown. |
| 102 | + * |
| 103 | + * @throws Exception when domain destruction or MySQL container destruction fails |
| 104 | + */ |
| 105 | + @AfterClass |
| 106 | + public static void staticUnPrepare() throws Exception { |
| 107 | + if (!QUICKTEST) { |
| 108 | + ExecResult result = TestUtils.exec("kubectl delete -f " + mysqlYamlFile); |
| 109 | + destroySitConfigDomain(); |
| 110 | + tearDown(); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * This test covers custom configuration override use cases for config.xml. |
| 116 | + * |
| 117 | + * <p>The test checks the overridden config.xml attributes connect-timeout, max-message-size, |
| 118 | + * restart-max, JMXCore and ServerLifeCycle debug flags, the T3Channel public address. The |
| 119 | + * overridden are verified against the ServerConfig MBean tree. It does not verifies whether the |
| 120 | + * overridden values are applied to the runtime. |
| 121 | + * |
| 122 | + * @throws Exception when the assertion fails due to unmatched values |
| 123 | + */ |
| 124 | + @Test |
| 125 | + public void testCustomSitConfigOverridesForDomain() throws Exception { |
| 126 | + Assume.assumeFalse(QUICKTEST); |
| 127 | + boolean testCompletedSuccessfully = false; |
| 128 | + String testMethod = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 129 | + logTestBegin(testMethod); |
| 130 | + ExecResult result = |
| 131 | + TestUtils.exec( |
| 132 | + KUBE_EXEC_CMD |
| 133 | + + " 'sh runSitConfigTests.sh " |
| 134 | + + fqdn |
| 135 | + + " " |
| 136 | + + T3CHANNELPORT |
| 137 | + + " weblogic welcome1 " |
| 138 | + + testMethod |
| 139 | + + "'"); |
| 140 | + assertResult(result); |
| 141 | + testCompletedSuccessfully = true; |
| 142 | + logger.log(Level.INFO, "SUCCESS - {0}", testMethod); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * This test covers custom resource override use cases for JDBC resource. |
| 147 | + * |
| 148 | + * <p>The resource override sets the following connection pool properties. initialCapacity, |
| 149 | + * maxCapacity, test-connections-on-reserve, connection-harvest-max-count, |
| 150 | + * inactive-connection-timeout-seconds in the JDBC resource override file. It also overrides the |
| 151 | + * jdbc driver parameters like data source url, db user and password using kubernetes secret. |
| 152 | + * |
| 153 | + * <p>The overridden values are verified against the ServerConfig MBean tree. It does not verifies |
| 154 | + * whether the overridden values are applied to the runtime except the JDBC URL which is verified |
| 155 | + * at runtime by making a connection to the MySql database and executing a DDL statement. |
| 156 | + * |
| 157 | + * @throws Exception when the assertion fails due to unmatched values |
| 158 | + */ |
| 159 | + @Test |
| 160 | + public void testCustomSitConfigOverridesForJdbc() throws Exception { |
| 161 | + Assume.assumeFalse(QUICKTEST); |
| 162 | + boolean testCompletedSuccessfully = false; |
| 163 | + String testMethod = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 164 | + logTestBegin(testMethod); |
| 165 | + ExecResult result = |
| 166 | + TestUtils.exec( |
| 167 | + KUBE_EXEC_CMD |
| 168 | + + " 'sh runSitConfigTests.sh " |
| 169 | + + fqdn |
| 170 | + + " " |
| 171 | + + T3CHANNELPORT |
| 172 | + + " weblogic welcome1 " |
| 173 | + + testMethod |
| 174 | + + " " |
| 175 | + + JDBC_URL |
| 176 | + + "'"); |
| 177 | + assertResult(result); |
| 178 | + testCompletedSuccessfully = true; |
| 179 | + logger.log(Level.INFO, "SUCCESS - {0}", testMethod); |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * This test covers custom resource use cases for JMS resource. The JMS resource override file |
| 184 | + * sets the following Delivery Failure Parameters re delivery limit and expiration policy for a |
| 185 | + * uniform-distributed-topic JMS resource. |
| 186 | + * |
| 187 | + * <p>The overridden values are verified against the ServerConfig MBean tree. It does not verifies |
| 188 | + * whether the overridden values are applied to the runtime. |
| 189 | + * |
| 190 | + * @throws Exception when the assertion fails due to unmatched values |
| 191 | + */ |
| 192 | + @Test |
| 193 | + public void testCustomSitConfigOverridesForJms() throws Exception { |
| 194 | + Assume.assumeFalse(QUICKTEST); |
| 195 | + boolean testCompletedSuccessfully = false; |
| 196 | + String testMethod = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 197 | + logTestBegin(testMethod); |
| 198 | + ExecResult result = |
| 199 | + TestUtils.exec( |
| 200 | + KUBE_EXEC_CMD |
| 201 | + + " 'sh runSitConfigTests.sh " |
| 202 | + + fqdn |
| 203 | + + " " |
| 204 | + + T3CHANNELPORT |
| 205 | + + " weblogic welcome1 " |
| 206 | + + testMethod |
| 207 | + + "'"); |
| 208 | + assertResult(result); |
| 209 | + testCompletedSuccessfully = true; |
| 210 | + logger.log(Level.INFO, "SUCCESS - {0}", testMethod); |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * This test covers custom resource override use cases for diagnostics resource. It adds the |
| 215 | + * following instrumentation monitors. Connector_After_Inbound, Connector_Around_Outbound, |
| 216 | + * Connector_Around_Tx, Connector_Around_Work, Connector_Before_Inbound, and harvesters for |
| 217 | + * weblogic.management.runtime.JDBCServiceRuntimeMBean, |
| 218 | + * weblogic.management.runtime.ServerRuntimeMBean. |
| 219 | + * |
| 220 | + * <p>The overridden values are verified against the ServerConfig MBean tree. It does not verifies |
| 221 | + * whether the overridden values are applied to the runtime. |
| 222 | + * |
| 223 | + * @throws Exception when the assertion fails due to unmatched values |
| 224 | + */ |
| 225 | + @Test |
| 226 | + public void testCustomSitConfigOverridesForWldf() throws Exception { |
| 227 | + Assume.assumeFalse(QUICKTEST); |
| 228 | + boolean testCompletedSuccessfully = false; |
| 229 | + String testMethod = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 230 | + logTestBegin(testMethod); |
| 231 | + ExecResult result = |
| 232 | + TestUtils.exec( |
| 233 | + KUBE_EXEC_CMD |
| 234 | + + " 'sh runSitConfigTests.sh " |
| 235 | + + fqdn |
| 236 | + + " " |
| 237 | + + T3CHANNELPORT |
| 238 | + + " weblogic welcome1 " |
| 239 | + + testMethod |
| 240 | + + "'"); |
| 241 | + assertResult(result); |
| 242 | + testCompletedSuccessfully = true; |
| 243 | + logger.log(Level.INFO, "SUCCESS - {0}", testMethod); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * Create Domain using the custom domain script create-domain-auto-custom-sit-config20.py |
| 248 | + * Customizes the following attributes of the domain map configOverrides, configOverridesFile |
| 249 | + * domain uid , admin node port and t3 channel port. |
| 250 | + * |
| 251 | + * @return - created domain |
| 252 | + * @throws Exception - if it cannot create the domain |
| 253 | + */ |
| 254 | + private static Domain createSitConfigDomain() throws Exception { |
| 255 | + String createDomainScript = TEST_RES_DIR + "/domain-home-on-pv/create-domain.py"; |
| 256 | + // load input yaml to map and add configOverrides |
| 257 | + Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML); |
| 258 | + domainMap.put("configOverrides", "sitconfigcm"); |
| 259 | + domainMap.put("configOverridesFile", configOverrideDir); |
| 260 | + domainMap.put("domainUID", DOMAINUID); |
| 261 | + domainMap.put("adminNodePort", new Integer(ADMINPORT)); |
| 262 | + domainMap.put("t3ChannelPort", new Integer(T3CHANNELPORT)); |
| 263 | + domainMap.put( |
| 264 | + "createDomainPyScript", |
| 265 | + "integration-tests/src/test/resources/sitconfig/scripts/create-domain-auto-custom-sit-config20.py"); |
| 266 | + domainMap.put( |
| 267 | + "javaOptions", |
| 268 | + "-Dweblogic.debug.DebugSituationalConfig=true -Dweblogic.debug.DebugSituationalConfigDumpXml=true"); |
| 269 | + domain = TestUtils.createDomain(domainMap); |
| 270 | + domain.verifyDomainCreated(); |
| 271 | + return domain; |
| 272 | + } |
| 273 | + |
| 274 | + /** |
| 275 | + * Destroys the domain. |
| 276 | + * |
| 277 | + * @throws Exception when domain destruction fails |
| 278 | + */ |
| 279 | + private static void destroySitConfigDomain() throws Exception { |
| 280 | + if (domain != null) { |
| 281 | + domain.destroy(); |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * Copy the configuration override files to a staging area after replacing the JDBC_URL token in |
| 287 | + * jdbc-JdbcTestDataSource-0.xml. |
| 288 | + * |
| 289 | + * @throws IOException when copying files from source location to staging area fails |
| 290 | + */ |
| 291 | + private static void copySitConfigFiles() throws IOException { |
| 292 | + String src_dir = TEST_RES_DIR + "/sitconfig/configoverrides"; |
| 293 | + String dst_dir = configOverrideDir; |
| 294 | + String files[] = { |
| 295 | + "config.xml", |
| 296 | + "jdbc-JdbcTestDataSource-0.xml", |
| 297 | + "diagnostics-WLDF-MODULE-0.xml", |
| 298 | + "jms-ClusterJmsSystemResource.xml", |
| 299 | + "version.txt" |
| 300 | + }; |
| 301 | + for (String file : files) { |
| 302 | + Path path = Paths.get(src_dir, file); |
| 303 | + logger.log(Level.INFO, "Copying {0}", path.toString()); |
| 304 | + Charset charset = StandardCharsets.UTF_8; |
| 305 | + String content = new String(Files.readAllBytes(path), charset); |
| 306 | + content = content.replaceAll("JDBC_URL", JDBC_URL); |
| 307 | + path = Paths.get(dst_dir, file); |
| 308 | + logger.log(Level.INFO, "to {0}", path.toString()); |
| 309 | + Files.write(path, content.getBytes(charset)); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + /** |
| 314 | + * A utility method to copy MySQL yaml template file replacing the NAMESPACE and DOMAINUID. |
| 315 | + * |
| 316 | + * @throws IOException when copying files from source location to staging area fails |
| 317 | + */ |
| 318 | + private static void copyMySqlFile() throws IOException { |
| 319 | + Path src = Paths.get(TEST_RES_DIR + "/mysql/mysql-dbservices.ymlt"); |
| 320 | + Path dst = Paths.get(mysqlYamlFile); |
| 321 | + logger.log(Level.INFO, "Copying {0}", src.toString()); |
| 322 | + Charset charset = StandardCharsets.UTF_8; |
| 323 | + String content = new String(Files.readAllBytes(src), charset); |
| 324 | + content = content.replaceAll("@NAMESPACE@", "default"); |
| 325 | + content = content.replaceAll("@DOMAIN_UID@", DOMAINUID); |
| 326 | + logger.log(Level.INFO, "to {0}", dst.toString()); |
| 327 | + Files.write(dst, content.getBytes(charset)); |
| 328 | + } |
| 329 | + |
| 330 | + /** |
| 331 | + * Verifies the test run result doesn't contain any errors and exit status is 0. |
| 332 | + * |
| 333 | + * @param result - ExecResult object containing result of the test run |
| 334 | + */ |
| 335 | + private void assertResult(ExecResult result) { |
| 336 | + logger.log(Level.INFO, result.stdout().trim()); |
| 337 | + Assert.assertFalse(result.stdout().toLowerCase().contains("error")); |
| 338 | + Assert.assertFalse(result.stderr().toLowerCase().contains("error")); |
| 339 | + Assert.assertEquals(0, result.exitValue()); |
| 340 | + } |
| 341 | +} |
0 commit comments