Fix H302 violations in unit tests

H302 violation is reported by flake8 when importing separated objects from
modules instead of importing the whole module.
e.g.   from package.module import function
       function()
is changed to
       from package import module
       module.function()

Change-Id: Ic6975f39c755ded54149a9c01fcdcfaf78c596fc
Partial-Bug: #1291032
This commit is contained in:
Jakub Libosvar 2014-04-18 15:30:32 +02:00
parent 26182d6819
commit c2634fa580
80 changed files with 1372 additions and 1295 deletions

View File

@ -17,7 +17,7 @@
import eventlet
import fixtures
from six.moves import xrange
from six import moves
from neutron.agent.linux import async_process
from neutron.tests import base
@ -29,7 +29,7 @@ class TestAsyncProcess(base.BaseTestCase):
super(TestAsyncProcess, self).setUp()
self.test_file_path = self.useFixture(
fixtures.TempDir()).join("test_async_process.tmp")
self.data = [str(x) for x in xrange(4)]
self.data = [str(x) for x in moves.xrange(4)]
with file(self.test_file_path, 'w') as f:
f.writelines('%s\n' % item for item in self.data)

View File

@ -26,7 +26,7 @@ from webob import exc
from neutron import context
from neutron.extensions import portbindings
from neutron.manager import NeutronManager
from neutron import manager
from neutron.tests.unit import test_db_plugin
@ -75,7 +75,7 @@ class PortBindingsTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
self._check_response_no_portbindings(non_admin_port)
def test_ports_vif_details(self):
plugin = NeutronManager.get_plugin()
plugin = manager.NeutronManager.get_plugin()
cfg.CONF.set_default('allow_overlapping_ips', True)
with contextlib.nested(self.port(), self.port()):
ctx = context.get_admin_context()

View File

@ -12,10 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
import collections
import mock
from oslo.config import cfg
import testtools
@ -29,6 +26,12 @@ from neutron.plugins.openvswitch.common import constants
from neutron.tests import base
from neutron.tests import tools
try:
OrderedDict = collections.OrderedDict
except AttributeError:
import ordereddict
OrderedDict = ordereddict.OrderedDict
OVS_LINUX_KERN_VERS_WITHOUT_VXLAN = "3.12.0"

View File

