From d5d53032ed849855ecf7647589ee8596da9f9627 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 19 Apr 2016 12:18:20 +0300 Subject: [PATCH] [Admin-Util]: Add error handling to nsxv update_dhcp_edge_binding 'nsxadmin -r dhcp-binding -o nsx-update' can fail if given the wrong edge-id Now we expect this error and log a proper message. Output example: NSX Plugin in use: nsxv ==== [NSX] Update Dhcp Edge Binding ==== Updating NSXv Edge: edge-4 Edge edge-4 not found Change-Id: I4840d55333fc84fbe0494873799283cea000914f --- .../admin/plugins/nsxv/resources/dhcp_binding.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py index 8cc086ba98..9c2963e399 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py @@ -27,6 +27,7 @@ from neutron.db import db_base_plugin_v2 from vmware_nsx._i18n import _LE, _LI from vmware_nsx.db import nsxv_db +from vmware_nsx.plugins.nsx_v.vshield.common import exceptions from vmware_nsx.plugins.nsx_v.vshield import edge_utils from vmware_nsx.plugins.nsx_v.vshield import vcns_driver @@ -100,15 +101,19 @@ def nsx_update_dhcp_edge_binding(resource, event, trigger, **kwargs): return else: properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) - LOG.info(_LI("Updating NSXv Edge: %s"), properties.get('edge-id')) + edge_id = properties.get('edge-id') + LOG.info(_LI("Updating NSXv Edge: %s"), edge_id) # Need to create a NeutronDbPlugin object; so that we are able to # do neutron list-ports. plugin = db_base_plugin_v2.NeutronDbPluginV2() nsxv_manager = vcns_driver.VcnsDriver( edge_utils.NsxVCallbacks(plugin)) edge_manager = edge_utils.EdgeManager(nsxv_manager, plugin) - edge_manager.update_dhcp_service_config( - neutron_db.context, properties.get('edge-id')) + try: + edge_manager.update_dhcp_service_config( + neutron_db.context, edge_id) + except exceptions.ResourceNotFound: + LOG.error(_LE("Edge %s not found"), edge_id) registry.subscribe(list_missing_dhcp_bindings,