Add exception protection in vfc-nfvo-lcm 11/18711/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Fri, 13 Oct 2017 06:25:35 +0000 (14:25 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Fri, 13 Oct 2017 06:25:35 +0000 (14:25 +0800)
Change-Id: I65b9886981487d1204def9fe5bad3e5e082bbadb
Issue-ID: VFC-525
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/vls/create_vls.py
lcm/ns/vls/delete_vls.py

index dc72101..f17027e 100644 (file)
@@ -196,37 +196,42 @@ class CreateVls(object):
 
     def create_network_and_subnet_in_aai(self):
         logger.debug("CreateVls::create_network_in_aai::report network[%s] to aai." % self.vl_inst_id)
-        data = {
-            "network-id": self.vl_inst_id,
-            "network-name": self.vl_inst_name,
-            "is-bound-to-vpn": False,
-            "is-provider-network": True,
-            "is-shared-network": True,
-            "is-external-network": True,
-            "subnets": {
-                "subnet": [
-                    {
-                        "subnet-id": self.related_subnetwork_id,
-                        "dhcp-enabled": False
-                    }
-                ]
-            },
-            "relationship-list": {
-                "relationship": [
-                    {
-                        "related-to": "generic-vnf",
-                        "relationship-data": [
-                            {
-                                "relationship-key": "generic-vnf.vnf-id",
-                                "relationship-value": self.owner_id
-                            }
-                        ]
-                    }
-                ]
+        try:
+            data = {
+                "network-id": self.vl_inst_id,
+                "network-name": self.vl_inst_name,
+                "is-bound-to-vpn": False,
+                "is-provider-network": True,
+                "is-shared-network": True,
+                "is-external-network": True,
+                "subnets": {
+                    "subnet": [
+                        {
+                            "subnet-id": self.related_subnetwork_id,
+                            "dhcp-enabled": False
+                        }
+                    ]
+                },
+                "relationship-list": {
+                    "relationship": [
+                        {
+                            "related-to": "generic-vnf",
+                            "relationship-data": [
+                                {
+                                    "relationship-key": "generic-vnf.vnf-id",
+                                    "relationship-value": self.owner_id
+                                }
+                            ]
+                        }
+                    ]
+                }
             }
-        }
-        resp_data, resp_status = create_network_aai(self.vl_inst_id, data)
-        if resp_data:
-            logger.debug("Fail to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
-        else:
-            logger.debug("Success to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
+            resp_data, resp_status = create_network_aai(self.vl_inst_id, data)
+            if resp_data:
+                logger.debug("Fail to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
+            else:
+                logger.debug("Success to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
+        except NSLCMException as e:
+            logger.debug("Fail to create network[%s] to aai, detail message: %s" % (self.vl_inst_id, e.message))
+        except:
+            logger.error(traceback.format_exc())
index 8c089b1..3402016 100644 (file)
@@ -85,17 +85,23 @@ class DeleteVls(object):
 
     def delete_network_and_subnet_in_aai(self):
         logger.debug("DeleteVls::delete_network_in_aai::delete network[%s] in aai." % self.vl_inst_id)
+        try:
+            # query network in aai, get resource_version
+            customer_info = query_network_aai(self.vl_inst_id)
+            resource_version = customer_info["resource-version"]
 
-        # query network in aai, get resource_version
-        customer_info = query_network_aai(self.vl_inst_id)
-        resource_version = customer_info["resource-version"]
-
-        # delete network from aai
-        resp_data, resp_status = delete_network_aai(self.vl_inst_id, resource_version)
-        if resp_data:
-            logger.debug("Fail to delete network[%s] from aai, resp_status: [%s]." % (self.vl_inst_id, resp_status))
-        else:
-            logger.debug("Success to delete network[%s] from aai, resp_status: [%s]." % (self.vl_inst_id, resp_status))
+            # delete network from aai
+            resp_data, resp_status = delete_network_aai(self.vl_inst_id, resource_version)
+            if resp_data:
+                logger.debug("Fail to delete network[%s] from aai, resp_status: [%s]."
+                             % (self.vl_inst_id, resp_status))
+            else:
+                logger.debug("Success to delete network[%s] from aai, resp_status: [%s]."
+                             % (self.vl_inst_id, resp_status))
+        except NSLCMException as e:
+            logger.debug("Fail to delete network[%s] to aai, detail message: %s" % (self.vl_inst_id, e.message))
+        except:
+            logger.error(traceback.format_exc())
 
     def delete_vl_from_db(self, vl_inst_info):
         # do_biz_with_share_lock("delete-vllist-in-vnffg-%s" % self.ns_inst_id, self.delete_vl_inst_id_in_vnffg)