Don't unschedule routers with auto_schedule=False from dead hosting devices

This change is intended to prevent Global routers to be unscheduled from
dead hosting devices. To not unschedule routers with auto_schedule=False
is also more inline with the semantics of the auto_schedule attribute.

Closes-bug: #1551692
(cherry-picked from commit c86ae2d83a0909b68e5675c949d64173142d4baf)

Change-Id: Iec16883d778d16e935b6ae319e73ac92f256e55d
This commit is contained in:
Bob Melander 2015-11-26 21:18:49 +01:00
parent 5d4ead7edd
commit 54916cf166
2 changed files with 34 additions and 9 deletions

View File

@ -532,17 +532,17 @@ class L3RouterApplianceDBMixin(extraroute_db.ExtraRoute_dbonly_mixin):
hd['id'])
router_ids = []
for binding_db in hd_bindings_db:
self.unschedule_router_from_hosting_device(context,
binding_db)
binding_db.hosting_device_id = None
router_ids.append(binding_db.router_id)
if binding_db.auto_schedule is True:
self.unschedule_router_from_hosting_device(context,
binding_db)
binding_db.hosting_device_id = None
router_ids.append(binding_db.router_id)
self._backlog_router(context, binding_db)
try:
affected_resources[hd['id']].update(
{'routers': router_ids})
except KeyError:
affected_resources[hd['id']] = {'routers': router_ids}
try:
affected_resources[hd['id']].update(
{'routers': router_ids})
except KeyError:
affected_resources[hd['id']] = {'routers': router_ids}
LOG.debug('Finished processing affected routers in dead hosting '
'devices')

View File

@ -1011,6 +1011,31 @@ class L3RoutertypeAwareHostingDeviceSchedulerTestCase(
self.assertEqual(hosting_device_id2,
rs_final[1][HOSTING_DEVICE_ATTR])
def test_router_without_auto_schedule_not_unscheduled_from_dead_hd(self):
with mock.patch.object(
self.plugin, 'unschedule_router_from_hosting_device') as (
mock_unsched):
arg_list = (routertypeawarescheduler.AUTO_SCHEDULE_ATTR, )
kwargs = {
routertypeawarescheduler.AUTO_SCHEDULE_ATTR: False}
router = self._make_router(self.fmt, _uuid(), 'router1',
arg_list=arg_list, **kwargs)
r = router['router']
r_id = r['id']
self.assertIsNone(r[HOSTING_DEVICE_ATTR])
hosting_device_id = '00000000-0000-0000-0000-000000000001'
self._add_router_to_hosting_device(hosting_device_id, r_id)
r_after = self._show('routers', r['id'])['router']
self.assertEqual(hosting_device_id, r_after[HOSTING_DEVICE_ATTR])
affected_resources = {}
# now report hosting device 1 as dead
self.plugin.handle_non_responding_hosting_devices(
self.adminContext, [{'id': hosting_device_id}],
affected_resources)
self.assertEqual(0, mock_unsched.call_count)
r_final = self._show('routers', r['id'])['router']
self.assertEqual(hosting_device_id, r_final[HOSTING_DEVICE_ATTR])
class HostingDeviceRouterL3CfgAgentNotifierTestCase(
L3RoutertypeAwareHostingDeviceSchedulerTestCaseBase):