Bugfix: some errors in env_setup.py. 83/19483/3
authorwu.zhihui <wu.zhihui1@zte.com.cn>
Wed, 24 Aug 2016 13:09:02 +0000 (21:09 +0800)
committerwu.zhihui <wu.zhihui1@zte.com.cn>
Thu, 25 Aug 2016 04:47:52 +0000 (12:47 +0800)
Change-Id: Ia9ab50f8990659d4657e67f38ece72d5eb47f4d9
Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
func/env_setup.py
func/fetch_compute_ips.sh

index 1f86f0e..ea49337 100644 (file)
@@ -124,19 +124,19 @@ class Env_setup:
         LOG.info("Fetch compute ips through installer")
         ips = []
 
-        installer_type = os.environ['INSTALLER_TYPE']
-        installer_ip = os.environ['INSTALLER_IP']
-        if installer_type.down.lower() != "fuel" or "compass":
+        installer_type = str(os.environ['INSTALLER_TYPE'].lower())
+        installer_ip = str(os.environ['INSTALLER_IP'])
+        if installer_type not in ["fuel", "compass"]:
             raise RuntimeError("%s is not supported" % installer_type)
-        if installer_ip:
+        if not installer_ip:
             raise RuntimeError("undefine environment variable INSTALLER_IP")
 
-        cmd = "bash ./fetch_compute_ip.sh -i %s -a %s" % \
+        cmd = "bash ./func/fetch_compute_ips.sh -i %s -a %s" % \
             (installer_type, installer_ip)
+        LOG.info(cmd)
         os.system(cmd)
         home = expanduser("~")
-        os.chdir(home)
-        with open("ips.log", "r") as file:
+        with open(home + "/ips.log", "r") as file:
             data = file.read()
         if data:
             ips.extend(data.rstrip('\n').split('\n'))
index c1cc4c6..ebe817a 100755 (executable)
@@ -41,7 +41,7 @@ verify_connectivity(){
 :${DEPLOY_TYPE:=''}
 
 #Getoptions
-whilegetopts ":d:i:a:h:v" optchar; do
+while getopts ":i:a:h:v" optchar; do
    case "${optchar}" in
        i) installer_type=${OPTARG} ;;
        a) installer_ip=${OPTARG} ;;
@@ -57,7 +57,7 @@ done
 installer_type=${installer_type:-$INSTALLER_TYPE}
 installer_ip=${installer_ip:-$INSTALLER_IP}
 
-if[ -z $installer_type ] || [ -z $installer_ip ]; then
+if [ -z $installer_type ] || [ -z $installer_ip ]; then
    usage
    exit 2
 fi
@@ -65,7 +65,7 @@ fi
 ssh_options="-oUserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
 
 #Start fetching compute ip
-if[ "$installer_type" == "fuel" ]; then
+if [ "$installer_type" == "fuel" ]; then
    verify_connectivity $installer_ip
 
    env=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
@@ -81,11 +81,11 @@ if[ "$installer_type" == "fuel" ]; then
        sed 's/ //g') &> /dev/null
 
 
-elif[ "$installer_type" == "apex" ]; then
+elif [ "$installer_type" == "apex" ]; then
    echo "not implement now"
    exit 1
 
-elif[ "$installer_type" == "compass" ]; then
+elif [ "$installer_type" == "compass" ]; then
    # need test
    verify_connectivity $installer_ip
    IPS=$(sshpass -p'root' ssh 2>/dev/null $ssh_options root@${installer_ip} \
@@ -93,11 +93,11 @@ elif[ "$installer_type" == "compass" ]; then
        | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"host[4-5]\"/) {print $(i+1);}}'  \
        | grep -oP "\d+.\d+.\d+.\d+")
 
-elif[ "$installer_type" == "joid" ]; then
+elif [ "$installer_type" == "joid" ]; then
    echo "not implement now"
    exit 1
 
-elif[ "$installer_type" == "foreman" ]; then
+elif [ "$installer_type" == "foreman" ]; then
    echo "not implement now"
    exit 1
 
@@ -105,7 +105,7 @@ else
    error "Installer $installer is not supported by this script"
 fi
 
-if[ -z $IPS ]; then
+if [ -z "$IPS" ]; then
    error "The compute node $IPS are not up. Please check that the POD is correctly deployed."
 else
    echo "-------- all compute node ips: --------"
@@ -114,4 +114,4 @@ else
    echo $IPS
 fi
 
-exit0
+exit 0