fix 1190 parse RO returned error 70/9570/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 11 Aug 2020 11:20:13 +0000 (11:20 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 11 Aug 2020 11:27:06 +0000 (11:27 +0000)
If error is a json/yaml, get description only
Remove Double "Stage Stage" at reported ns details

Change-Id: I6b5cda154b8851101d231db68e1b6c8a76b65ae3
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_lcm/ROclient.py
osm_lcm/ns.py

index 0ca00a5..db2be1c 100644 (file)
@@ -164,7 +164,8 @@ class ROClient:
         self.tenant = None      # force to reload tenant with different credentials
         self.datacenter = None  # force to reload datacenter with different credentials
 
-    def _parse(self, descriptor, descriptor_format, response=False):
+    @staticmethod
+    def _parse(descriptor, descriptor_format, response=False):
         if descriptor_format and descriptor_format != "json" and descriptor_format != "yaml":
             raise ROClientException("'descriptor_format' must be a 'json' or 'yaml' text")
         if descriptor_format != "json":
@@ -186,8 +187,18 @@ class ROClient:
         if response:
             raise ROClientException(error_text)
         raise ROClientException(error_text)
-    
-    def _parse_yaml(self, descriptor, response=False):
+
+    @staticmethod
+    def _parse_error_yaml(descriptor):
+        json_error = None
+        try:
+            json_error = yaml.load(descriptor, Loader=yaml.Loader)
+            return json_error["error"]["description"]
+        except Exception:
+            return str(json_error or descriptor)
+
+    @staticmethod
+    def _parse_yaml(descriptor, response=False):
         try:
             return yaml.load(descriptor, Loader=yaml.Loader)
         except yaml.YAMLError as exc:
@@ -311,15 +322,15 @@ class ROClient:
             total["networks"] = len(ns_descriptor["nets"])
             for net in ns_descriptor["nets"]:
                 if net["status"] in ("ERROR", "VIM_ERROR"):
-                    error_list.append("VIM network ({}) on error: {}".format(_get_ref(net), net["error_msg"]))
+                    error_list.append("Error at VIM network {}: {}".format(_get_ref(net), net["error_msg"]))
                 elif net["status"] == "ACTIVE":
                     done["networks"] += 1
 
             total["SDN_networks"] = len(ns_descriptor["sdn_nets"])
             for sdn_net in ns_descriptor["sdn_nets"]:
                 if sdn_net["status"] in ("ERROR", "VIM_ERROR", "WIM_ERROR"):
-                    error_list.append("SDN network ({}) on error: {}".format(_get_sdn_ref(sdn_net.get("sce_net_id")),
-                                                                             sdn_net["error_msg"]))
+                    error_list.append("Error at SDN network {}: {}".format(_get_sdn_ref(sdn_net.get("sce_net_id")),
+                                                                           sdn_net["error_msg"]))
                 elif sdn_net["status"] == "ACTIVE":
                     done["SDN_networks"] += 1
 
@@ -327,11 +338,12 @@ class ROClient:
                 for vm in vnf["vms"]:
                     total["VMs"] += 1
                     if vm["status"] in ("ERROR", "VIM_ERROR"):
-                        error_list.append("VIM VM ({}) on error: {}".format(_get_ref(vm), vm["error_msg"]))
+                        error_list.append("Error at VIM VM {}: {}".format(_get_ref(vm), vm["error_msg"]))
                     elif vm["status"] == "ACTIVE":
                         done["VMs"] += 1
             if error_list:
-                return "ERROR", "; ".join(error_list)
+                # skip errors caused because other dependendent task is on error
+                return "ERROR", "; ".join([el for el in error_list if "because depends on failed  ACTION" not in el])
             if all(total[x] == done[x] for x in total):  # DONE == TOTAL for all items
                 return "ACTIVE", str({x: total[x] for x in total if total[x]})  # print only those which value is not 0
             else:
@@ -449,7 +461,7 @@ class ROClient:
                 raise ROClientException("No {} found with id '{}'".format(item[:-1], item_id_name),
                                         http_code=404)
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
         content = self._parse_yaml(response_text, response=True)
 
         if item_id:
@@ -496,7 +508,7 @@ class ROClient:
             response_text = await response.read()
             self.logger.debug("GET {} [{}] {}".format(url, response.status, response_text[:100]))
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
         return self._parse_yaml(response_text, response=True)
 
@@ -555,7 +567,7 @@ class ROClient:
             response_text = await response.read()
             self.logger.debug("POST {} [{}] {}".format(url, response.status, response_text[:100]))
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
         return self._parse_yaml(response_text, response=True)
 
@@ -584,7 +596,7 @@ class ROClient:
             response_text = await response.read()
             self.logger.debug("DELETE {} [{}] {}".format(url, response.status, response_text[:100]))
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
         return self._parse_yaml(response_text, response=True)
 
@@ -610,7 +622,7 @@ class ROClient:
             response_text = await response.read()
             self.logger.debug("GET {} [{}] {}".format(url, response.status, response_text[:100]))
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
         return self._parse_yaml(response_text, response=True)
 
@@ -634,7 +646,7 @@ class ROClient:
             response_text = await response.read()
             self.logger.debug("PUT {} [{}] {}".format(url, response.status, response_text[:100]))
             if response.status >= 300:
-                raise ROClientException(response_text, http_code=response.status)
+                raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
         return self._parse_yaml(response_text, response=True)
 
@@ -653,7 +665,7 @@ class ROClient:
                     response_text = await response.read()
                     self.logger.debug("GET {} [{}] {}".format(url, response.status, response_text[:100]))
                     if response.status >= 300:
-                        raise ROClientException(response_text, http_code=response.status)
+                        raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
                 for word in str(response_text).split(" "):
                     if "." in word:
@@ -951,7 +963,7 @@ class ROClient:
                     response_text = await response.read()
                     self.logger.debug("POST {} [{}] {}".format(url, response.status, response_text[:100]))
                     if response.status >= 300:
-                        raise ROClientException(response_text, http_code=response.status)
+                        raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
 
                 response_desc = self._parse_yaml(response_text, response=True)
                 desc = remove_envelop(item, response_desc)
@@ -978,7 +990,7 @@ class ROClient:
                     response_text = await response.read()
                     self.logger.debug("DELETE {} [{}] {}".format(url, response.status, response_text[:100]))
                     if response.status >= 300:
-                        raise ROClientException(response_text, http_code=response.status)
+                        raise ROClientException(self._parse_error_yaml(response_text), http_code=response.status)
  
                 response_desc = self._parse_yaml(response_text, response=True)
                 desc = remove_envelop(item, response_desc)
index 4bed2c6..fbefc4d 100644 (file)
@@ -1850,11 +1850,11 @@ class NsLcm(LcmBase):
             # wait for any previous tasks in process
             await self.lcm_tasks.waitfor_related_HA('ns', 'nslcmops', nslcmop_id)
 
-            stage[1] = "Sync filesystem from database"
+            stage[1] = "Sync filesystem from database."
             self.fs.sync()  # TODO, make use of partial sync, only for the needed packages
 
             # STEP 0: Reading database (nslcmops, nsrs, nsds, vnfrs, vnfds)
-            stage[1] = "Reading from database"
+            stage[1] = "Reading from database."
             # nsState="BUILDING", currentOperation="INSTANTIATING", currentOperationID=nslcmop_id
             db_nsr_update["detailed-status"] = "creating"
             db_nsr_update["operational-status"] = "init"
@@ -1872,7 +1872,7 @@ class NsLcm(LcmBase):
             )
 
             # read from db: operation
