Fix bug for Dynamic Recovery 91/50891/1
authorBin Sun <bins@vmware.com>
Thu, 7 Jun 2018 03:03:25 +0000 (11:03 +0800)
committerBin Sun <bins@vmware.com>
Thu, 7 Jun 2018 03:05:05 +0000 (11:05 +0800)
Change-Id: Ic16d530d20de98b99e77c7d1ddf27afb3a951530
Issue-ID: VFC-791
Signed-off-by: Bin Sun <bins@vmware.com>
docker/instance_config.sh
lcm/ns/vnfs/heal_vnfs.py
lcm/pub/config/config.py

index 3f56645..3a9f3a0 100755 (executable)
@@ -3,6 +3,9 @@
 MSB_IP=`echo $MSB_ADDR | cut -d: -f 1`
 MSB_PORT=`echo $MSB_ADDR | cut -d: -f 2`
 
+MR_IP=`echo $MR_ADDR | cut -d: -f 1`
+MR_PORT=`echo $MR_ADDR | cut -d: -f 2`
+
 if [ $MSB_IP ]; then
     sed -i "s|MSB_SERVICE_IP.*|MSB_SERVICE_IP = '$MSB_IP'|" vfc/nfvo/lcm/lcm/pub/config/config.py
 fi
@@ -11,6 +14,14 @@ if [ $MSB_PORT ]; then
     sed -i "s|MSB_SERVICE_PORT.*|MSB_SERVICE_PORT = '$MSB_PORT'|" vfc/nfvo/lcm/lcm/pub/config/config.py
 fi
 
+if [ $MR_IP ]; then
+    sed -i "s|MR_IP.*|MR_IP = '$MR_IP'|" vfc/nfvo/lcm/lcm/pub/config/config.py
+fi
+
+if [ $MR_PORT ]; then
+    sed -i "s|MR_PORT.*|MR_PORT = '$MR_PORT'|" vfc/nfvo/lcm/lcm/pub/config/config.py
+fi
+
 if [ $SERVICE_IP ]; then
     sed -i "s|\"ip\": \".*\"|\"ip\": \"$SERVICE_IP\"|" vfc/nfvo/lcm/lcm/pub/config/config.py
 fi
index 5117d59..b9520ad 100644 (file)
@@ -24,6 +24,9 @@ from lcm.pub.exceptions import NSLCMException
 from lcm.pub.msapi.vnfmdriver import send_nf_heal_request
 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
 from lcm.pub.utils.values import ignore_case_get
+from lcm.pub.config.config import MR_IP
+from lcm.pub.config.config import MR_PORT
+from lcm.pub.utils import restcall
 
 JOB_ERROR = 255
 
@@ -75,25 +78,33 @@ class NFHealService(threading.Thread):
             logger.error('additionalParams parameter does not exist or value incorrect')
             raise NSLCMException('additionalParams parameter does not exist or value incorrect')
 
-        action = ignore_case_get(self.nf_additional_params, 'action')
-        if action == "restartvm":
-            action = "vmReset"
-            # action = "vmStart"
-
         actionvminfo = ignore_case_get(self.nf_additional_params, 'actionvminfo')
         vmid = ignore_case_get(actionvminfo, 'vmid')
-        vmname = ignore_case_get(actionvminfo, 'vmname')
-
-        vduid = self.get_vudId(vmid)
-
-        self.nf_heal_params = {
-            "action": action,
-            "affectedvm": {
-                "vmid": vmid,
-                "vduid": vduid,
-                "vmname": vmname,
-            }
-        }
+        retry_count = 10
+        while (retry_count > 0):
+            resp = restcall.call_req('http://%s:%s/events' % (MR_IP, MR_PORT),
+                                     '',
+                                     '',
+                                     restcall.rest_no_auth,
+                                     '/test/bins/1?timeout=15000',
+                                     'GET')
+            if resp[2] == '200' and resp[1] != '[]':
+                for message in eval(resp[1]):
+                    if 'powering-off' in message:
+                        action = "vmReset"
+                        vm_info = json.loads(message)
+                        if vmid == vm_info['instance_id']:
+                            vduid = self.get_vudId(vm_info['instance_id'])
+                            self.nf_heal_params = {
+                                "action": action,
+                                "affectedvm": {
+                                    "vmid": vm_info['instance_id'],
+                                    "vduid": vduid,
+                                    "vmname": vm_info['display_name']
+                                }
+                            }
+                            retry_count = -1
+            retry_count = retry_count - 1
 
     def send_nf_healing_request(self):
         req_param = json.JSONEncoder().encode(self.nf_heal_params)
index 3dbe7e5..131ccdb 100644 (file)
@@ -72,6 +72,10 @@ SDC_BASE_URL = "http://10.0.14.1:80/api"
 SDC_USER = "SDC"
 SDC_PASSWD = "SDC"
 
+# [DMaaP]
+MR_IP = '127.0.0.1'
+MR_PORT = '3904'
+
 # [workflow]
 DEPLOY_WORKFLOW_WHEN_START = False
 # Support option: activiti/wso2/buildin