Make ipa-downloader error fail the build
[icn.git] / env / metal3 / 03_launch_prereq.sh
index 3f6fc6e..9d58f57 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set -xe
+#!/usr/bin/env bash
+set -eux -o pipefail
 
 LIBDIR="$(dirname "$PWD")"
 
@@ -11,7 +11,7 @@ if [[ $EUID -ne 0 ]]; then
     exit 1
 fi
 
-function get_default_inteface_ipaddress {
+function get_default_interface_ipaddress {
     local _ip=$1
     local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
     local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
@@ -87,6 +87,12 @@ function install_ironic_container {
 
     docker wait ipa-downloader
 
+    if [ ! -e "$IRONIC_DATA_DIR/html/images/ironic-python-agent.kernel" ] ||
+       [ ! -e "$IRONIC_DATA_DIR/html/images/ironic-python-agent.initramfs" ]; then
+        echo "Failed to get ironic-python-agent"
+        exit 1
+    fi
+
     # Start dnsmasq, http, mariadb, and ironic containers using same image
     # See this file for env vars you can set, like IP, DHCP_RANGE, INTERFACE
     docker run -d --net host --privileged --name dnsmasq \
@@ -125,7 +131,7 @@ function remove_k8s_noschedule_taint {
 }
 
 function install_k8s_single_node {
-    get_default_inteface_ipaddress apiserver_advertise_addr
+    get_default_interface_ipaddress apiserver_advertise_addr
     kubeadm_init="kubeadm init --kubernetes-version=$KUBE_VERSION \
         --pod-network-cidr=$POD_NETWORK_CIDR \
         --apiserver-advertise-address=$apiserver_advertise_addr"
@@ -147,10 +153,18 @@ function install_dhcp {
     kubectl create -f $PWD/04_dhcp.yaml
 }
 
+function reset_dhcp {
+    kubectl delete -f $PWD/04_dhcp.yaml
+    if [ -d $BS_DHCP_DIR ]; then
+        rm -rf $BS_DHCP_DIR
+    fi
+}
+
 function create_ironic_env {
     cat <<EOF > ${PWD}/ironic.env
 PROVISIONING_INTERFACE=provisioning
 DHCP_RANGE=172.22.0.10,172.22.0.100
+IPA_BASEURI=https://images.rdoproject.org/train/rdo_trunk/current-tripleo
 DEPLOY_KERNEL_URL=http://172.22.0.1/images/ironic-python-agent.kernel
 DEPLOY_RAMDISK_URL=http://172.22.0.1/images/ironic-python-agent.initramfs
 IRONIC_ENDPOINT=http://172.22.0.1:6385/v1/
@@ -173,12 +187,20 @@ function install {
     #Todo - error handling mechanism
     create_ironic_env
     install_ironic_container
-    install_dhcp
 }
 
-if [ "$1" == "-o" ]; then
+if [ "$#" -eq 0 ]; then
+    install online
+elif [ "$1" == "-o" ]; then
     install offline
-    exit 0
+elif [ "$1" == "--dhcp-start" ]; then
+    install_dhcp
+    echo "wait for 320s for nodes to be assigned"
+    sleep 6m
+elif [ "$1" == "--dhcp-reset" ]; then
+    reset_dhcp
+    echo "wait for 320s for nodes to be re-assigned"
+    sleep 6m
+else
+    exit 1
 fi
-
-install