@@ -27,19 +27,26 @@ export PATH="${GOPATH_BIN}:${PATH}"
2727source " ${REPO_ROOT} /hack/ensure-go.sh"
2828# shellcheck source=../hack/ensure-kubectl.sh
2929source " ${REPO_ROOT} /hack/ensure-kubectl.sh"
30+ # shellcheck source=../hack/boskos.sh
31+ source ${REPO_ROOT} /hack/boskos.sh
3032
3133ARTIFACTS=" ${ARTIFACTS:- ${PWD} / _artifacts} "
3234mkdir -p " ${ARTIFACTS} /logs/"
3335
3436ARCH=$( uname -m)
35- PVSADM_VERSION=${PVSADM_VERSION:- " v0.1.3" }
37+ PVSADM_VERSION=${PVSADM_VERSION:- " v0.1.4-alpha. 3" }
3638E2E_FLAVOR=${E2E_FLAVOR:- }
39+ REGION=${REGION:- " us-south" }
40+ RESOURCE_GROUP=${RESOURCE_GROUP:- " prow-resource-group" }
3741
3842trap cleanup EXIT
3943
4044cleanup (){
4145 # Delete the created ports for the network instance
4246 [ -n " ${NEW_PORT} " ] && ./pvsadm delete port --network ${IBMPOWERVS_NETWORK_NAME} --port-id ${PORT_ID} --instance-id ${IBMPOWERVS_SERVICE_INSTANCE_ID}
47+
48+ # stop the boskos heartbeat
49+ [[ -z ${HEART_BEAT_PID:- } ]] || kill -9 " ${HEART_BEAT_PID} " || true
4350}
4451
4552install_pvsadm (){
@@ -50,8 +57,26 @@ install_pvsadm(){
5057 chmod +x ./pvsadm
5158}
5259
60+ create_powervs_network_instance (){
61+ # Install ibmcloud CLI tool
62+ curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
63+
64+ # Login to IBM Cloud using the API Key
65+ ibmcloud login -a cloud.ibm.com -r ${REGION} -g ${RESOURCE_GROUP}
66+
67+ # Install power-iaas command-line plug-in and target the required service instance
68+ ibmcloud plugin install power-iaas
69+ CRN=$( ibmcloud resource service-instance ${IBMPOWERVS_SERVICE_INSTANCE_ID} --output json | jq -r ' .[].crn' )
70+ ibmcloud pi service-target ${CRN}
71+
72+ # Create the network instance
73+ ibmcloud pi network-create-public ${IBMPOWERVS_NETWORK_NAME} --dns-servers " 8.8.8.8 9.9.9.9"
74+
75+ }
76+
5377init_network_powervs (){
5478 install_pvsadm
79+ create_powervs_network_instance
5580
5681 # Creating ports using the pvsadm tool
5782 ./pvsadm create port --description " capi-port-e2e" --network ${IBMPOWERVS_NETWORK_NAME} --instance-id ${IBMPOWERVS_SERVICE_INSTANCE_ID}
@@ -68,10 +93,37 @@ prerequisites_powervs(){
6893 # Assigning PowerVS variables
6994 export IBMPOWERVS_IMAGE_NAME=${IBMPOWERVS_IMAGE_NAME:- " capibm-powervs-centos-streams8-1-22-4" }
7095 export IBMPOWERVS_SERVICE_INSTANCE_ID=${IBMPOWERVS_SERVICE_INSTANCE_ID:- " 0f28d13a-6e33-4d86-b6d7-a9b46ff7659e" }
71- export IBMPOWERVS_NETWORK_NAME=${IBMPOWERVS_NETWORK_NAME :- " capi-e2e-test" }
96+ export IBMPOWERVS_NETWORK_NAME=${BOSKOS_RESOURCE_NAME :- " capi-e2e-test" }
7297}
7398
7499main (){
100+ # If BOSKOS_HOST is set then acquire an IBM Cloud resource from Boskos.
101+ if [ -n " ${BOSKOS_HOST:- } " ]; then
102+ # Check out the resource from Boskos and store the produced environment
103+ # variables in a temporary file.
104+ account_env_var_file=" $( mktemp) "
105+ checkout_account 1> " ${account_env_var_file} "
106+ checkout_account_status=" ${?} "
107+
108+ # If the checkout process was a success then load the
109+ # environment variables into this process.
110+ [ " ${checkout_account_status} " = " 0" ] && . " ${account_env_var_file} "
111+
112+ # Always remove the account environment variable file which
113+ # could contain sensitive information.
114+ rm -f " ${account_env_var_file} "
115+
116+ if [ ! " ${checkout_account_status} " = " 0" ]; then
117+ echo " error getting account from boskos" 1>&2
118+ exit " ${checkout_account_status} "
119+ fi
120+
121+ # Run the heart beat process to tell Boskos that we are still
122+ # using the checked out resource periodically.
123+ heartbeat_account >> " $ARTIFACTS /logs/boskos.log" 2>&1 &
124+ HEART_BEAT_PID=$( echo $! )
125+ fi
126+
75127 if [[ " ${E2E_FLAVOR} " == " powervs" ]]; then
76128 prerequisites_powervs
77129 init_network_powervs
@@ -81,6 +133,9 @@ main(){
81133 make test-e2e
82134 test_status=" ${?} "
83135 echo TESTSTATUS=" ${test_status} "
136+
137+ # If Boskos is being used then release the IBM Cloud resource back to Boskos.
138+ [ -z " ${BOSKOS_HOST:- } " ] || release_account >> " $ARTIFACTS /logs/boskos.log" 2>&1
84139}
85140
86141main " $@ "
0 commit comments