FIX for ip link state verification
[genesis.git] / common / ci / setup.sh
old mode 100644 (file)
new mode 100755 (executable)
index 73b0aa6..380ac4d
@@ -88,8 +88,9 @@ check_interface() {
   if [[ ${link_state} != 'UP' ]]; then
     echo "${blue}${interface} state is ${link_state}. Bringing it UP!${reset}"
     ip link set dev ${interface} up
+    sleep 5
     link_state=$(ip link show ${interface} | grep -oP 'state \K[^ ]+')
-    if [[ ${link_state} != 'UP' ]]; then
+    if [[ ${link_state} == 'DOWN' ]]; then
       echo "${red}Could not bring UP interface ${interface} link state is ${link_state}${reset}"
       exit 1
     fi
@@ -128,22 +129,19 @@ setup_pxe_bridge() {
 
   #Check whether PXE bridge exists
   echo "${blue}Checking whether PXE bridge ${pxe_bridge} exists${reset}"
-  if brctl show ${pxe_bridge} | grep 'No such device'; then
+  if brctl show ${pxe_bridge} 2>&1 | grep 'No such device'; then
     echo "${blue}Creating PXE bridge ${pxe_bridge}${reset}"
     brctl addbr ${pxe_bridge}
   else
     echo "${green}OK!${reset}"
   fi
 
-  #Check whether PXE bridge is UP
-  check_interface ${pxe_bridge}
-
   #Add VLAN 0 (PXE) interface to PXE bridge
   echo "${blue}Checking whether VLAN 0 (PXE) interface ${pxe_interface} is added to PXE bridge ${pxe_bridge} exists${reset}"
-  if ! brctl show ${pxe_bridge} | grep ${pxe_interface}; then
+  if ! brctl show ${pxe_bridge} 2>&1 | grep ${pxe_interface}; then
     echo "${blue}Adding VLAN 0 (PXE) interface ${pxe_interface} to PXE bridge ${pxe_bridge}${reset}"
     brctl addif ${pxe_bridge} ${pxe_interface}
-    if ! brctl show ${pxe_bridge} | grep ${pxe_interface}; then
+    if ! brctl show ${pxe_bridge} 2>&1 | grep ${pxe_interface}; then
       echo "${red}Could not add VLAN 0 (PXE) interface ${pxe_interface} to PXE bridge ${pxe_bridge}${reset}"
       exit 1
     fi
@@ -151,6 +149,9 @@ setup_pxe_bridge() {
     echo "${green}OK!${reset}"
   fi
 
+  #Check whether PXE bridge is UP
+  check_interface ${pxe_bridge}
+
   #Add Fuel Gateway IP Address to PXE bridge
   echo "${blue}Checking whether Fuel Gateway IP Address ${fuel_gw_ip} is assigned to PXE bridge ${pxe_bridge}${reset}"
   if ! ip addr show ${pxe_bridge} | grep ${fuel_gw_ip}; then