diff --git a/neutron_lbaas/tests/unit/common/cert_manager/test_local.py b/neutron_lbaas/tests/unit/common/cert_manager/test_local.py index d0b1f65bb..5c61dbe99 100644 --- a/neutron_lbaas/tests/unit/common/cert_manager/test_local.py +++ b/neutron_lbaas/tests/unit/common/cert_manager/test_local.py @@ -65,7 +65,7 @@ class TestLocalManager(base.BaseTestCase): def _store_cert(self): file_mock = mock.mock_open() # Attempt to store the cert - with mock.patch('__builtin__.open', file_mock, create=True): + with mock.patch('six.moves.builtins.open', file_mock, create=True): cert_id = local_cert_manager.CertManager.store_cert( certificate=self.certificate, intermediates=self.intermediates, @@ -97,7 +97,7 @@ class TestLocalManager(base.BaseTestCase): def _get_cert(self, cert_id): file_mock = mock.mock_open() # Attempt to retrieve the cert - with mock.patch('__builtin__.open', file_mock, create=True): + with mock.patch('six.moves.builtins.open', file_mock, create=True): data = local_cert_manager.CertManager.get_cert(cert_id) # Verify the correct files were opened diff --git a/neutron_lbaas/tests/unit/drivers/haproxy/test_namespace_driver.py b/neutron_lbaas/tests/unit/drivers/haproxy/test_namespace_driver.py index 92a47b270..07ae403b8 100644 --- a/neutron_lbaas/tests/unit/drivers/haproxy/test_namespace_driver.py +++ b/neutron_lbaas/tests/unit/drivers/haproxy/test_namespace_driver.py @@ -241,7 +241,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): def test_update(self): self.driver._get_state_file_path = mock.Mock(return_value='/path') self.driver._spawn = mock.Mock() - with mock.patch('__builtin__.open') as m_open: + with mock.patch('six.moves.builtins.open') as m_open: file_mock = mock.MagicMock() m_open.return_value = file_mock file_mock.__enter__.return_value = file_mock @@ -667,7 +667,7 @@ class TestNamespaceDriverModule(base.BaseTestCase): @mock.patch('neutron.agent.linux.utils.execute') def test_kill_pids_in_file(self, execute, exists): pid_path = '/var/lib/data' - with mock.patch('__builtin__.open') as m_open: + with mock.patch('six.moves.builtins.open') as m_open: exists.return_value = False file_mock = mock.MagicMock() m_open.return_value = file_mock diff --git a/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py b/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py index a343a71fd..68eafba65 100644 --- a/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py +++ b/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py @@ -20,6 +20,7 @@ import mock from neutron.common import exceptions from neutron.extensions import portbindings from neutron.plugins.common import constants +import six from neutron_lbaas.db.loadbalancer import models from neutron_lbaas.drivers.haproxy \ @@ -78,7 +79,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): rdb.asert_called_once_with(dirs) upin.assert_has_calls([mock.call(lbs[0]), mock.call(lbs[1])]) self.assertEqual(2, upin.call_count) - #deployed_loadbalancer_ids is a set + # deployed_loadbalancer_ids is a set self.assertEqual(1, len(self.driver.deployed_loadbalancer_ids)) self.assertIn(self._sample_in_loadbalancer().id, self.driver.deployed_loadbalancer_ids) @@ -514,7 +515,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): with contextlib.nested( mock.patch.object(self.driver, '_get_state_file_path'), mock.patch.object(self.driver, '_spawn'), - mock.patch('__builtin__.open') + mock.patch.object(six.moves.builtins, 'open') ) as (gsp, spawn, mock_open): mock_open.return_value = ['5'] @@ -650,7 +651,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): def test_kill_pids_in_file(self): with contextlib.nested( mock.patch('os.path.exists'), - mock.patch('__builtin__.open'), + mock.patch.object(six.moves.builtins, 'open'), mock.patch('neutron.agent.linux.utils.execute'), mock.patch.object(namespace_driver.LOG, 'exception'), ) as (path_exists, mock_open, mock_execute, mock_log): diff --git a/neutron_lbaas/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py b/neutron_lbaas/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py index c6328c0ac..c1050eebb 100644 --- a/neutron_lbaas/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py +++ b/neutron_lbaas/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py @@ -16,6 +16,7 @@ import contextlib import mock from neutron.common import exceptions +import six from neutron_lbaas.services.loadbalancer.drivers.haproxy \ import namespace_driver @@ -73,7 +74,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): with contextlib.nested( mock.patch.object(self.driver, '_get_state_file_path'), mock.patch.object(self.driver, '_spawn'), - mock.patch('__builtin__.open') + mock.patch.object(six.moves.builtins, 'open') ) as (gsp, spawn, mock_open): mock_open.return_value = ['5'] @@ -410,7 +411,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): def test_kill_pids_in_file(self): with contextlib.nested( mock.patch('os.path.exists'), - mock.patch('__builtin__.open'), + mock.patch.object(six.moves.builtins, 'open'), mock.patch('neutron.agent.linux.utils.execute'), mock.patch.object(namespace_driver.LOG, 'exception'), ) as (path_exists, mock_open, mock_execute, mock_log):