trivial: Make driver_controller's _attrs_to_driver py3 compatible

In python3 dict.values() doesn't return list but instead dict_values,
it must be converted to list to "enjoy" list operations like insert.
Add unit tests to be sure.

Closes-Bug: #1923423
Change-Id: Ie270ac2ee65c02bdb099d11af7f1d2fb62ad0f61
(cherry picked from commit e270ac2ee65c02bdb099d11af7f1d2fb62ad0f61)
(cherry picked from commit 3ec596f9ef)
(cherry picked from commit 321162a653)
This commit is contained in:
elajkat 2021-04-12 09:54:59 +02:00 committed by Lajos Katona
parent 31d6707988
commit f15fb6831a
2 changed files with 14 additions and 1 deletions

View File

@ -224,7 +224,7 @@ class DriverController(object):
distributed = _is_distributed( distributed = _is_distributed(
router.get('distributed', lib_const.ATTR_NOT_SPECIFIED)) router.get('distributed', lib_const.ATTR_NOT_SPECIFIED))
ha = _is_ha(router.get('ha', lib_const.ATTR_NOT_SPECIFIED)) ha = _is_ha(router.get('ha', lib_const.ATTR_NOT_SPECIFIED))
drivers = self.drivers.values() drivers = list(self.drivers.values())
# make sure default is tried before the rest if defined # make sure default is tried before the rest if defined
if self.default_provider: if self.default_provider:
drivers.insert(0, self.drivers[self.default_provider]) drivers.insert(0, self.drivers[self.default_provider])

View File

@ -25,6 +25,7 @@ from oslo_utils import uuidutils
import testtools import testtools
from neutron.services.l3_router.service_providers import driver_controller from neutron.services.l3_router.service_providers import driver_controller
from neutron.services.l3_router.service_providers import single_node
from neutron.services import provider_configuration from neutron.services import provider_configuration
from neutron.tests import base from neutron.tests import base
from neutron.tests.unit import testlib_api from neutron.tests.unit import testlib_api
@ -114,6 +115,18 @@ class TestDriverController(testlib_api.SqlTestCase):
states=({'flavor_id': 'old_fid'},))) states=({'flavor_id': 'old_fid'},)))
mock_cb.assert_not_called() mock_cb.assert_not_called()
def test___attrs_to_driver(self):
test_dc = driver_controller.DriverController(self.fake_l3)
test_dc.default_provider = 'single_node'
self.assertIsInstance(test_dc._attrs_to_driver({}),
single_node.SingleNodeDriver)
test_dc.default_provider = 'ha'
with mock.patch.object(driver_controller,
"_is_driver_compatible", return_value=False):
self.assertRaises(NotImplementedError, test_dc._attrs_to_driver,
{})
def test__update_router_provider_with_flags(self): def test__update_router_provider_with_flags(self):
test_dc = driver_controller.DriverController(self.fake_l3) test_dc = driver_controller.DriverController(self.fake_l3)
with mock.patch.object(registry, "publish"): with mock.patch.object(registry, "publish"):