From 47da978a3ddf42591339fe5f2250b119459796e1 Mon Sep 17 00:00:00 2001 From: Sumit Naiksatam Date: Fri, 19 Aug 2011 10:55:46 -0700 Subject: [PATCH] Raising exceptions in extension resources handling (where missing). --- quantum/plugins/cisco/l2network_plugin.py | 56 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/quantum/plugins/cisco/l2network_plugin.py b/quantum/plugins/cisco/l2network_plugin.py index 29fc35424..21fd16fd0 100644 --- a/quantum/plugins/cisco/l2network_plugin.py +++ b/quantum/plugins/cisco/l2network_plugin.py @@ -275,7 +275,12 @@ class L2Network(QuantumPluginBase): def get_portprofile_details(self, tenant_id, profile_id): """Get port profile details""" LOG.debug("get_portprofile_details() called\n") - portprofile = cdb.get_portprofile(tenant_id, profile_id) + try: + portprofile = cdb.get_portprofile(tenant_id, profile_id) + except Exception, excp: + raise cexc.PortProfileNotFound(tenant_id=tenant_id, + portprofile_id=profile_id) + new_pp = self._make_portprofile_dict(tenant_id, portprofile[const.UUID], portprofile[const.PPNAME], @@ -291,7 +296,6 @@ class L2Network(QuantumPluginBase): portprofile[const.UUID], portprofile[const.PPNAME], portprofile[const.PPQOS]) - print("***Sumit: %s\n", new_pp) return new_pp def delete_portprofile(self, tenant_id, profile_id): @@ -299,7 +303,7 @@ class L2Network(QuantumPluginBase): LOG.debug("delete_portprofile() called\n") try: portprofile = cdb.get_portprofile(tenant_id, profile_id) - except Exception, exc: + except Exception, excp: raise cexc.PortProfileNotFound(tenant_id=tenant_id, portprofile_id=profile_id) @@ -315,7 +319,7 @@ class L2Network(QuantumPluginBase): LOG.debug("rename_portprofile() called\n") try: portprofile = cdb.get_portprofile(tenant_id, profile_id) - except Exception, exc: + except Exception, excp: raise cexc.PortProfileNotFound(tenant_id=tenant_id, portprofile_id=profile_id) portprofile = cdb.update_portprofile(tenant_id, profile_id, new_name) @@ -331,7 +335,7 @@ class L2Network(QuantumPluginBase): LOG.debug("associate_portprofile() called\n") try: portprofile = cdb.get_portprofile(tenant_id, portprofile_id) - except Exception, exc: + except Exception, excp: raise cexc.PortProfileNotFound(tenant_id=tenant_id, portprofile_id=portprofile_id) @@ -343,7 +347,7 @@ class L2Network(QuantumPluginBase): LOG.debug("disassociate_portprofile() called\n") try: portprofile = cdb.get_portprofile(tenant_id, portprofile_id) - except Exception, exc: + except Exception, excp: raise cexc.PortProfileNotFound(tenant_id=tenant_id, portprofile_id=portprofile_id) @@ -372,7 +376,12 @@ class L2Network(QuantumPluginBase): def get_qos_details(self, tenant_id, qos_id): """Get QoS Details""" LOG.debug("get_qos_details() called\n") - return self._get_qos_level(tenant_id, qos_id) + try: + qos_level = self._get_qos_level(tenant_id, qos_id) + except Exception, excp: + raise cexc.QoSLevelNotFound(tenant_id=tenant_id, + qos_id=qos_id) + return qos_level def create_qos(self, tenant_id, qos_name, qos_desc): """Create a QoS level""" @@ -388,7 +397,11 @@ class L2Network(QuantumPluginBase): def delete_qos(self, tenant_id, qos_id): """Delete a QoS level""" LOG.debug("delete_qos() called\n") - qos_level = self._get_qos_level(tenant_id, qos_id) + try: + qos_level = self._get_qos_level(tenant_id, qos_id) + except Exception, excp: + raise cexc.QoSLevelNotFound(tenant_id=tenant_id, + qos_id=qos_id) associations = qos_level[const.QOS_LEVEL_ASSOCIATIONS] if len(associations) > 0: raise cexc.QoSLevelInvalidDelete(tenant_id=tenant_id, @@ -400,6 +413,11 @@ class L2Network(QuantumPluginBase): """Rename QoS level""" LOG.debug("rename_qos() called\n") qos_level = self._get_qos_level(tenant_id, qos_id) + try: + qos_level = self._get_qos_level(tenant_id, qos_id) + except Exception, excp: + raise cexc.QoSLevelNotFound(tenant_id=tenant_id, + qos_id=qos_id) qos_level[const.QOS_LEVEL_NAME] = new_name return qos_level @@ -411,7 +429,12 @@ class L2Network(QuantumPluginBase): def get_credential_details(self, tenant_id, credential_id): """Get a particular credential""" LOG.debug("get_credential_details() called\n") - return self._get_credential(tenant_id, credential_id) + try: + credential = self._get_credential(tenant_id, credential_id) + except Exception, excp: + raise cexc.CredentialNotFound(tenant_id=tenant_id, + credential_id=credential_id) + return credential def create_credential(self, tenant_id, credential_name, user_name, password): @@ -430,14 +453,25 @@ class L2Network(QuantumPluginBase): def delete_credential(self, tenant_id, credential_id): """Delete a credential""" LOG.debug("delete_credential() called\n") - credential = self._get_credential(tenant_id, credential_id) + try: + credential = self._get_credential(tenant_id, credential_id) + except Exception, excp: + raise cexc.CredentialNotFound(tenant_id=tenant_id, + credential_id=credential_id) self._credentials.pop(credential_id) cred.Store.deleteCredential(credential_id) def rename_credential(self, tenant_id, credential_id, new_name): """Do nothing for this resource""" LOG.debug("rename_credential() called\n") - pass + try: + credential = self._get_credential(tenant_id, credential_id) + except Exception, excp: + raise cexc.CredentialNotFound(tenant_id=tenant_id, + credential_id=credential_id) + + credential[const.CREDENTIAL_NAME] = new_name + return credential def get_host(self, tenant_id, instance_id, instance_desc): """Provides the hostname on which a dynamic vnic is reserved""" -- 2.45.2