From 9df406d7ddbc2eccea94c19967f054ff7c3d9d55 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Fri, 15 Mar 2019 17:12:44 +0800 Subject: [PATCH] Move the function is_connection_activate_intime out --- xCAT/postscripts/nicutils.sh | 50 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/xCAT/postscripts/nicutils.sh b/xCAT/postscripts/nicutils.sh index cc68dc3b8..903fea88b 100755 --- a/xCAT/postscripts/nicutils.sh +++ b/xCAT/postscripts/nicutils.sh @@ -1677,7 +1677,7 @@ function get_first_addr_ipv4 { # # create vlan using nmcli # -# input : ifname= vlanid= +# input : ifname= vlanid= ipaddrs= # return : 0 success # ############################################################################### @@ -1741,18 +1741,9 @@ function create_vlan_interface_nmcli { $cmd log_info "$cmd" nmcli con up $con_name - - i=0 - while [ $i -lt 10 ]; do - con_state=`nmcli con show $con_name | grep -i state| awk '{print $2}'`; - if [ ! -z "$con_state" -a "$con_state" = "activated" ]; then - break - fi - sleep 2 - i=$((i+1)) - done - - if [ $i -ge 10 ]; then + is_connection_activate_intime $con_name + is_active=$? + if [ "$is_active" -eq 0 ]; then log_error "The vlan configuration for $ifname.$vlanid can not be booted up" nmcli con delete $con_name if [ ! -z "$tmp_con_name" ]; then @@ -1765,6 +1756,39 @@ function create_vlan_interface_nmcli { return 0 } +############################################################################### +# +# is_connection_activate_intime +# +# input : connection_name +# time_out (optional, 40 seconds by default) +# return : 1 active +# 0 failed +# +############################################################################### + +function is_connection_activate_intime { + con_name=$1 + time_out=40 + if [ ! -z "$2" ]; then + time_out=$2 + fi + i=0 + while [ $i -lt "$time_out" ]; do + con_state=`nmcli con show $con_name | grep -i state| awk '{print $2}'`; + if [ ! -z "$con_state" -a "$con_state" = "activated" ]; then + break + fi + sleep 1 + i=$((i+1)) + done + if [ $i -ge "$time_out" ]; then + return 0 + else + return 1 + fi +} + ############################################################################### # # create bridge