Browse code

Replace old build utility functions with `os::cmd::try_until_text`

With the advent of `os::cmd::try_until_text` and simple object indexing
with jsonpath, there is no need for cusom polling utility function impls
anymore. We can collapse on polling with `os::cmd` and the correct index
instead. We _do_ lose the early-exit functionality of these functions as
`os::cmd` doesn't support that, but the loss is worth it as we simplify
our Bash scripts.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>

Steve Kuznetsov authored on 2016/11/05 00:18:49
Showing 2 changed files
... ...
@@ -247,30 +247,6 @@ function install_registry() {
247 247
 }
248 248
 readonly -f install_registry
249 249
 
250
-# Wait for builds to start
251
-# $1 namespace
252
-function os::build:wait_for_start() {
253
-	echo "[INFO] Waiting for $1 namespace build to start"
254
-	wait_for_command "oc get -n $1 builds | grep -i running" $((10*TIME_MIN)) "oc get -n $1 builds | grep -i -e failed -e error"
255
-	BUILD_ID=`oc get -n $1 builds  --output-version=v1 --template="{{with index .items 0}}{{.metadata.name}}{{end}}"`
256
-	echo "[INFO] Build ${BUILD_ID} started"
257
-}
258
-readonly -f os::build:wait_for_start
259
-
260
-# Wait for builds to complete
261
-# $1 namespace
262
-function os::build:wait_for_end() {
263
-	echo "[INFO] Waiting for $1 namespace build to complete"
264
-	wait_for_command "oc get -n $1 builds | grep -i complete" $((10*TIME_MIN)) "oc get -n $1 builds | grep -i -e failed -e error"
265
-	BUILD_ID=`oc get -n $1 builds --output-version=v1 --template="{{with index .items 0}}{{.metadata.name}}{{end}}"`
266
-	echo "[INFO] Build ${BUILD_ID} finished"
267
-	# TODO: fix
268
-	set +e
269
-	oc build-logs -n $1 $BUILD_ID > $LOG_DIR/$1build.log
270
-	set -e
271
-}
272
-readonly -f os::build:wait_for_end
273
-
274 250
 # enable-selinux/disable-selinux use the shared control variable
275 251
 # SELINUX_DISABLED to determine whether to re-enable selinux after it
276 252
 # has been disabled.  The goal is to allow temporary disablement of
... ...
@@ -387,12 +387,12 @@ echo "[INFO] Applying STI application config"
387 387
 os::cmd::expect_success "oc create -f ${STI_CONFIG_FILE}"
388 388
 
389 389
 # Wait for build which should have triggered automatically
390
-echo "[INFO] Starting build from ${STI_CONFIG_FILE} and streaming its logs..."
391
-#oc start-build -n test ruby-sample-build --follow
392
-os::build:wait_for_start "test"
390
+os::cmd::try_until_text "oc get builds --namespace test -o jsonpath='{.items[0].status.phase}'" "Running" "$(( 10*TIME_MIN ))"
391
+BUILD_ID="$( oc get builds --namespace test -o jsonpath='{.items[0].metadata.name}' )"
393 392
 # Ensure that the build pod doesn't allow exec
394 393
 os::cmd::expect_failure_and_text "oc rsh ${BUILD_ID}-build" 'forbidden'
395
-os::build:wait_for_end "test"
394
+os::cmd::try_until_text "oc get builds --namespace test -o jsonpath='{.items[0].status.phase}'" "Complete" "$(( 10*TIME_MIN ))"
395
+os::cmd::expect_success "oc build-logs --namespace test '${BUILD_ID}' > '${LOG_DIR}/test-build.log'"
396 396
 wait_for_app "test"
397 397
 
398 398
 # logs can't be tested without a node, so has to be in e2e
... ...
@@ -439,14 +439,18 @@ os::cmd::expect_success_and_text "oc rsh ${frontend_pod} ls /tmp/sample-app" 'ap
439 439
 #oc create -n docker -f "${DOCKER_CONFIG_FILE}"
440 440
 #echo "[INFO] Invoking generic web hook to trigger new docker build using curl"
441 441
 #curl -k -X POST $API_SCHEME://$API_HOST:$API_PORT/oapi/v1/namespaces/docker/buildconfigs/ruby-sample-build/webhooks/secret101/generic && sleep 3
442
-#os::build:wait_for_end "docker"
442
+# BUILD_ID="$( oc get builds --namespace docker -o jsonpath='{.items[0].metadata.name}' )"
443
+# os::cmd::try_until_text "oc get builds --namespace docker -o jsonpath='{.items[0].status.phase}'" "Complete" "$(( 10*TIME_MIN ))"
444
+# os::cmd::expect_success "oc build-logs --namespace docker '${BUILD_ID}' > '${LOG_DIR}/docker-build.log'"
443 445
 #wait_for_app "docker"
444 446
 
445 447
 #echo "[INFO] Applying Custom application config"
446 448
 #oc create -n custom -f "${CUSTOM_CONFIG_FILE}"
447 449
 #echo "[INFO] Invoking generic web hook to trigger new custom build using curl"
448 450
 #curl -k -X POST $API_SCHEME://$API_HOST:$API_PORT/oapi/v1/namespaces/custom/buildconfigs/ruby-sample-build/webhooks/secret101/generic && sleep 3
449
-#os::build:wait_for_end "custom"
451
+# BUILD_ID="$( oc get builds --namespace custom -o jsonpath='{.items[0].metadata.name}' )"
452
+# os::cmd::try_until_text "oc get builds --namespace custom -o jsonpath='{.items[0].status.phase}'" "Complete" "$(( 10*TIME_MIN ))"
453
+# os::cmd::expect_success "oc build-logs --namespace custom '${BUILD_ID}' > '${LOG_DIR}/custom-build.log'"
450 454
 #wait_for_app "custom"
451 455
 
452 456
 echo "[INFO] Back to 'default' project with 'admin' user..."