-            stage[1] = "Getting nslcmop={} from db".format(nslcmop_id)
+            stage[1] = "Getting nslcmop={} from db.".format(nslcmop_id)
             db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
             ns_params = db_nslcmop.get("operationParams")
             if ns_params and ns_params.get("timeout_ns_deploy"):
@@ -1881,15 +1881,15 @@ class NsLcm(LcmBase):
                 timeout_ns_deploy = self.timeout.get("ns_deploy", self.timeout_ns_deploy)
 
             # read from db: ns
-            stage[1] = "Getting nsr={} from db".format(nsr_id)
+            stage[1] = "Getting nsr={} from db.".format(nsr_id)
             db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
-            stage[1] = "Getting nsd={} from db".format(db_nsr["nsd-id"])
+            stage[1] = "Getting nsd={} from db.".format(db_nsr["nsd-id"])
             nsd = self.db.get_one("nsds", {"_id": db_nsr["nsd-id"]})
             db_nsr["nsd"] = nsd
             # nsr_name = db_nsr["name"]   # TODO short-name??
 
             # read from db: vnf's of this ns
-            stage[1] = "Getting vnfrs from db"
+            stage[1] = "Getting vnfrs from db."
             self.logger.debug(logging_text + stage[1])
             db_vnfrs_list = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
 
@@ -1907,7 +1907,7 @@ class NsLcm(LcmBase):
                 # if we haven't this vnfd, read it from db
                 if vnfd_id not in db_vnfds:
                     # read from db
-                    stage[1] = "Getting vnfd={} id='{}' from db".format(vnfd_id, vnfd_ref)
+                    stage[1] = "Getting vnfd={} id='{}' from db.".format(vnfd_id, vnfd_ref)
                     self.logger.debug(logging_text + stage[1])
                     vnfd = self.db.get_one("vnfds", {"_id": vnfd_id})
 
@@ -1949,7 +1949,7 @@ class NsLcm(LcmBase):
                 stage=stage
             )
 
-            stage[1] = "Deploying KDUs,"
+            stage[1] = "Deploying KDUs."
             # self.logger.debug(logging_text + "Before deploy_kdus")
             # Call to deploy_kdus in case exists the "vdu:kdu" param
             await self.deploy_kdus(
@@ -2190,8 +2190,8 @@ class NsLcm(LcmBase):
             if error_list:
                 error_detail = ". ".join(error_list)
                 self.logger.error(logging_text + error_detail)
-                error_description_nslcmop = 'Stage: {}. Detail: {}'.format(stage[0], error_detail)
-                error_description_nsr = 'Operation: INSTANTIATING.{}, Stage {}'.format(nslcmop_id, stage[0])
+                error_description_nslcmop = '{} Detail: {}'.format(stage[0], error_detail)
+                error_description_nsr = 'Operation: INSTANTIATING.{}, {}'.format(nslcmop_id, stage[0])
 
                 db_nsr_update["detailed-status"] = error_description_nsr + " Detail: " + error_detail
                 db_nslcmop_update["detailed-status"] = error_detail
@@ -3314,8 +3314,8 @@ class NsLcm(LcmBase):
             if error_list:
                 error_detail = "; ".join(error_list)
                 # self.logger.error(logging_text + error_detail)
-                error_description_nslcmop = 'Stage: {}. Detail: {}'.format(stage[0], error_detail)
-                error_description_nsr = 'Operation: TERMINATING.{}, Stage {}.'.format(nslcmop_id, stage[0])
+                error_description_nslcmop = '{} Detail: {}'.format(stage[0], error_detail)
+                error_description_nsr = 'Operation: TERMINATING.{}, {}.'.format(nslcmop_id, stage[0])
 
                 db_nsr_update["operational-status"] = "failed"
                 db_nsr_update["detailed-status"] = error_description_nsr + " Detail: " + error_detail