Fix attribute mismatch in router provider update

The transition of a router from distributed to centralized may
mistakenley get its 'ha' attribute updated at the same time. The
side-effect is that the router may become HA enabled unexpectedly.

This patch fixed the mismatched attribute in _update_router_provider
method which addressed the issue cited above.

Closes-Bug: #1780094
Change-Id: Ib00de137692979229d1b7ba033ecff04e9cc9db0
This commit is contained in:
Kailun Qin 2018-07-05 07:17:31 +08:00
parent d786643214
commit 886e241553
2 changed files with 36 additions and 1 deletions

View File

@ -146,7 +146,12 @@ class DriverController(object):
payload.request_body['distributed'] = (payload.states[0]
['distributed'])
if 'ha' not in payload.request_body:
payload.request_body['ha'] = payload.states[0]['distributed']
payload.request_body['ha'] = payload.states[0]['ha']
LOG.debug("Get a provider driver handle based on the ha flag: "
"%(ha_flag)s and distributed flag: %(distributed_flag)s",
{'ha_flag': payload.request_body['ha'],
'distributed_flag':
payload.request_body['distributed']})
new_drv = self._attrs_to_driver(payload.request_body)
if new_drv:
LOG.debug("Router %(id)s migrating from %(old)s provider to "

View File

@ -111,6 +111,36 @@ class TestDriverController(testlib_api.SqlTestCase):
states=({'flavor_id': 'old_fid'},)))
mock_cb.assert_not_called()
def test__update_router_provider_with_flags(self):
test_dc = driver_controller.DriverController(self.fake_l3)
with mock.patch.object(registry, "publish"):
with mock.patch.object(test_dc, "get_provider_for_router"):
with mock.patch.object(
driver_controller,
"_ensure_driver_supports_request") as _ensure:
_ensure.side_effect = lib_exc.InvalidInput(
error_message='message')
with mock.patch(
"neutron.services.l3_router.service_providers."
"driver_controller.LOG.debug") as mock_log:
self.assertRaises(
lib_exc.InvalidInput,
test_dc._update_router_provider,
None, None, None,
payload=events.DBEventPayload(
None, request_body={'name': 'testname',
'distributed': False},
states=({'flavor_id': None,
'distributed': True, 'ha': False},)))
# To validate that the 'ha' attribute of the router
# stays unchanged from the previous state while
# updating 'distributed' from True to False.
mock_log.assert_any_call(
"Get a provider driver handle based on the ha "
"flag: %(ha_flag)s and distributed flag: "
"%(distributed_flag)s",
{'ha_flag': False, 'distributed_flag': False})
@mock.patch('neutron_lib.callbacks.registry.notify')
def test__set_router_provider_attr_lookups(self, mock_cb):
# ensure correct drivers are looked up based on attrs