@ -17,7 +17,7 @@
#
# @author Kevin Benton
from contextlib import nested
import contextlib
import mock
from neutron.tests.unit.bigswitch import test_router_db
@ -32,7 +32,7 @@ HTTPCON = SERVERMANAGER + '.httplib.HTTPConnection'
class CapabilitiesTests(test_router_db.RouterDBTestBase):
def test_floating_ip_capability(self):
with nested(
with contextlib.nested(
mock.patch(SERVERRESTCALL,
return_value=(200, None, None, '["floatingip"]')),
mock.patch(SERVERPOOL + '.rest_create_floatingip',
@ -51,7 +51,7 @@ class CapabilitiesTests(test_router_db.RouterDBTestBase):
)
def test_floating_ip_capability_neg(self):
with nested(
with contextlib.nested(
mock.patch(SERVERRESTCALL,
return_value=(200, None, None, '[""]')),
mock.patch(SERVERPOOL + '.rest_update_network',

View File

@ -15,7 +15,7 @@
#
# @author: Kevin Benton, Big Switch Networks
from contextlib import nested
import contextlib
import mock
@ -164,7 +164,7 @@ class TestRestProxyAgent(BaseAgentTestCase):
'CONF.RESTPROXYAGENT.polling_interval': 5,
'CONF.RESTPROXYAGENT.virtual_switch_type': 'ovs',
'CONF.AGENT.root_helper': 'helper'}
with nested(
with contextlib.nested(
mock.patch(AGENTMOD + '.cfg', **cfg_attrs),
mock.patch(NEUTRONCFG),
mock.patch(PLCONFIG),

View File

@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from contextlib import nested
import contextlib
import mock
from oslo.config import cfg
import webob.exc
@ -23,7 +23,7 @@ import webob.exc
from neutron.common import constants
from neutron import context
from neutron.extensions import portbindings
from neutron.manager import NeutronManager
from neutron import manager
from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit.bigswitch import fake_server
from neutron.tests.unit.bigswitch import test_base
@ -106,7 +106,7 @@ class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2,
self._list_ports('json', netid=netid))['ports']
def test_rollback_for_port_create(self):
plugin = NeutronManager.get_plugin()
plugin = manager.NeutronManager.get_plugin()
with self.subnet() as s:
# stop normal patch
self.httpPatch.stop()
@ -183,7 +183,7 @@ class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2,
def test_create404_triggers_sync(self):
# allow async port thread for this patch
self.spawn_p.stop()
with nested(
with contextlib.nested(
self.subnet(),
patch(HTTPCON, create=True,
new=fake_server.HTTPConnectionMock404),
@ -192,7 +192,7 @@ class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2,
) as (s, mock_http, mock_send_all):
with self.port(subnet=s, device_id='somedevid') as p:
# wait for the async port thread to finish
plugin = NeutronManager.get_plugin()
plugin = manager.NeutronManager.get_plugin()
plugin.evpool.waitall()
call = mock.call(
send_routers=True, send_ports=True, send_floating_ips=True,
@ -259,7 +259,7 @@ class TestBigSwitchProxyNetworksV2(test_plugin.TestNetworksV2,
def _get_networks(self, tenant_id):
ctx = context.Context('', tenant_id)
return NeutronManager.get_plugin().get_networks(ctx)
return manager.NeutronManager.get_plugin().get_networks(ctx)
def test_rollback_on_network_create(self):
tid = test_api_v2._uuid()
@ -306,7 +306,7 @@ class TestBigSwitchProxySubnetsV2(test_plugin.TestSubnetsV2,
class TestBigSwitchProxySync(BigSwitchProxyPluginV2TestCase):
def test_send_data(self):
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
result = plugin_obj._send_all_data()
self.assertEqual(result[0], 200)

View File

@ -21,15 +21,15 @@
import contextlib
import copy
from mock import patch
import mock
from oslo.config import cfg
from six.moves import xrange
from six import moves
from webob import exc
from neutron.common.test_lib import test_config
from neutron.common import test_lib
from neutron import context
from neutron.extensions import l3
from neutron.manager import NeutronManager
from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.bigswitch.extensions import routerrule
from neutron.tests.unit.bigswitch import fake_server
@ -79,12 +79,12 @@ class RouterDBTestBase(test_base.BigSwitchTestBase,
super(RouterDBTestBase, self).setUp(plugin=self._plugin_name,
ext_mgr=ext_mgr)
cfg.CONF.set_default('allow_overlapping_ips', False)
self.plugin_obj = NeutronManager.get_plugin()
self.plugin_obj = manager.NeutronManager.get_plugin()
self.startHttpPatch()
def tearDown(self):
super(RouterDBTestBase, self).tearDown()
del test_config['config_files']
del test_lib.test_config['config_files']
class RouterDBTestCase(RouterDBTestBase,
@ -172,7 +172,7 @@ class RouterDBTestCase(RouterDBTestBase,
port_id=p1['port']['id'],
tenant_id=tenant1_id)
self.httpPatch.stop()
multiFloatPatch = patch(
multiFloatPatch = mock.patch(
HTTPCON,
new=fake_server.VerifyMultiTenantFloatingIP)
multiFloatPatch.start()
@ -301,7 +301,7 @@ class RouterDBTestCase(RouterDBTestBase,
def test_send_data(self):
fmt = 'json'
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
with self.router() as r:
r_id = r['router']['id']
@ -502,7 +502,7 @@ class RouterDBTestCase(RouterDBTestBase,
cfg.CONF.set_override('max_router_rules', 10, 'ROUTER')
with self.router() as r:
rules = []
for i in xrange(1, 12):
for i in moves.xrange(1, 12):
rule = {'source': 'any', 'nexthops': [],
'destination': '1.1.1.' + str(i) + '/32',
'action': 'permit'}
@ -514,7 +514,7 @@ class RouterDBTestCase(RouterDBTestBase,
def test_rollback_on_router_create(self):
tid = test_api_v2._uuid()
self.httpPatch.stop()
with patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
self._create_router('json', tid)
self.assertTrue(len(self._get_routers(tid)) == 0)
@ -522,7 +522,7 @@ class RouterDBTestCase(RouterDBTestBase,
with self.router() as r:
data = {'router': {'name': 'aNewName'}}
self.httpPatch.stop()
with patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
self.new_update_request(
'routers', data, r['router']['id']).get_response(self.api)
self.httpPatch.start()
@ -533,7 +533,7 @@ class RouterDBTestCase(RouterDBTestBase,
def test_rollback_on_router_delete(self):
with self.router() as r:
self.httpPatch.stop()
with patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
self._delete('routers', r['router']['id'],
expected_code=exc.HTTPInternalServerError.code)
self.httpPatch.start()

View File

@ -14,7 +14,7 @@
#
# @author: Kevin Benton, kevin.benton@bigswitch.com
#
from contextlib import nested
import contextlib
import httplib
import socket
import ssl
@ -22,7 +22,7 @@ import ssl
import mock
from oslo.config import cfg
from neutron.manager import NeutronManager
from neutron import manager
from neutron.openstack.common import importutils
from neutron.plugins.bigswitch import servermanager
from neutron.tests.unit.bigswitch import test_restproxy_plugin as test_rp
@ -61,7 +61,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
'[ABCD:EF01:2345:6789:ABCD:EF01:2345:6789]')
def test_sticky_cert_fetch_fail(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.ssl = True
with mock.patch(
'ssl.get_server_certificate',
@ -75,10 +75,10 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
sslgetmock.assert_has_calls([mock.call(('example.org', 443))])
def test_consistency_watchdog(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.capabilities = []
self.watch_p.stop()
with nested(
with contextlib.nested(
mock.patch('eventlet.sleep'),
mock.patch(
SERVERMANAGER + '.ServerPool.rest_call',
@ -119,7 +119,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
'HASH2')
def test_file_put_contents(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
with mock.patch(SERVERMANAGER + '.open', create=True) as omock:
pl.servers._file_put_contents('somepath', 'contents')
omock.assert_has_calls([mock.call('somepath', 'w')])
@ -128,7 +128,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
])
def test_combine_certs_to_file(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
with mock.patch(SERVERMANAGER + '.open', create=True) as omock:
omock.return_value.__enter__().read.return_value = 'certdata'
pl.servers._combine_certs_to_file(['cert1.pem', 'cert2.pem'],
@ -248,7 +248,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
self.assertEqual(resp, (0, None, None, None))
def test_cert_get_fail(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.ssl = True
with mock.patch('os.path.exists', return_value=False):
self.assertRaises(cfg.Error,
@ -256,11 +256,11 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
*('example.org', 443))
def test_cert_make_dirs(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.ssl = True
cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY')
# pretend base dir exists, 3 children don't, and host cert does
with nested(
with contextlib.nested(
mock.patch('os.path.exists', side_effect=[True, False, False,
False, True]),
mock.patch('os.makedirs'),
@ -279,7 +279,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
self.assertEqual(makemock.call_count, 3)
def test_no_cert_error(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.ssl = True
cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY')
# pretend base dir exists and 3 children do, but host cert doesn't
@ -296,18 +296,18 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
self.assertEqual(exmock.call_count, 5)
def test_action_success(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
self.assertTrue(pl.servers.action_success((200,)))
def test_server_failure(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
self.assertTrue(pl.servers.server_failure((404,)))
# server failure has an ignore codes option
self.assertFalse(pl.servers.server_failure((404,),
ignore_codes=[404]))
def test_conflict_triggers_sync(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
with mock.patch(
SERVERMANAGER + '.ServerProxy.rest_call',
return_value=(httplib.CONFLICT, 0, 0, 0)
@ -322,7 +322,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
])
def test_conflict_sync_raises_error_without_topology(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
pl.servers.get_topo_function = None
with mock.patch(
SERVERMANAGER + '.ServerProxy.rest_call',
@ -337,7 +337,7 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
)
def test_floating_calls(self):
pl = NeutronManager.get_plugin()
pl = manager.NeutronManager.get_plugin()
with mock.patch(SERVERMANAGER + '.ServerPool.rest_action') as ramock:
pl.servers.rest_create_floatingip('tenant', {'id': 'somefloat'})
pl.servers.rest_update_floatingip('tenant', {'name': 'myfl'}, 'id')

View File

@ -14,7 +14,7 @@
#
# @author: Kevin Benton, kevin.benton@bigswitch.com
#
from contextlib import nested
import contextlib
import os
import mock
@ -101,7 +101,7 @@ class TestSslSticky(test_ssl_certificate_base):
def test_sticky_cert(self):
# SSL connection should be successful and cert should be cached
with nested(
with contextlib.nested(
mock.patch(HTTPS, new=fake_server.HTTPSHostValidation),
self.network()
):
@ -241,7 +241,7 @@ class TestSslNoValidation(test_ssl_certificate_base):
def test_validation_disabled(self):
# SSL connection should be successful without any certificates
# If not, attempting to create a network will raise an exception
with nested(
with contextlib.nested(
mock.patch(HTTPS, new=fake_server.HTTPSNoValidation),
self.network()
):

View File

@ -19,7 +19,7 @@
from neutron.openstack.common import log as logging
from neutron.plugins.cisco.common import cisco_exceptions as c_exc
from neutron.plugins.cisco.n1kv.n1kv_client import Client as n1kv_client
from neutron.plugins.cisco.n1kv import n1kv_client
LOG = logging.getLogger(__name__)
@ -31,7 +31,7 @@ _resource_metadata = {'port': ['id', 'macAddress', 'ipAddress', 'subnetId'],
'ipAddress', 'subnetId']}
class TestClient(n1kv_client):
class TestClient(n1kv_client.Client):
def __init__(self, **kwargs):
self.broken = False

View File

@ -18,7 +18,7 @@
# @author: Abhishek Raut, Cisco Systems Inc.
# @author: Rudrajit Tapadar, Cisco Systems Inc.
from six.moves import xrange
from six import moves
from sqlalchemy.orm import exc as s_exc
from testtools import matchers
@ -147,7 +147,7 @@ class VlanAllocationsTest(base.BaseTestCase):
def test_vlan_pool(self):
vlan_ids = set()
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
for x in moves.xrange(VLAN_MIN, VLAN_MAX + 1):
(physical_network, seg_type,
vlan_id, m_ip) = n1kv_db_v2.reserve_vlan(self.session, self.net_p)
self.assertEqual(physical_network, PHYS_NET)
@ -242,7 +242,7 @@ class VxlanAllocationsTest(base.BaseTestCase,
def test_vxlan_pool(self):
vxlan_ids = set()
for x in xrange(VXLAN_MIN, VXLAN_MAX + 1):
for x in moves.xrange(VXLAN_MIN, VXLAN_MAX + 1):
vxlan = n1kv_db_v2.reserve_vxlan(self.session, self.net_p)
vxlan_id = vxlan[2]
self.assertThat(vxlan_id, matchers.GreaterThan(VXLAN_MIN - 1))

View File

@ -18,7 +18,7 @@
# @author: Abhishek Raut, Cisco Systems Inc.
# @author: Sourabh Patwardhan, Cisco Systems Inc.
from mock import patch
import mock
from neutron.api import extensions as neutron_extensions
from neutron.api.v2 import attributes
@ -184,7 +184,7 @@ class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase):
# in the unit tests, we need to 'fake' it by patching the HTTP library
# itself. We install a patch for a fake HTTP connection class.
# Using __name__ to avoid having to enter the full module path.
http_patcher = patch(n1kv_client.httplib2.__name__ + ".Http")
http_patcher = mock.patch(n1kv_client.httplib2.__name__ + ".Http")
FakeHttpConnection = http_patcher.start()
# Now define the return values for a few functions that may be called
# on any instance of the fake HTTP connection class.
@ -201,13 +201,14 @@ class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase):
# in the background.
# Return a dummy VSM IP address
get_vsm_hosts_patcher = patch(n1kv_client.__name__ +
".Client._get_vsm_hosts")
get_vsm_hosts_patcher = mock.patch(n1kv_client.__name__ +
".Client._get_vsm_hosts")
fake_get_vsm_hosts = get_vsm_hosts_patcher.start()
fake_get_vsm_hosts.return_value = ["127.0.0.1"]
# Return dummy user profiles
get_cred_name_patcher = patch(cdb.__name__ + ".get_credential_name")
get_cred_name_patcher = mock.patch(cdb.__name__ +
".get_credential_name")
fake_get_cred_name = get_cred_name_patcher.start()
fake_get_cred_name.return_value = {"user_name": "admin",
"password": "admin_password"}
@ -495,8 +496,8 @@ class TestN1kvPorts(test_plugin.TestPortsV2,
"""Test parameters for first port create sent to the VSM."""
profile_obj = self._make_test_policy_profile(name='test_profile')
with self.network() as network:
client_patch = patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClientInvalidRequest)
client_patch = mock.patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClientInvalidRequest)
client_patch.start()
data = {'port': {n1kv.PROFILE_ID: profile_obj.id,
'tenant_id': self.tenant_id,
@ -510,8 +511,8 @@ class TestN1kvPorts(test_plugin.TestPortsV2,
def test_create_next_port_invalid_parameters_fail(self):
"""Test parameters for subsequent port create sent to the VSM."""
with self.port() as port:
client_patch = patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClientInvalidRequest)
client_patch = mock.patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClientInvalidRequest)
client_patch.start()
data = {'port': {n1kv.PROFILE_ID: port['port']['n1kv:profile_id'],
'tenant_id': port['port']['tenant_id'],
@ -524,8 +525,8 @@ class TestN1kvPorts(test_plugin.TestPortsV2,
class TestN1kvPolicyProfiles(N1kvPluginTestCase):
def test_populate_policy_profile(self):
client_patch = patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClient)
client_patch = mock.patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClient)
client_patch.start()
instance = n1kv_neutron_plugin.N1kvNeutronPluginV2()
instance._populate_policy_profiles()
@ -537,11 +538,11 @@ class TestN1kvPolicyProfiles(N1kvPluginTestCase):
def test_populate_policy_profile_delete(self):
# Patch the Client class with the TestClient class
with patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClient):
with mock.patch(n1kv_client.__name__ + ".Client",
new=fake_client.TestClient):
# Patch the _get_total_profiles() method to return a custom value
with patch(fake_client.__name__ +
'.TestClient._get_total_profiles') as obj_inst:
with mock.patch(fake_client.__name__ +
'.TestClient._get_total_profiles') as obj_inst:
# Return 3 policy profiles
obj_inst.return_value = 3
plugin = manager.NeutronManager.get_plugin()

View File

@ -31,7 +31,7 @@ from neutron.db import db_base_plugin_v2 as base_plugin
from neutron.db import l3_db
from neutron.extensions import portbindings
from neutron.extensions import providernet as provider
from neutron.manager import NeutronManager
from neutron import manager
from neutron.openstack.common import gettextutils
from neutron.plugins.cisco.common import cisco_constants as const
from neutron.plugins.cisco.common import cisco_exceptions as c_exc
@ -136,7 +136,7 @@ class CiscoNetworkPluginV2TestCase(test_db_plugin.NeutronDbPluginV2TestCase):
new=NEXUS_IP_ADDR).start()
def _get_plugin_ref(self):
return getattr(NeutronManager.get_plugin(),
return getattr(manager.NeutronManager.get_plugin(),
"_model")._plugins[const.VSWITCH_PLUGIN]
@contextlib.contextmanager
@ -239,7 +239,7 @@ class TestCiscoGetAttribute(CiscoNetworkPluginV2TestCase):
This test also checks that this operation does not cause
excessive nesting of calls to deepcopy.
"""
plugin = NeutronManager.get_plugin()
plugin = manager.NeutronManager.get_plugin()
def _lazy_gettext(msg):
return gettextutils.Message(msg, domain='neutron')

View File

@ -21,8 +21,7 @@ from oslo.config import cfg
import testtools
import webob.exc
from neutron.api.extensions import ExtensionMiddleware
from neutron.api.extensions import PluginAwareExtensionManager
from neutron.api import extensions
from neutron.common import config
from neutron import context
import neutron.db.l3_db # noqa
@ -34,9 +33,7 @@ from neutron.plugins.common import constants
from neutron.services.loadbalancer import (
plugin as loadbalancer_plugin
)
from neutron.services.loadbalancer.drivers import (
abstract_driver
)
from neutron.services.loadbalancer.drivers import abstract_driver
from neutron.services import provider_configuration as pconf
from neutron.tests.unit import test_db_plugin
@ -324,12 +321,12 @@ class LoadBalancerPluginDbTestCase(LoadBalancerTestMixin,
if not ext_mgr:
self.plugin = loadbalancer_plugin.LoadBalancerPlugin()
ext_mgr = PluginAwareExtensionManager(
ext_mgr = extensions.PluginAwareExtensionManager(
extensions_path,
{constants.LOADBALANCER: self.plugin}
)
app = config.load_paste_app('extensions_test_app')
self.ext_api = ExtensionMiddleware(app, ext_mgr=ext_mgr)
self.ext_api = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr)
get_lbaas_agent_patcher = mock.patch(
'neutron.services.loadbalancer.agent_scheduler'

View File

@ -19,8 +19,7 @@ import logging
import webob.exc
from neutron.api.extensions import ExtensionMiddleware
from neutron.api.extensions import PluginAwareExtensionManager
from neutron.api import extensions
from neutron.common import config
from neutron import context
import neutron.extensions
@ -136,12 +135,12 @@ class MeteringPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
)
self.plugin = metering_plugin.MeteringPlugin()
ext_mgr = PluginAwareExtensionManager(
ext_mgr = extensions.PluginAwareExtensionManager(
extensions_path,
{constants.METERING: self.plugin}
)
app = config.load_paste_app('extensions_test_app')
self.ext_api = ExtensionMiddleware(app, ext_mgr=ext_mgr)
self.ext_api = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr)
def test_create_metering_label(self):
name = 'my label'

View File

@ -23,8 +23,7 @@ import os
from oslo.config import cfg
import webob.exc
from neutron.api.extensions import ExtensionMiddleware
from neutron.api.extensions import PluginAwareExtensionManager
from neutron.api import extensions as api_extensions
from neutron.common import config
from neutron import context
from neutron.db import agentschedulers_db
@ -441,13 +440,13 @@ class VPNPluginDbTestCase(VPNTestMixin,
self._subnet_id = uuidutils.generate_uuid()
self.core_plugin = TestVpnCorePlugin
self.plugin = vpn_plugin.VPNPlugin()
ext_mgr = PluginAwareExtensionManager(
ext_mgr = api_extensions.PluginAwareExtensionManager(
extensions_path,
{constants.CORE: self.core_plugin,
constants.VPN: self.plugin}
)
app = config.load_paste_app('extensions_test_app')
self.ext_api = ExtensionMiddleware(app, ext_mgr=ext_mgr)
self.ext_api = api_extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr)
class TestVpnaas(VPNPluginDbTestCase):

View File

@ -23,7 +23,7 @@ from neutron.extensions import servicetype
from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants
from neutron.services.service_base import ServicePluginBase
from neutron.services import service_base
DUMMY_PLUGIN_NAME = "dummy_plugin"
@ -85,7 +85,7 @@ class Dummy(object):
controller)]
class DummyServicePlugin(ServicePluginBase):
class DummyServicePlugin(service_base.ServicePluginBase):
"""This is a simple plugin for managing instantes of a fictional 'dummy'
service. This plugin is provided as a proof-of-concept of how
advanced service might leverage the service type extension.

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from abc import abstractmethod
import abc
from neutron.api import extensions
from neutron import wsgi
@ -60,7 +60,7 @@ class ExtensionExpectingPluginInterface(StubExtension):
class StubPluginInterface(extensions.PluginInterface):
@abstractmethod
@abc.abstractmethod
def get_foo(self, bar=None):
pass

View File

@ -18,7 +18,7 @@
# @author: Kaiwei Fan, VMware, Inc
#
from abc import abstractmethod
import abc
from neutron.api import extensions
from neutron.api.v2 import base
@ -101,10 +101,10 @@ class Extensionattribute(extensions.ExtensionDescriptor):
class ExtensionObjectTestPluginBase(object):
@abstractmethod
@abc.abstractmethod
def create_ext_test_resource(self, context, router):
pass
@abstractmethod
@abc.abstractmethod
def get_ext_test_resource(self, context, id, fields=None):
pass

View File

@ -15,7 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from abc import abstractmethod
import abc
from neutron.api import extensions
from neutron.openstack.common import jsonutils
@ -30,7 +30,7 @@ class FoxInSocksController(wsgi.Controller):
class FoxInSocksPluginInterface(extensions.PluginInterface):
@abstractmethod
@abc.abstractmethod
def method_to_support_foxnsox_extension(self):
pass

View File

@ -22,7 +22,7 @@ from oslo.config import cfg
from neutron import context
from neutron.extensions import portbindings
from neutron.manager import NeutronManager
from neutron import manager
from neutron.tests.unit import test_db_plugin as test_plugin
@ -54,7 +54,7 @@ class TestHyperVVirtualSwitchPortsV2(
def test_ports_vif_details(self):
cfg.CONF.set_default('allow_overlapping_ips', True)
plugin = NeutronManager.get_plugin()
plugin = manager.NeutronManager.get_plugin()
with contextlib.nested(self.port(), self.port()) as (port1, port2):
ctx = context.get_admin_context()
ports = plugin.get_ports(ctx)

View File

@ -14,7 +14,7 @@
# limitations under the License.
from oslo.config import cfg
from six.moves import xrange
from six import moves
import testtools
from testtools import matchers
@ -108,7 +108,7 @@ class NetworkStatesTest(base.BaseTestCase):
def test_network_pool(self):
vlan_ids = set()
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
for x in moves.xrange(VLAN_MIN, VLAN_MAX + 1):
physical_network, vlan_id = lb_db.reserve_network(self.session)
self.assertEqual(physical_network, PHYS_NET)
self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1))

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from neutron.tests.unit.metaplugin.test_metaplugin import setup_metaplugin_conf
from neutron.tests.unit.metaplugin.test_metaplugin import unregister_meta_hooks
from neutron.tests.unit.metaplugin import test_metaplugin
from neutron.tests.unit import test_db_plugin as test_plugin
from neutron.tests.unit import test_l3_plugin
@ -30,9 +29,9 @@ class MetaPluginV2DBTestCase(test_plugin.NeutronDbPluginV2TestCase):
# as this class will always invoke super with self._plugin_name.
# These keyword parameters ensure setUp methods always have the
# same signature.
setup_metaplugin_conf()
test_metaplugin.setup_metaplugin_conf()
ext_mgr = ext_mgr or test_l3_plugin.L3TestExtensionManager()
self.addCleanup(unregister_meta_hooks)
self.addCleanup(test_metaplugin.unregister_meta_hooks)
super(MetaPluginV2DBTestCase, self).setUp(
plugin=self._plugin_name, ext_mgr=ext_mgr,
service_plugins=service_plugins)

View File

@ -27,10 +27,7 @@ from neutron.db import db_base_plugin_v2
from neutron.db import models_v2
from neutron.extensions import flavor as ext_flavor
from neutron.openstack.common import uuidutils
from neutron.plugins.metaplugin.meta_neutron_plugin import (
FaildToAddFlavorBinding)
from neutron.plugins.metaplugin.meta_neutron_plugin import FlavorNotFound
from neutron.plugins.metaplugin.meta_neutron_plugin import MetaPluginV2
from neutron.plugins.metaplugin import meta_neutron_plugin
from neutron.tests import base
CONF_FILE = ""
@ -112,9 +109,10 @@ class MetaNeutronPluginV2Test(base.BaseTestCase):
self.client_inst.delete_network.return_value = True
self.client_inst.delete_port.return_value = True
self.client_inst.delete_subnet.return_value = True
plugin = MetaPluginV2.__module__ + '.' + MetaPluginV2.__name__
plugin = (meta_neutron_plugin.MetaPluginV2.__module__ + '.'
+ meta_neutron_plugin.MetaPluginV2.__name__)
self.setup_coreplugin(plugin)
self.plugin = MetaPluginV2(configfile=None)
self.plugin = meta_neutron_plugin.MetaPluginV2(configfile=None)
def _fake_network(self, flavor):
data = {'network': {'name': flavor,
@ -311,7 +309,7 @@ class MetaNeutronPluginV2Test(base.BaseTestCase):
self.plugin.delete_router(self.context, router_ret1['id'])
self.plugin.delete_router(self.context, router_ret2['id'])
with testtools.ExpectedException(FlavorNotFound):
with testtools.ExpectedException(meta_neutron_plugin.FlavorNotFound):
self.plugin.get_router(self.context, router_ret1['id'])
def test_extension_method(self):
@ -333,7 +331,7 @@ class MetaNeutronPluginV2Test(base.BaseTestCase):
'add_network_flavor_binding',
side_effect=Exception):
network = self._fake_network('fake1')
self.assertRaises(FaildToAddFlavorBinding,
self.assertRaises(meta_neutron_plugin.FaildToAddFlavorBinding,
self.plugin.create_network,
self.context,
network)
@ -345,7 +343,7 @@ class MetaNeutronPluginV2Test(base.BaseTestCase):
'add_router_flavor_binding',
side_effect=Exception):
router = self._fake_router('fake1')
self.assertRaises(FaildToAddFlavorBinding,
self.assertRaises(meta_neutron_plugin.FaildToAddFlavorBinding,
self.plugin.create_router,
self.context,
router)
@ -383,7 +381,7 @@ class MetaNeutronPluginV2TestRpcFlavor(base.BaseTestCase):
def test_rpc_flavor(self):
setup_metaplugin_conf()
cfg.CONF.set_override('rpc_flavor', 'fake1', 'META')
self.plugin = MetaPluginV2()
self.plugin = meta_neutron_plugin.MetaPluginV2()
self.assertEqual(topics.PLUGIN, 'q-plugin')
ret = self.plugin.rpc_workers_supported()
self.assertFalse(ret)
@ -392,13 +390,13 @@ class MetaNeutronPluginV2TestRpcFlavor(base.BaseTestCase):
setup_metaplugin_conf()
cfg.CONF.set_override('rpc_flavor', 'fake-fake', 'META')
self.assertRaises(exc.Invalid,
MetaPluginV2)
meta_neutron_plugin.MetaPluginV2)
self.assertEqual(topics.PLUGIN, 'q-plugin')
def test_rpc_flavor_multiple_rpc_workers(self):
setup_metaplugin_conf()
cfg.CONF.set_override('rpc_flavor', 'fake2', 'META')
self.plugin = MetaPluginV2()
self.plugin = meta_neutron_plugin.MetaPluginV2()
self.assertEqual(topics.PLUGIN, 'q-plugin')
ret = self.plugin.rpc_workers_supported()
self.assertTrue(ret)

View File

@ -22,7 +22,7 @@ from neutron.api.v2 import base
from neutron.common import constants as n_const
from neutron import context
from neutron.extensions import portbindings
from neutron.manager import NeutronManager
from neutron import manager
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2 import config as ml2_config
@ -274,7 +274,7 @@ class TestCiscoPortsV2(CiscoML2MechanismTestCase,
with mock.patch('__builtin__.hasattr',
new=fakehasattr):
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_port
with mock.patch.object(plugin_obj,
'create_port') as patched_plugin:
@ -308,7 +308,7 @@ class TestCiscoPortsV2(CiscoML2MechanismTestCase,
self.skipTest("Plugin does not support native bulk port create")
ctx = context.get_admin_context()
with self.network() as net:
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_port
with mock.patch.object(plugin_obj,
'create_port') as patched_plugin:
@ -605,7 +605,7 @@ class TestCiscoNetworksV2(CiscoML2MechanismTestCase,
return False
return real_has_attr(item, attr)
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_network
#ensures the API choose the emulation code path
with mock.patch('__builtin__.hasattr',
@ -627,7 +627,7 @@ class TestCiscoNetworksV2(CiscoML2MechanismTestCase,
def test_create_networks_bulk_native_plugin_failure(self):
if self._skip_native_bulk:
self.skipTest("Plugin does not support native bulk network create")
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_network
with mock.patch.object(plugin_obj,
'create_network') as patched_plugin:
@ -659,7 +659,7 @@ class TestCiscoSubnetsV2(CiscoML2MechanismTestCase,
with mock.patch('__builtin__.hasattr',
new=fakehasattr):
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_subnet
with mock.patch.object(plugin_obj,
'create_subnet') as patched_plugin:
@ -682,7 +682,7 @@ class TestCiscoSubnetsV2(CiscoML2MechanismTestCase,
def test_create_subnets_bulk_native_plugin_failure(self):
if self._skip_native_bulk:
self.skipTest("Plugin does not support native bulk subnet create")
plugin_obj = NeutronManager.get_plugin()
plugin_obj = manager.NeutronManager.get_plugin()
orig = plugin_obj.create_subnet
with mock.patch.object(plugin_obj,
'create_subnet') as patched_plugin:

View File

@ -15,17 +15,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from contextlib import nested
import contextlib
import mock
import webob.exc
from neutron.extensions import portbindings
from neutron.manager import NeutronManager
from neutron import manager
from neutron.plugins.bigswitch import servermanager
from neutron.plugins.ml2 import config as ml2_config
from neutron.plugins.ml2.drivers import type_vlan as vlan_config
import neutron.tests.unit.bigswitch.test_restproxy_plugin as trp
from neutron.tests.unit.ml2.test_ml2_plugin import PLUGIN_NAME as ML2_PLUGIN
from neutron.tests.unit.ml2 import test_ml2_plugin
from neutron.tests.unit import test_db_plugin
PHYS_NET = 'physnet1'
@ -53,7 +53,7 @@ class TestBigSwitchMechDriverBase(trp.BigSwitchProxyPluginV2TestCase):
[phys_vrange],
'ml2_type_vlan')
super(TestBigSwitchMechDriverBase,
self).setUp(ML2_PLUGIN)
self).setUp(test_ml2_plugin.PLUGIN_NAME)
class TestBigSwitchMechDriverNetworksV2(test_db_plugin.TestNetworksV2,
@ -90,7 +90,7 @@ class TestBigSwitchMechDriverPortsV2(test_db_plugin.TestPortsV2,
def test_create404_triggers_background_sync(self):
# allow the async background thread to run for this test
self.spawn_p.stop()
with nested(
with contextlib.nested(
mock.patch(SERVER_POOL + '.rest_create_port',
side_effect=servermanager.RemoteRestError(
reason=servermanager.NXNETWORK, status=404)),
@ -98,7 +98,7 @@ class TestBigSwitchMechDriverPortsV2(test_db_plugin.TestPortsV2,
self.port(**{'device_id': 'devid', 'binding:host_id': 'host'})
) as (mock_http, mock_send_all, p):
# wait for thread to finish
mm = NeutronManager.get_plugin().mechanism_manager
mm = manager.NeutronManager.get_plugin().mechanism_manager
bigdriver = mm.mech_drivers['bigswitch'].obj
bigdriver.evpool.waitall()
mock_send_all.assert_has_calls([
@ -111,7 +111,7 @@ class TestBigSwitchMechDriverPortsV2(test_db_plugin.TestPortsV2,
self.spawn_p.start()
def test_backend_request_contents(self):
with nested(
with contextlib.nested(
mock.patch(SERVER_POOL + '.rest_create_port'),
self.port(**{'device_id': 'devid', 'binding:host_id': 'host'})
) as (mock_rest, p):

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves import xrange
from six import moves
import testtools
from testtools import matchers
@ -138,7 +138,7 @@ class GreTypeTest(base.BaseTestCase):
def test_allocate_tenant_segment(self):
tunnel_ids = set()
for x in xrange(TUN_MIN, TUN_MAX + 1):
for x in moves.xrange(TUN_MIN, TUN_MAX + 1):
segment = self.driver.allocate_tenant_segment(self.session)
self.assertThat(segment[api.SEGMENTATION_ID],
matchers.GreaterThan(TUN_MIN - 1))

View File

@ -15,7 +15,7 @@
# @author: Kyle Mestery, Cisco Systems, Inc.
from oslo.config import cfg
from six.moves import xrange
from six import moves
import testtools
from testtools import matchers
@ -146,7 +146,7 @@ class VxlanTypeTest(base.BaseTestCase):
def test_allocate_tenant_segment(self):
tunnel_ids = set()
for x in xrange(TUN_MIN, TUN_MAX + 1):
for x in moves.xrange(TUN_MIN, TUN_MAX + 1):
segment = self.driver.allocate_tenant_segment(self.session)
self.assertThat(segment[api.SEGMENTATION_ID],
matchers.GreaterThan(TUN_MIN - 1))

View File

@ -16,7 +16,7 @@
import mock
from oslo.config import cfg
from neutron.plugins.mlnx.common.comm_utils import RetryDecorator
from neutron.plugins.mlnx.common import comm_utils
from neutron.plugins.mlnx.common import config # noqa
from neutron.plugins.mlnx.common import exceptions
from neutron.tests import base
@ -29,14 +29,15 @@ class WrongException(Exception):
class TestRetryDecorator(base.BaseTestCase):
def setUp(self):
super(TestRetryDecorator, self).setUp()
self.sleep_fn_p = mock.patch.object(RetryDecorator, 'sleep_fn')