|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2020, Oracle Corporation and/or its affiliates. |
| 3 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +# |
| 5 | +# This script provisions a OKE Kubernetes cluster using terraform (https://www.terraform.io/) and runs the new |
| 6 | +# integration test suite against that cluster. Blog https://blogs.oracle.com/weblogicserver/easily-create-an-oci-container-engine-for-kubernetes-cluster-with-terraform-installer-to-run-weblogic-server |
| 7 | +# provides detailed explanation for OCI properties file creation. |
| 8 | +# |
| 9 | +# |
| 10 | +# As of May 6, 2020, the tests are clean on Kubernetes 1.16 with the following JDK workarounds: |
| 11 | +# 1. Maven must be run with OpenJDK 11.0.7, available here: https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.7%2B10/OpenJDK11U-jdk_x64_linux_11.0.7_10.tar.gz |
| 12 | +# This is because of a critical bug fix. Unfortunately, the Oracle JDK 11.0.7 release was based on an earlier build and doesn't have the fix. |
| 13 | +# 2. The WebLogic Image Tool will not accept an OpenJDK JDK. Set WIT_JAVA_HOME to an Oracle JDK Java Home. |
| 14 | +# For example, "export WIT_JAVA_HOME=/usr/java/jdk-11.0.7" before running this script. |
| 15 | +# |
| 16 | +set -o errexit |
| 17 | +set -o pipefail |
| 18 | + |
| 19 | +script="${BASH_SOURCE[0]}" |
| 20 | +scriptDir="$( cd "$( dirname "${script}" )" && pwd )" |
| 21 | + |
| 22 | +function usage { |
| 23 | + echo "usage: ${script} [-n <terraform config files directory>] [-o <directory>] [-t <tests>] [-c <name>] [-p true|false] [-x <number_of_threads>] [-d <wdt_download_url>] [-i <wit_download_url>] [-m <maven_profile_name>] [-h]" |
| 24 | + echo " -n Terraform config files directory " |
| 25 | + echo " -o Output directory (optional) " |
| 26 | + echo " (default: \${WORKSPACE}/logdir/\${BUILD_TAG}, if \${WORKSPACE} defined, else /scratch/\${USER}/kindtest) " |
| 27 | + echo " -b Availability Domain Name " |
| 28 | + echo " (for example: VPGL:PHX-AD-1 , check limits quota with OCI admin)" |
| 29 | + echo " -t Test filter (optional) " |
| 30 | + echo " (default: **/It*) " |
| 31 | + echo " -s Oracle Cloud Infra properties file " |
| 32 | + echo " -p Run It classes in parallel" |
| 33 | + echo " (default: false) " |
| 34 | + echo " -x Number of threads to run the classes in parallel" |
| 35 | + echo " (default: 2) " |
| 36 | + echo " -d WDT download URL" |
| 37 | + echo " (default: https://github.com/oracle/weblogic-deploy-tooling/releases/latest) " |
| 38 | + echo " -i WIT download URL" |
| 39 | + echo " (default: https://github.com/oracle/weblogic-image-tool/releases/latest) " |
| 40 | + echo " -m Run integration-tests or oke-cert " |
| 41 | + echo " (default: integration-tests, supported values: oke-cert) " |
| 42 | + echo " -h Help" |
| 43 | + exit $1 |
| 44 | +} |
| 45 | + |
| 46 | +function prop { |
| 47 | + grep "${1}" ${oci_property_file}| grep -v "#" | cut -d'=' -f2 |
| 48 | +} |
| 49 | + |
| 50 | +if [[ -z "${WORKSPACE}" ]]; then |
| 51 | + outdir="/scratch/${USER}/oketest" |
| 52 | + export WORKSPACE=${PWD} |
| 53 | +else |
| 54 | + outdir="${WORKSPACE}/logdir/${BUILD_TAG}" |
| 55 | +fi |
| 56 | +test_filter="**/It*" |
| 57 | +parallel_run="false" |
| 58 | +threads="2" |
| 59 | +wdt_download_url="https://github.com/oracle/weblogic-deploy-tooling/releases/latest" |
| 60 | +wit_download_url="https://github.com/oracle/weblogic-image-tool/releases/latest" |
| 61 | +maven_profile_name="integration-tests" |
| 62 | + |
| 63 | +while getopts ":h:n:o:t:x:s:p:d:i:m:b:" opt; do |
| 64 | + case $opt in |
| 65 | + n) terraform_script_dir_name="${OPTARG}" |
| 66 | + ;; |
| 67 | + s) oci_property_file="${OPTARG}" |
| 68 | + ;; |
| 69 | + b) availability_domain="${OPTARG}" |
| 70 | + ;; |
| 71 | + o) outdir="${OPTARG}" |
| 72 | + ;; |
| 73 | + t) test_filter="${OPTARG}" |
| 74 | + ;; |
| 75 | + x) threads="${OPTARG}" |
| 76 | + ;; |
| 77 | + p) parallel_run="${OPTARG}" |
| 78 | + ;; |
| 79 | + d) wdt_download_url="${OPTARG}" |
| 80 | + ;; |
| 81 | + i) wit_download_url="${OPTARG}" |
| 82 | + ;; |
| 83 | + m) maven_profile_name="${OPTARG}" |
| 84 | + ;; |
| 85 | + h) usage 0 |
| 86 | + ;; |
| 87 | + d) echo "Ignoring -d=${OPTARG}" |
| 88 | + ;; |
| 89 | + i) echo "Ignoring -i=${OPTARG}" |
| 90 | + ;; |
| 91 | + *) usage 1 |
| 92 | + ;; |
| 93 | + esac |
| 94 | +done |
| 95 | + |
| 96 | +k8s_version=$(prop 'k8s.version') |
| 97 | +echo "Using Kubernetes version: ${k8s_version}" |
| 98 | + |
| 99 | +mkdir -m777 -p "${outdir}" |
| 100 | +export RESULT_ROOT="${outdir}/wl_k8s_test_results" |
| 101 | +if [ -d "${RESULT_ROOT}" ]; then |
| 102 | + rm -Rf "${RESULT_ROOT}/*" |
| 103 | +else |
| 104 | + mkdir -m777 "${RESULT_ROOT}" |
| 105 | +fi |
| 106 | + |
| 107 | +echo "Results will be in ${RESULT_ROOT}" |
| 108 | + |
| 109 | +export PV_ROOT="${outdir}/k8s-pvroot" |
| 110 | +if [ -d "${PV_ROOT}" ]; then |
| 111 | + rm -Rf "${PV_ROOT}/*" |
| 112 | +else |
| 113 | + mkdir -m777 "${PV_ROOT}" |
| 114 | +fi |
| 115 | + |
| 116 | +echo "Persistent volume files, if any, will be in ${PV_ROOT}" |
| 117 | + |
| 118 | +echo 'Create a OKE cluster' |
| 119 | +mkdir -p "${WORKSPACE}/terraform" |
| 120 | +cp -rf ${terraform_script_dir_name}/*.tf ${WORKSPACE}/terraform/. |
| 121 | +cp -rf ${WORKSPACE}/kubernetes/samples/scripts/terraform/template.tfvars ${WORKSPACE}/terraform/. |
| 122 | +cp -rf ${WORKSPACE}/kubernetes/samples/scripts/terraform/*.sh ${WORKSPACE}/terraform/. |
| 123 | +chmod 777 ${WORKSPACE}/terraform/*.sh |
| 124 | +mkdir -p ${WORKSPACE}/terraform/terraforminstall |
| 125 | + |
| 126 | +if ! sh ${WORKSPACE}/terraform/oke.create.sh ${oci_property_file} ${WORKSPACE}/terraform ; then |
| 127 | + sh ${WORKSPACE}/terraform/oke.delete.sh ${oci_property_file} ${WORKSPACE}/terraform |
| 128 | +fi |
| 129 | + |
| 130 | +clusterName=$(prop 'okeclustername') |
| 131 | + |
| 132 | +export KUBECONFIG=${WORKSPACE}/terraform/${clusterName}_kubeconfig |
| 133 | +export PATH=${WORKSPACE}/terraform/terraforminstall:$PATH |
| 134 | + |
| 135 | +echo "creating storage class to setup OFSS ..." |
| 136 | + |
| 137 | +echo "getting MountTarget ID" |
| 138 | +compartment_ocid=$(prop 'compartment.ocid') |
| 139 | +mount_target_id=`oci fs mount-target list --compartment-id=$compartment_ocid --display-name=${clusterName}-mt --availability-domain=${availability_domain} | jq -r '.data[] | .id'` |
| 140 | +mt_privateip_id=`oci fs mount-target list --compartment-id=$compartment_ocid --display-name=${clusterName}-mt --availability-domain=${availability_domain} | jq -r '.data[] | ."private-ip-ids"[]'` |
| 141 | +mt_private_ip=`oci network private-ip get --private-ip-id $mt_privateip_id | jq -r '.data | ."ip-address"'` |
| 142 | + |
| 143 | +export NFS_SERVER=$mt_private_ip |
| 144 | +echo "Using NFS Server ${NFS_SERVER}" |
| 145 | +echo "Creating Storage Class to mount OFSS" |
| 146 | +cat << EOF | kubectl apply -f - |
| 147 | +kind: StorageClass |
| 148 | +apiVersion: storage.k8s.io/v1beta1 |
| 149 | +metadata: |
| 150 | + name: oci-fss |
| 151 | +provisioner: oracle.com/oci-fss |
| 152 | +parameters: |
| 153 | + # Insert mount target from the FSS here |
| 154 | + mntTargetId: ${mount_target_id} |
| 155 | +EOF |
| 156 | + |
| 157 | +echo 'Set up test running ENVVARs...' |
| 158 | +NODE_IP=`kubectl get nodes -o wide| awk '{print $7}'| tail -n+3` |
| 159 | +if [ -z "$NODE_IP" ]; then |
| 160 | + echo "retry get node ip "; |
| 161 | + sleep 15; |
| 162 | + NODE_IP=`kubectl get nodes -o wide| awk '{print $7}'| tail -n+3` |
| 163 | +fi |
| 164 | + |
| 165 | +export K8S_NODEPORT_HOST=$NODE_IP |
| 166 | +export JAVA_HOME="${JAVA_HOME:-`type -p java|xargs readlink -f|xargs dirname|xargs dirname`}" |
| 167 | + |
| 168 | +echo 'Clean up result root...' |
| 169 | +rm -rf "${RESULT_ROOT:?}/*" |
| 170 | +cd ${WORKSPACE} |
| 171 | +echo 'Run tests...' |
| 172 | +if [ "${maven_profile_name}" = "oke-cert" ]; then |
| 173 | + echo "Running mvn -Dwdt.download.url=${wdt_download_url} -Dwit.download.url=${wit_download_url} -Djdk.tls.client.protocols=TLSv1.2 -pl integration-tests -P ${maven_profile_name} verify 2>&1 | tee ${RESULT_ROOT}/oke.log" |
| 174 | + mvn -Dwdt.download.url="${wdt_download_url}" -Dwit.download.url="${wit_download_url}" -Djdk.tls.client.protocols=TLSv1.2 -pl integration-tests -P ${maven_profile_name} verify 2>&1 | tee "${RESULT_ROOT}/oke.log" |
| 175 | +else |
| 176 | + echo "Running mvn -Dit.test=${test_filter}, !ItExternalRmiTunneling, !ItSamples, !ItMiiSample, !ItTwoDomainsLoadBalancers, !ItMonitoringExporter, !ItPodRestart -Dwdt.download.url=${wdt_download_url} -Dwit.download.url=${wit_download_url} -Djdk.tls.client.protocols=TLSv1.2 -pl integration-tests -P integration-tests verify 2>&1 | tee ${RESULT_ROOT}/oke.log" |
| 177 | + mvn -Dit.test="${test_filter}, !ItExternalRmiTunneling, !ItSamples, !ItMiiSample, !ItTwoDomainsLoadBalancers, !ItMonitoringExporter, !ItPodRestart" -Dwdt.download.url="${wdt_download_url}" -Dwit.download.url="${wit_download_url}" -Djdk.tls.client.protocols=TLSv1.2 -pl integration-tests -P ${maven_profile_name} verify 2>&1 | tee "${RESULT_ROOT}/oke.log" |
| 178 | +fi |
0 commit comments