From 46261c24e607e6b1fbb17049f2706706853345ff Mon Sep 17 00:00:00 2001 From: Bob Melander Date: Mon, 19 Jun 2017 18:52:58 +0200 Subject: [PATCH] Fixes incorrect format strings in log statements One of the erroneous format strings in particular has been causing intermittent failures for some of the ASR1k router type driver unit tests. This patch therefore removes the workaround for those UT failures provided in commit 0ac6a2ec0abe85c94a08a47b242e1374aad74fa6. AKA: DE3463 Partial-Bug: #1676435 Change-Id: Ifa9fa8ae8ca2f88e7339ac6aaf8b6adb56a80268 --- networking_cisco/apps/saf/db/dfa_db_models.py | 2 +- .../cisco/db/l3/l3_router_appliance_db.py | 14 ++++++----- .../n1kv_ml2_trunking_driver.py | 2 +- .../plugins/cisco/extensions/ha.py | 2 +- .../drivers/asr1k/asr1k_routertype_driver.py | 16 +++++++++---- .../drivers/cisco/nexus/mech_cisco_nexus.py | 2 +- .../device_manager/plugging_test_driver.py | 2 +- .../cisco/l3/test_asr1k_routertype_driver.py | 24 ++++--------------- 8 files changed, 30 insertions(+), 34 deletions(-) diff --git a/networking_cisco/apps/saf/db/dfa_db_models.py b/networking_cisco/apps/saf/db/dfa_db_models.py index 914872d..575c94d 100644 --- a/networking_cisco/apps/saf/db/dfa_db_models.py +++ b/networking_cisco/apps/saf/db/dfa_db_models.py @@ -223,7 +223,7 @@ class DfaSegmentTypeDriver(object): alloc = self._allocate_specified_segment(session, seg_id, source) if not alloc: LOG.error(_LE("ERROR: Segmentation_id %(seg)s is in use. for " - "net %(net)s source %(src)"), + "net %(net)s source %(src)s"), {'seg': seg_id, 'net': net_id, 'src': source}) return diff --git a/networking_cisco/plugins/cisco/db/l3/l3_router_appliance_db.py b/networking_cisco/plugins/cisco/db/l3/l3_router_appliance_db.py index a0077ad..0b5cb10 100644 --- a/networking_cisco/plugins/cisco/db/l3/l3_router_appliance_db.py +++ b/networking_cisco/plugins/cisco/db/l3/l3_router_appliance_db.py @@ -343,7 +343,7 @@ class L3RouterApplianceDBMixin(extraroute_db.ExtraRoute_dbonly_mixin): self._validate_caller(context, router_id) except RouterBindingInfoError: LOG.debug('Router %s to be deleted has no binding information ' - 'so assuming it is a regular router') + 'so assuming it is a regular router', router_id) try: router_db = self._ensure_router_not_in_use(context, router_id) except sa_exc.InvalidRequestError: @@ -1241,7 +1241,8 @@ class L3RouterApplianceDBMixin(extraroute_db.ExtraRoute_dbonly_mixin): raise RouterCreateInternalError() return self._make_routertype_dict(router_type_db) - def _get_effective_and_normal_routertypes(self, context, hosting_info): + def _get_effective_and_normal_routertypes(self, context, router_id, + hosting_info): if hosting_info: hosting_device = hosting_info.hosting_device normal = self._make_routertype_dict(hosting_info.router_type) @@ -1261,14 +1262,15 @@ class L3RouterApplianceDBMixin(extraroute_db.ExtraRoute_dbonly_mixin): else: # should not happen but just in case... LOG.debug('Could not determine effective router type since ' - 'router db record had no binding information') + 'router db record for router %s had no binding ' + 'information', router_id) normal = None effective = None return effective, normal - def _get_effective_slot_need(self, context, hosting_info): + def _get_effective_slot_need(self, context, router_id, hosting_info): (eff_rt, norm_rt) = self._get_effective_and_normal_routertypes( - context, hosting_info) + context, router_id, hosting_info) return eff_rt['slot_need'] if eff_rt else 0 def _update_routertype(self, context, r, binding_info_db): @@ -1291,7 +1293,7 @@ class L3RouterApplianceDBMixin(extraroute_db.ExtraRoute_dbonly_mixin): def _extend_router_dict_routertype(self, router_res, router_db): adm_context = bc.context.get_admin_context() (eff_rt, norm_rt) = self._get_effective_and_normal_routertypes( - adm_context, router_db.hosting_info) + adm_context, router_db.id, router_db.hosting_info) # Show both current (temporary) and normal types if Neutron router is # relocated to a device of different type if eff_rt and norm_rt: diff --git a/networking_cisco/plugins/cisco/device_manager/plugging_drivers/n1kv_ml2_trunking_driver.py b/networking_cisco/plugins/cisco/device_manager/plugging_drivers/n1kv_ml2_trunking_driver.py index 42bb30a..1d45a19 100644 --- a/networking_cisco/plugins/cisco/device_manager/plugging_drivers/n1kv_ml2_trunking_driver.py +++ b/networking_cisco/plugins/cisco/device_manager/plugging_drivers/n1kv_ml2_trunking_driver.py @@ -274,7 +274,7 @@ class N1kvML2TrunkingPlugDriver(plug.PluginSidePluggingDriver, except exception_type: resource_ids.remove(item_id) except n_exc.NeutronException as e: - LOG.error(_LE('Failed to delete %(resource_name) %(net_id)s ' + LOG.error(_LE('Failed to delete %(resource_name)s %(net_id)s ' 'for service vm due to %(err)s'), {'resource_name': name, 'net_id': item_id, 'err': e}) diff --git a/networking_cisco/plugins/cisco/extensions/ha.py b/networking_cisco/plugins/cisco/extensions/ha.py index 3cae29b..4acd80c 100644 --- a/networking_cisco/plugins/cisco/extensions/ha.py +++ b/networking_cisco/plugins/cisco/extensions/ha.py @@ -182,4 +182,4 @@ class HATypeCannotBeChanged(nexception.Conflict): class HATypeNotCompatibleWithFloatingIP(nexception.BadRequest): - message = _("HA type %(ha_type) cannot be used with FloatingIP") + message = _("HA type %(ha_type)s cannot be used with FloatingIP") diff --git a/networking_cisco/plugins/cisco/l3/drivers/asr1k/asr1k_routertype_driver.py b/networking_cisco/plugins/cisco/l3/drivers/asr1k/asr1k_routertype_driver.py index bbe0975..ee7c828 100644 --- a/networking_cisco/plugins/cisco/l3/drivers/asr1k/asr1k_routertype_driver.py +++ b/networking_cisco/plugins/cisco/l3/drivers/asr1k/asr1k_routertype_driver.py @@ -533,7 +533,7 @@ class ASR1kL3RouterDriver(drivers.L3RouterBaseDriver): l3_port_check=False) except (exc.ObjectDeletedError, n_exc.PortNotFound) as e: LOG.info(_LI('Unable to delete port for Global router ' - '%(r_id). It has likely been concurrently ' + '%(r_id)s. It has likely been concurrently ' 'deleted. %(err)s'), {'r_id': router_id, 'err': e}) @@ -552,9 +552,17 @@ class ASR1kL3RouterDriver(drivers.L3RouterBaseDriver): context, global_router_id, unschedule=False) except (exc.ObjectDeletedError, l3.RouterNotFound) as e: g_r_type = 'Logical Global' if logical is True else 'Global' - LOG.info(_LI('Unable to delete %(g_r_type)s router. It has likely ' - 'been concurrently deleted. %(err)s'), - {'g_r_type': g_r_type, 'err': e}) + LOG.info(_LI('Unable to delete %(g_r_type)s router %(r_id)s. It ' + 'has likely been concurrently deleted. %(err)s'), + {'g_r_type': g_r_type, 'r_id': global_router_id, + 'err': e}) + except Exception as e: + g_r_type = 'Logical Global' if logical is True else 'Global' + LOG.debug('Failed to delete %(g_r_type)s router %(r_id). It may ' + 'have been deleted concurrently. Error details: ' + '%(err)s', + {'g_r_type': g_r_type, 'r_id': global_router_id, + 'err': e}) def _get_gateway_routers_count(self, context, ext_net_id, routertype_id, router_role, hosting_device_id=None): diff --git a/networking_cisco/plugins/ml2/drivers/cisco/nexus/mech_cisco_nexus.py b/networking_cisco/plugins/ml2/drivers/cisco/nexus/mech_cisco_nexus.py index e234629..ad3d7a0 100644 --- a/networking_cisco/plugins/ml2/drivers/cisco/nexus/mech_cisco_nexus.py +++ b/networking_cisco/plugins/ml2/drivers/cisco/nexus/mech_cisco_nexus.py @@ -819,7 +819,7 @@ class CiscoNexusMechanismDriver(api.MechanismDriver): except Exception: LOG.error(_LE("Failed to remove port %(port)s" "vlan %(vlan)d vni %(vni)d " - "switch_ip %(ip), instance %(id)s"), + "switch_ip %(ip)s, instance %(id)s"), {'port': old_port_id, 'vlan': row.vlan_id, 'vni': row.vni, diff --git a/networking_cisco/tests/unit/cisco/device_manager/plugging_test_driver.py b/networking_cisco/tests/unit/cisco/device_manager/plugging_test_driver.py index a44eb6a..e70ea0d 100644 --- a/networking_cisco/tests/unit/cisco/device_manager/plugging_test_driver.py +++ b/networking_cisco/tests/unit/cisco/device_manager/plugging_test_driver.py @@ -118,7 +118,7 @@ class TestPluggingDriver(n1kv_ml2_trunking_driver.N1kvML2TrunkingPlugDriver): except exception_type: resource_ids.remove(item_id) except n_exc.NeutronException as e: - LOG.error(_LE('Failed to delete %(resource_name) %(net_id)s ' + LOG.error(_LE('Failed to delete %(resource_name)s %(net_id)s ' 'for service vm due to %(err)s'), {'resource_name': name, 'net_id': item_id, 'err': e}) diff --git a/networking_cisco/tests/unit/cisco/l3/test_asr1k_routertype_driver.py b/networking_cisco/tests/unit/cisco/l3/test_asr1k_routertype_driver.py index fe1317e..2f7b265 100644 --- a/networking_cisco/tests/unit/cisco/l3/test_asr1k_routertype_driver.py +++ b/networking_cisco/tests/unit/cisco/l3/test_asr1k_routertype_driver.py @@ -72,23 +72,6 @@ class Asr1kRouterTypeDriverTestCase( # that router type in the test setup which makes scheduling deterministic router_type = 'Nexus_ToR_Neutron_router' - def setUp(self, core_plugin=None, l3_plugin=None, dm_plugin=None, - ext_mgr=None): - if l3_plugin is None: - l3_plugin = cisco_test_case.L3_PLUGIN_KLASS - if ext_mgr is None: - ext_mgr = TestSchedulingL3RouterApplianceExtensionManager() - super(Asr1kRouterTypeDriverTestCase, self).setUp( - core_plugin, l3_plugin, dm_plugin, ext_mgr) - - #TODO(bobmel): Remove this mock once bug/#1676435 is fixed - def noop_pre_backlog_processing(context): - LOG.debug('No-op pre_backlog_processing during UTs') - - mock.patch('networking_cisco.plugins.cisco.l3.drivers.asr1k' - '.asr1k_routertype_driver.ASR1kL3RouterDriver' - '.pre_backlog_processing', new=noop_pre_backlog_processing) - def _verify_global_router(self, role, hd_id, ext_net_ids): # The 'ext_net_ids' argument is a dict where key is ext_net_id and # value is a list of subnet_ids that the global router should be @@ -589,8 +572,10 @@ class Asr1kRouterTypeDriverTestCase( ext_net_ids.pop(ext_net_1_id) self._verify_routers(r_ids, ext_net_ids, hd_id, [0, 1]) if update_operation is True: + LOG.debug('Update router %s to remove gateway', r2['id']) self._update('routers', r2['id'], r_spec) else: + LOG.debug('Delete router %s', r2['id']) self._delete('routers', r2['id']) r_ids = {} # should have no global router now @@ -688,13 +673,13 @@ class Asr1kRouterTypeDriverTestCase( if same_ext_net is False: ext_net_ids.pop(msn_ext_net_1_id) self._verify_routers(r_ids, ext_net_ids, hd_id, [0, 1]) + LOG.debug('Update router %s to remove gateway', r2['id']) self._update('routers', r2['id'], r_spec) # should have no global router now self._verify_routers(r_ids, ext_net_ids) def test_router_update_unset_msn_gw(self): - #self._test_router_update_unset_msn_gw() - pass + self._test_router_update_unset_msn_gw() def test_router_update_unset_msn_gw_dt(self): self._test_router_update_unset_msn_gw(same_tenant=False) @@ -778,6 +763,7 @@ class Asr1kRouterTypeDriverTestCase( '.asr1k_routertype_driver.ASR1kL3RouterDriver' '._delete_global_router', new=_concurrent_delete_global_router): + LOG.debug('Update router %s to remove gateway', r['id']) self._update('routers', r['id'], r_spec) # should have no global router now self._verify_routers(r_ids, ext_net_ids)