From 511295b8c653c4cb0de4365dec06797591f77a68 Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Tue, 29 Dec 2015 21:50:37 -0800 Subject: [PATCH] [NSX-v]: Update existing vague exceptions Use NsxResourceNotFound exception to detail the resource name and resource ID not found on backend. Change-Id: Ib7749380672e54f452b5721da2dd2d92feceb618 Depends-On: Ibba7b4997b89ecabfe5fba162f7b60c3c9a889c8 --- vmware_nsx/common/exceptions.py | 2 +- vmware_nsx/plugins/nsx_v/plugin.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/vmware_nsx/common/exceptions.py b/vmware_nsx/common/exceptions.py index 7dc5a5fcd5..b3d5ddee4f 100644 --- a/vmware_nsx/common/exceptions.py +++ b/vmware_nsx/common/exceptions.py @@ -169,4 +169,4 @@ class SecurityGroupMaximumCapacityReached(NsxPluginException): class NsxResourceNotFound(n_exc.NotFound): - message = _("%(res_name)s %(res_id)s not found on the backend") + message = _("%(res_name)s %(res_id)s not found on the backend.") diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 5cd9c68d21..f8e5bc388c 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -2154,28 +2154,33 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, def _validate_config(self): if (cfg.CONF.nsxv.dvs_id and not self.nsx_v.vcns.validate_dvs(cfg.CONF.nsxv.dvs_id)): - error = _("Configured dvs_id not found") - raise nsx_exc.NsxPluginException(err_msg=error) + raise nsx_exc.NsxResourceNotFound( + res_name='dvs_id', + res_id=cfg.CONF.nsxv.dvs_id) if not self.nsx_v.vcns.validate_datacenter_moid( cfg.CONF.nsxv.datacenter_moid): - error = _("Configured datacenter_moid not found") - raise nsx_exc.NsxPluginException(err_msg=error) + raise nsx_exc.NsxResourceNotFound( + res_name='datacenter_moid', + res_id=cfg.CONF.nsxv.datacenter_moid) if not self.nsx_v.vcns.validate_network( cfg.CONF.nsxv.external_network): - error = _("Configured external_network not found") - raise nsx_exc.NsxPluginException(err_msg=error) + raise nsx_exc.NsxResourceNotFound( + res_name='external_network', + res_id=cfg.CONF.nsxv.external_network) if not self.nsx_v.vcns.validate_vdn_scope(cfg.CONF.nsxv.vdn_scope_id): - error = _("Configured vdn_scope_id not found") - raise nsx_exc.NsxPluginException(err_msg=error) + raise nsx_exc.NsxResourceNotFound( + res_name='vdn_scope_id', + res_id=cfg.CONF.nsxv.vdn_scope_id) if (cfg.CONF.nsxv.mgt_net_moid and not self.nsx_v.vcns.validate_network( cfg.CONF.nsxv.mgt_net_moid)): - error = _("Configured mgt_net_moid not found") - raise nsx_exc.NsxPluginException(err_msg=error) + raise nsx_exc.NsxResourceNotFound( + res_name='mgt_net_moid', + res_id=cfg.CONF.nsxv.mgt_net_moid) ver = self.nsx_v.vcns.get_version() if version.LooseVersion(ver) < version.LooseVersion('6.2.0'):