Opera adapter fix 89/31189/1
authorHarry Huang <huangxiangyu5@huawei.com>
Tue, 21 Mar 2017 03:31:56 +0000 (11:31 +0800)
committerJustin chi <chigang@huawei.com>
Tue, 21 Mar 2017 12:10:14 +0000 (12:10 +0000)
* CI return 0 when opera_adapter fails which cover the error.
* opera_adapter runs with no sudo will fail when generate ssh
key.
* opera_adapter.py use simple ip replacement for openrc file
will lead to error when openrc file changed in compass.

1. add judgement to tell if opera_adapter fails
2. add sudo when run opera_adapter
3. pass data in openrc files to opera openrc instead of ip
rewriting

Change-Id: I681717947746b768791529975a5b0d2a23c6069a
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
(cherry picked from commit b21d57081d4b705689cb6d7372e254818b84a760)

deploy/launch.sh
deploy/opera_adapter.py

index aa47678..5f1ee1c 100755 (executable)
@@ -142,5 +142,8 @@ echo "NOTE: openrc file is in the controller nodes"
 echo ""
 
 if [[ ${DHA##*/} =~ "openo" ]]; then
-    python ${COMPASS_DIR}/deploy/opera_adapter.py $DHA $NETWORK
+    sudo python ${COMPASS_DIR}/deploy/opera_adapter.py $DHA $NETWORK
+    if [[ $? -ne 0 ]]; then
+        exit 1
+    fi
 fi
index 09702fc..71f1995 100644 (file)
@@ -47,11 +47,24 @@ def sync_openo_config(openo_config, dha, network):
 
 
 def sync_admin_openrc(network, admin_openrc_file):
-    ip = re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")
-    with open(admin_openrc_file, 'r+') as fd:
-        data = fd.read()
-        fd.seek(0)
-        fd.write(re.sub(ip, network['public_vip']['ip'], data))
+    ssh_opts = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
+    vip = network['public_vip']['ip']
+    cmd = 'sshpass -p"root" ssh %s root@%s "cat /opt/admin-openrc.sh"' \
+          % (ssh_opts, vip)
+    ssh = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+    if ssh.stdout is None:
+        print("fetch openrc fail")
+        sys.exit(1)
+
+    rcdata = ssh.stdout.readlines()
+    with open(admin_openrc_file, 'w') as fd:
+        ip = re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")
+        for i in rcdata:
+            if 'OS_AUTH_URL' in i:
+                i = re.sub(ip, vip, i)
+            fd.write(i)
+
+        fd.write('export OS_REGION_NAME=RegionOne')
 
 
 if __name__ == "__main__":