|
| 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.nio.file.Files; |
| 8 | +import java.nio.file.Paths; |
| 9 | +import java.util.Properties; |
| 10 | +import java.util.logging.Logger; |
| 11 | +import oracle.kubernetes.operator.utils.ExecCommand; |
| 12 | +import oracle.kubernetes.operator.utils.ExecResult; |
| 13 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 14 | + |
| 15 | +/** |
| 16 | + * Base class which contains common methods to create/shutdown operator and domain. IT tests can |
| 17 | + * extend this class. |
| 18 | + */ |
| 19 | +public class BaseTest { |
| 20 | + public static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT"); |
| 21 | + |
| 22 | + private static String resultRoot = ""; |
| 23 | + private static String pvRoot = ""; |
| 24 | + // private static String resultDir = ""; |
| 25 | + private static String userProjectsDir = ""; |
| 26 | + private static String projectRoot = ""; |
| 27 | + private static String username = "weblogic"; |
| 28 | + private static String password = "welcome1"; |
| 29 | + private static int maxIterationsPod = 50; |
| 30 | + private static int waitTimePod = 5; |
| 31 | + private static String leaseId = ""; |
| 32 | + |
| 33 | + private static Properties appProps; |
| 34 | + |
| 35 | + public static void initialize(String appPropsFile) throws Exception { |
| 36 | + |
| 37 | + // load app props defined |
| 38 | + appProps = TestUtils.loadProps(appPropsFile); |
| 39 | + |
| 40 | + // check app props |
| 41 | + String baseDir = appProps.getProperty("baseDir"); |
| 42 | + if (baseDir == null) { |
| 43 | + throw new IllegalArgumentException("FAILURE: baseDir is not set"); |
| 44 | + } |
| 45 | + username = appProps.getProperty("username", username); |
| 46 | + password = appProps.getProperty("password", password); |
| 47 | + maxIterationsPod = |
| 48 | + new Integer(appProps.getProperty("maxIterationsPod", "" + maxIterationsPod)).intValue(); |
| 49 | + waitTimePod = new Integer(appProps.getProperty("waitTimePod", "" + waitTimePod)).intValue(); |
| 50 | + if (System.getenv("RESULT_ROOT") != null) { |
| 51 | + resultRoot = System.getenv("RESULT_ROOT"); |
| 52 | + } else { |
| 53 | + resultRoot = baseDir + "/" + System.getProperty("user.name") + "/wl_k8s_test_results"; |
| 54 | + } |
| 55 | + if (System.getenv("PV_ROOT") != null) { |
| 56 | + pvRoot = System.getenv("PV_ROOT"); |
| 57 | + } else { |
| 58 | + pvRoot = resultRoot; |
| 59 | + } |
| 60 | + if (System.getenv("LEASE_ID") != null) { |
| 61 | + leaseId = System.getenv("LEASE_ID"); |
| 62 | + } |
| 63 | + // resultDir = resultRoot + "/acceptance_test_tmp"; |
| 64 | + userProjectsDir = resultRoot + "/acceptance_test_tmp/user-projects"; |
| 65 | + projectRoot = System.getProperty("user.dir") + "/.."; |
| 66 | + logger.info("RESULT_ROOT =" + resultRoot); |
| 67 | + logger.info("PV_ROOT =" + pvRoot); |
| 68 | + logger.info("userProjectsDir =" + userProjectsDir); |
| 69 | + logger.info("projectRoot =" + projectRoot); |
| 70 | + |
| 71 | + logger.info("Env var RESULT_ROOT " + System.getenv("RESULT_ROOT")); |
| 72 | + logger.info("Env var PV_ROOT " + System.getenv("PV_ROOT")); |
| 73 | + logger.info("Env var K8S_NODEPORT_HOST " + System.getenv("K8S_NODEPORT_HOST")); |
| 74 | + logger.info("Env var IMAGE_NAME_OPERATOR= " + System.getenv("IMAGE_NAME_OPERATOR")); |
| 75 | + logger.info("Env var IMAGE_TAG_OPERATOR " + System.getenv("IMAGE_TAG_OPERATOR")); |
| 76 | + logger.info( |
| 77 | + "Env var IMAGE_PULL_POLICY_OPERATOR " + System.getenv("IMAGE_PULL_POLICY_OPERATOR")); |
| 78 | + logger.info( |
| 79 | + "Env var IMAGE_PULL_SECRET_OPERATOR " + System.getenv("IMAGE_PULL_SECRET_OPERATOR")); |
| 80 | + logger.info( |
| 81 | + "Env var IMAGE_PULL_SECRET_WEBLOGIC " + System.getenv("IMAGE_PULL_SECRET_WEBLOGIC")); |
| 82 | + |
| 83 | + // create resultRoot, PVRoot, etc |
| 84 | + Files.createDirectories(Paths.get(resultRoot)); |
| 85 | + |
| 86 | + if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) { |
| 87 | + logger.info("Creating PVROOT " + pvRoot); |
| 88 | + Files.createDirectories(Paths.get(pvRoot)); |
| 89 | + ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot); |
| 90 | + if (result.exitValue() != 0) { |
| 91 | + throw new RuntimeException( |
| 92 | + "FAILURE: Couldn't change permissions for PVROOT " + result.stderr()); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // Files.createDirectories(Paths.get(resultDir)); |
| 97 | + |
| 98 | + Files.createDirectories(Paths.get(userProjectsDir)); |
| 99 | + } |
| 100 | + |
| 101 | + public static String getResultRoot() { |
| 102 | + return resultRoot; |
| 103 | + } |
| 104 | + |
| 105 | + public static String getPvRoot() { |
| 106 | + return pvRoot; |
| 107 | + } |
| 108 | + |
| 109 | + public static String getUserProjectsDir() { |
| 110 | + return userProjectsDir; |
| 111 | + } |
| 112 | + |
| 113 | + public static String getProjectRoot() { |
| 114 | + return projectRoot; |
| 115 | + } |
| 116 | + |
| 117 | + public static String getUsername() { |
| 118 | + return username; |
| 119 | + } |
| 120 | + |
| 121 | + public static String getPassword() { |
| 122 | + return password; |
| 123 | + } |
| 124 | + |
| 125 | + public static int getMaxIterationsPod() { |
| 126 | + return maxIterationsPod; |
| 127 | + } |
| 128 | + |
| 129 | + public static int getWaitTimePod() { |
| 130 | + return waitTimePod; |
| 131 | + } |
| 132 | + |
| 133 | + public static Properties getAppProps() { |
| 134 | + return appProps; |
| 135 | + } |
| 136 | + |
| 137 | + public static String getLeaseId() { |
| 138 | + return leaseId; |
| 139 | + } |
| 140 | + |
| 141 | + protected void logTestBegin(String testName) throws Exception { |
| 142 | + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); |
| 143 | + logger.info("BEGIN " + testName); |
| 144 | + // renew lease at the beginning for every test method, leaseId is set only for Wercker |
| 145 | + TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId()); |
| 146 | + } |
| 147 | +} |
0 commit comments