Merge "Fix H302 violations in unit tests"
This commit is contained in:
commit
b145624aae
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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),
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
|
@ -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()
|
||||
):
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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):
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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')
|
||||
self.sleep_fn_p = mock.patch.object(comm_utils.RetryDecorator,
|
||||
'sleep_fn')
|
||||
self.sleep_fn = self.sleep_fn_p.start()
|
||||
|
||||
def test_no_retry_required(self):
|
||||
self.counter = 0
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout, interval=2,
|
||||
retries=3, backoff_rate=2)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout, interval=2,
|
||||
retries=3, backoff_rate=2)
|
||||
def succeeds():
|
||||
self.counter += 1
|
||||
return 'success'
|
||||
@ -52,8 +53,8 @@ class TestRetryDecorator(base.BaseTestCase):
|
||||
backoff_rate = 2
|
||||
retries = 0
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
def always_fails():
|
||||
self.counter += 1
|
||||
raise exceptions.RequestTimeout()
|
||||
@ -68,8 +69,8 @@ class TestRetryDecorator(base.BaseTestCase):
|
||||
backoff_rate = 2
|
||||
retries = 3
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
def fails_once():
|
||||
self.counter += 1
|
||||
if self.counter < 2:
|
||||
@ -89,8 +90,8 @@ class TestRetryDecorator(base.BaseTestCase):
|
||||
interval = 2
|
||||
backoff_rate = 4
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout, interval,
|
||||
retries, backoff_rate)
|
||||
def always_fails():
|
||||
self.counter += 1
|
||||
raise exceptions.RequestTimeout()
|
||||
@ -109,7 +110,7 @@ class TestRetryDecorator(base.BaseTestCase):
|
||||
def test_limit_is_reached_with_conf(self):
|
||||
self.counter = 0
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout)
|
||||
def always_fails():
|
||||
self.counter += 1
|
||||
raise exceptions.RequestTimeout()
|
||||
@ -130,7 +131,7 @@ class TestRetryDecorator(base.BaseTestCase):
|
||||
|
||||
def test_wrong_exception_no_retry(self):
|
||||
|
||||
@RetryDecorator(exceptions.RequestTimeout)
|
||||
@comm_utils.RetryDecorator(exceptions.RequestTimeout)
|
||||
def raise_unexpected_error():
|
||||
raise WrongException("wrong exception")
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
from testtools import matchers
|
||||
|
||||
from neutron.common import exceptions as n_exc
|
||||
@ -107,7 +107,7 @@ class SegmentationIdAllocationTest(base.BaseTestCase):
|
||||
|
||||
def test_segmentationId_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 = mlnx_db.reserve_network(self.session)
|
||||
self.assertEqual(physical_network, PHYS_NET)
|
||||
self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1))
|
||||
|
@ -19,7 +19,7 @@ from oslo.config import cfg
|
||||
#NOTE this import loads tests required options
|
||||
from neutron.plugins.mlnx.common import config # noqa
|
||||
from neutron.plugins.mlnx.common import constants
|
||||
from neutron.plugins.mlnx.mlnx_plugin import MellanoxEswitchPlugin
|
||||
from neutron.plugins.mlnx import mlnx_plugin
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class TestMlnxPluginConfig(base.BaseTestCase):
|
||||
|
||||
def _create_mlnx_plugin(self):
|
||||
with mock.patch('neutron.plugins.mlnx.db.mlnx_db_v2'):
|
||||
return MellanoxEswitchPlugin()
|
||||
return mlnx_plugin.MellanoxEswitchPlugin()
|
||||
|
||||
def _assert_expected_config(self):
|
||||
plugin = self._create_mlnx_plugin()
|
||||
|
@ -21,7 +21,7 @@ import time
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
import testtools
|
||||
|
||||
from neutron.agent.linux import ovs_lib
|
||||
@ -154,8 +154,8 @@ class TestNecAgent(TestNecAgentBase):
|
||||
# Ensure vif_ports_scenario is longer than DAEMON_LOOP_COUNT
|
||||
if len(self.vif_ports_scenario) < DAEMON_LOOP_COUNT:
|
||||
self.vif_ports_scenario.extend(
|
||||
[] for _i in xrange(DAEMON_LOOP_COUNT -
|
||||
len(self.vif_ports_scenario)))
|
||||
[] for _i in moves.xrange(DAEMON_LOOP_COUNT -
|
||||
len(self.vif_ports_scenario)))
|
||||
|
||||
with contextlib.nested(
|
||||
mock.patch.object(time, 'sleep', side_effect=sleep_mock),
|
||||
|
@ -20,7 +20,7 @@ import mock
|
||||
import webob.exc
|
||||
|
||||
from neutron.common import constants
|
||||
from neutron.common.test_lib import test_config
|
||||
from neutron.common import test_lib
|
||||
from neutron.common import topics
|
||||
from neutron import context
|
||||
from neutron.db import db_base_plugin_v2
|
||||
@ -52,16 +52,16 @@ class NecPluginV2TestCaseBase(object):
|
||||
self.nec_ini_file = self.useFixture(fixtures.TempDir()).join("nec.ini")
|
||||
with open(self.nec_ini_file, 'w') as f:
|
||||
f.write(self._nec_ini)
|
||||
if 'config_files' in test_config.keys():
|
||||
for c in test_config['config_files']:
|
||||
if 'config_files' in test_lib.test_config.keys():
|
||||
for c in test_lib.test_config['config_files']:
|
||||
if c.rfind("/nec.ini") > -1:
|
||||
test_config['config_files'].remove(c)
|
||||
test_config['config_files'].append(self.nec_ini_file)
|
||||
test_lib.test_config['config_files'].remove(c)
|
||||
test_lib.test_config['config_files'].append(self.nec_ini_file)
|
||||
else:
|
||||
test_config['config_files'] = [self.nec_ini_file]
|
||||
test_lib.test_config['config_files'] = [self.nec_ini_file]
|
||||
|
||||
def _clean_nec_ini(self):
|
||||
test_config['config_files'].remove(self.nec_ini_file)
|
||||
test_lib.test_config['config_files'].remove(self.nec_ini_file)
|
||||
os.remove(self.nec_ini_file)
|
||||
self.nec_ini_file = None
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
import random
|
||||
|
||||
import mock
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.nec.common import ofc_client
|
||||
@ -48,7 +48,8 @@ class TremaDriverTestBase(base.BaseTestCase):
|
||||
tenant_id = uuidutils.generate_uuid()
|
||||
network_id = uuidutils.generate_uuid()
|
||||
port_id = uuidutils.generate_uuid()
|
||||
mac = ':'.join(['%x' % random.randint(0, 255) for i in xrange(6)])
|
||||
mac = ':'.join(['%x' % random.randint(0, 255)
|
||||
for i in moves.xrange(6)])
|
||||
portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789",
|
||||
port_no=1234, vlan_id=321,
|
||||
mac=mac)
|
||||
@ -186,7 +187,8 @@ class TremaFilterDriverTest(TremaDriverTestBase):
|
||||
def _test_create_filter(self, filter_dict=None, filter_post=None,
|
||||
filter_wildcards=None, no_portinfo=False):
|
||||
t, n, p = self.get_ofc_item_random_params()
|
||||
src_mac = ':'.join(['%x' % random.randint(0, 255) for i in xrange(6)])
|
||||
src_mac = ':'.join(['%x' % random.randint(0, 255)
|
||||
for i in moves.xrange(6)])
|
||||
if filter_wildcards is None:
|
||||
filter_wildcards = []
|
||||
|
||||
@ -286,7 +288,8 @@ class TremaFilterDriverTest(TremaDriverTestBase):
|
||||
filter_wildcards=['dl_src'])
|
||||
|
||||
def test_create_filter_dst_mac(self):
|
||||
dst_mac = ':'.join(['%x' % random.randint(0, 255) for i in xrange(6)])
|
||||
dst_mac = ':'.join(['%x' % random.randint(0, 255)
|
||||
for i in moves.xrange(6)])
|
||||
self._test_create_filter(filter_dict={'dst_mac': dst_mac},
|
||||
filter_post={'dl_dst': dst_mac})
|
||||
|
||||
|
@ -23,7 +23,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.plugins.oneconvergence import plugin as nvsd_plugin
|
||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
||||
from neutron.tests.unit import test_db_plugin as test_plugin
|
||||
@ -97,7 +97,7 @@ class TestOneConvergencePluginPortsV2(test_plugin.TestPortsV2,
|
||||
self.skipTest("NVSD Plugin does not support IPV6.")
|
||||
|
||||
def test_port_vif_details(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
with self.port(name='name') as port1:
|
||||
ctx = context.get_admin_context()
|
||||
port = plugin.get_port(ctx, port1['port']['id'])
|
||||
@ -106,7 +106,7 @@ class TestOneConvergencePluginPortsV2(test_plugin.TestPortsV2,
|
||||
|
||||
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)
|
||||
|
@ -39,8 +39,8 @@ from neutron.tests.unit import test_agent_ext_plugin
|
||||
from neutron.tests.unit import test_db_plugin as test_plugin
|
||||
from neutron.tests.unit import test_extensions
|
||||
from neutron.tests.unit import test_l3_plugin
|
||||
from neutron.tests.unit.testlib_api import create_request
|
||||
from neutron.wsgi import Serializer
|
||||
from neutron.tests.unit import testlib_api
|
||||
from neutron import wsgi
|
||||
|
||||
L3_HOSTA = 'hosta'
|
||||
DHCP_HOSTA = 'hosta'
|
||||
@ -63,12 +63,12 @@ class AgentSchedulerTestMixIn(object):
|
||||
content_type = 'application/%s' % self.fmt
|
||||
body = None
|
||||
if data is not None: # empty dict is valid
|
||||
body = Serializer().serialize(data, content_type)
|
||||
body = wsgi.Serializer().serialize(data, content_type)
|
||||
if admin_context:
|
||||
return create_request(
|
||||
return testlib_api.create_request(
|
||||
path, body, content_type, method, query_string=query_string)
|
||||
else:
|
||||
return create_request(
|
||||
return testlib_api.create_request(
|
||||
path, body, content_type, method, query_string=query_string,
|
||||
context=context.Context('', 'tenant_id'))
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
@ -126,7 +126,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, vlan_id = ovs_db_v2.reserve_vlan(self.session)
|
||||
self.assertEqual(physical_network, PHYS_NET)
|
||||
self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1))
|
||||
@ -178,7 +178,7 @@ class VlanAllocationsTest(base.BaseTestCase):
|
||||
|
||||
def test_sync_with_allocated_false(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 = ovs_db_v2.reserve_vlan(self.session)
|
||||
self.assertEqual(physical_network, PHYS_NET)
|
||||
self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1))
|
||||
@ -223,7 +223,7 @@ class TunnelAllocationsTest(base.BaseTestCase):
|
||||
|
||||
def test_tunnel_pool(self):
|
||||
tunnel_ids = set()
|
||||
for x in xrange(TUN_MIN, TUN_MAX + 1):
|
||||
for x in moves.xrange(TUN_MIN, TUN_MAX + 1):
|
||||
tunnel_id = ovs_db_v2.reserve_tunnel(self.session)
|
||||
self.assertThat(tunnel_id, matchers.GreaterThan(TUN_MIN - 1))
|
||||
self.assertThat(tunnel_id, matchers.LessThan(TUN_MAX + 1))
|
||||
|
@ -23,7 +23,7 @@ import mock
|
||||
|
||||
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 importutils
|
||||
from neutron.plugins.plumgrid.plumgrid_plugin import plumgrid_plugin
|
||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
||||
@ -111,7 +111,7 @@ class TestPlumgridNetworkAdminState(PLUMgridPluginV2TestCase):
|
||||
network = {'network': {'name': name,
|
||||
'admin_state_up': admin_status_up,
|
||||
'tenant_id': tenant_id}}
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
self.assertEqual(plugin._network_admin_state(network), network)
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ class TestPlumgridAllocationPool(PLUMgridPluginV2TestCase):
|
||||
allocation_pool = [{"start": '10.0.0.2',
|
||||
"end": '10.0.0.253'}]
|
||||
context = None
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
pool = plugin._allocate_pools_for_subnet(context, subnet)
|
||||
self.assertEqual(allocation_pool, pool)
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from contextlib import nested
|
||||
import contextlib
|
||||
import httplib
|
||||
|
||||
import mock
|
||||
@ -226,7 +226,7 @@ class TestOVSNeutronOFPRyuAgent(RyuAgentTestCase):
|
||||
|
||||
class TestRyuPluginApi(RyuAgentTestCase):
|
||||
def test_get_ofp_rest_api_addr(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.RyuPluginApi.make_msg',
|
||||
return_value='msg'),
|
||||
mock.patch(self._AGENT_NAME + '.RyuPluginApi.call',
|
||||
@ -313,7 +313,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(ofport, 1)
|
||||
|
||||
def test_get_ports(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_port_name_list',
|
||||
return_value=['p1', 'p2']),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -338,7 +338,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(ports, ['port1', 'port2'])
|
||||
|
||||
def test_get_ports_empty(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_port_name_list',
|
||||
return_value=[]),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -356,7 +356,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(len(ports), 0)
|
||||
|
||||
def test_get_ports_invalid_ofport(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_port_name_list',
|
||||
return_value=['p1', 'p2']),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -380,7 +380,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(ports, ['port1'])
|
||||
|
||||
def test_get_ports_invalid_port(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_port_name_list',
|
||||
return_value=['p1', 'p2']),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -405,7 +405,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(ports, ['port2'])
|
||||
|
||||
def test_get_external_port(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.db_get_map',
|
||||
side_effect=[None, {'opts': 'opts_val'}]),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -428,7 +428,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertEqual(vifport, mock_vif.return_value)
|
||||
|
||||
def test_get_external_port_vmport(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.db_get_map',
|
||||
side_effect=[{'extids': 'extid_val'},
|
||||
{'opts': 'opts_val'}]),
|
||||
@ -447,7 +447,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertIsNone(vifport)
|
||||
|
||||
def test_get_external_port_tunnel(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.db_get_map',
|
||||
side_effect=[None, {'remote_ip': '0.0.0.0'}]),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge.get_ofport',
|
||||
@ -466,7 +466,7 @@ class TestOVSBridge(RyuAgentTestCase):
|
||||
self.assertIsNone(vifport)
|
||||
|
||||
def test_get_external_ports(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge._get_external_port'),
|
||||
mock.patch(self._AGENT_NAME + '.OVSBridge._get_ports')
|
||||
) as (mock_extport, mock_port):
|
||||
@ -514,7 +514,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
def test_get_ip_ip(self):
|
||||
cfg_attrs = {'CONF.OVS.cfg_ip': '1.2.3.4',
|
||||
'CONF.OVS.cfg_iface': 'eth0'}
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
|
||||
mock.patch(self._AGENT_NAME + '._get_ip_from_nic',
|
||||
return_value='10.0.0.1'),
|
||||
@ -530,7 +530,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
def test_get_ip_nic(self):
|
||||
cfg_attrs = {'CONF.OVS.cfg_ip': None,
|
||||
'CONF.OVS.cfg_iface': 'eth0'}
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
|
||||
mock.patch(self._AGENT_NAME + '._get_ip_from_nic',
|
||||
return_value='10.0.0.1'),
|
||||
@ -548,7 +548,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
def test_get_ip_myip(self):
|
||||
cfg_attrs = {'CONF.OVS.cfg_ip': None,
|
||||
'CONF.OVS.cfg_iface': None}
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
|
||||
mock.patch(self._AGENT_NAME + '._get_ip_from_nic',
|
||||
return_value='10.0.0.1'),
|
||||
@ -566,7 +566,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
def test_get_ip_nic_myip(self):
|
||||
cfg_attrs = {'CONF.OVS.cfg_ip': None,
|
||||
'CONF.OVS.cfg_iface': 'eth0'}
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
|
||||
mock.patch(self._AGENT_NAME + '._get_ip_from_nic',
|
||||
return_value=None),
|
||||
@ -608,7 +608,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
'CONF.OVS.ovsdb_port': 16634,
|
||||
'CONF.AGENT.polling_interval': 2,
|
||||
'CONF.AGENT.root_helper': 'helper'}
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
|
||||
mock.patch(self._AGENT_NAME + '.logging_config'),
|
||||
mock.patch(self._AGENT_NAME + '._get_tunnel_ip',
|
||||
@ -635,7 +635,7 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
|
||||
])
|
||||
|
||||
def test_main_raise(self):
|
||||
with nested(
|
||||
with contextlib.nested(
|
||||
mock.patch(self._AGENT_NAME + '.OVSNeutronOFPRyuAgent',
|
||||
side_effect=httplib.HTTPException('boom')),
|
||||
mock.patch('sys.exit', side_effect=SystemExit(0))
|
||||
|
@ -15,7 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from contextlib import nested
|
||||
import contextlib
|
||||
import operator
|
||||
|
||||
from neutron.db import api as db
|
||||
@ -34,10 +34,9 @@ class RyuDBTest(test_plugin.NeutronDbPluginV2TestCase):
|
||||
def test_key_allocation(self):
|
||||
tunnel_key = db_api_v2.TunnelKey()
|
||||
session = db.get_session()
|
||||
with nested(self.network('network-0'),
|
||||
self.network('network-1')
|
||||
) as (network_0,
|
||||
network_1):
|
||||
with contextlib.nested(self.network('network-0'),
|
||||
self.network('network-1')
|
||||
) as (network_0, network_1):
|
||||
network_id0 = network_0['network']['id']
|
||||
key0 = tunnel_key.allocate(session, network_id0)
|
||||
network_id1 = network_1['network']['id']
|
||||
|
@ -18,7 +18,6 @@
|
||||
# @author: Rajesh Mohan, Rajesh_Mohan3@Dell.com, DELL Inc.
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.agent.common import config as a_cfg
|
||||
@ -125,29 +124,29 @@ class IptablesFwaasTestCase(base.BaseTestCase):
|
||||
ipt_mgr_echain = '%s-%s' % (bname, egress_chain[:11])
|
||||
for router_info_inst in apply_list:
|
||||
v4filter_inst = router_info_inst.iptables_manager.ipv4['filter']
|
||||
calls = [call.ensure_remove_chain('iv4fake-fw-uuid'),
|
||||
call.ensure_remove_chain('ov4fake-fw-uuid'),
|
||||
call.ensure_remove_chain('fwaas-default-policy'),
|
||||
call.add_chain('fwaas-default-policy'),
|
||||
call.add_rule('fwaas-default-policy', '-j DROP'),
|
||||
call.add_chain(ingress_chain),
|
||||
call.add_rule(ingress_chain, invalid_rule),
|
||||
call.add_rule(ingress_chain, est_rule),
|
||||
call.add_chain(egress_chain),
|
||||
call.add_rule(egress_chain, invalid_rule),
|
||||
call.add_rule(egress_chain, est_rule),
|
||||
call.add_rule(ingress_chain, rule1),
|
||||
call.add_rule(egress_chain, rule1),
|
||||
call.add_rule(ingress_chain, rule2),
|
||||
call.add_rule(egress_chain, rule2),
|
||||
call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s' % ipt_mgr_ichain),
|
||||
call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s' % ipt_mgr_echain),
|
||||
call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s-fwaas-defau' % bname),
|
||||
call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s-fwaas-defau' % bname)]
|
||||
calls = [mock.call.ensure_remove_chain('iv4fake-fw-uuid'),
|
||||
mock.call.ensure_remove_chain('ov4fake-fw-uuid'),
|
||||
mock.call.ensure_remove_chain('fwaas-default-policy'),
|
||||
mock.call.add_chain('fwaas-default-policy'),
|
||||
mock.call.add_rule('fwaas-default-policy', '-j DROP'),
|
||||
mock.call.add_chain(ingress_chain),
|
||||
mock.call.add_rule(ingress_chain, invalid_rule),
|
||||
mock.call.add_rule(ingress_chain, est_rule),
|
||||
mock.call.add_chain(egress_chain),
|
||||
mock.call.add_rule(egress_chain, invalid_rule),
|
||||
mock.call.add_rule(egress_chain, est_rule),
|
||||
mock.call.add_rule(ingress_chain, rule1),
|
||||
mock.call.add_rule(egress_chain, rule1),
|
||||
mock.call.add_rule(ingress_chain, rule2),
|
||||
mock.call.add_rule(egress_chain, rule2),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s' % ipt_mgr_ichain),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s' % ipt_mgr_echain),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s-fwaas-defau' % bname),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s-fwaas-defau' % bname)]
|
||||
v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
def test_create_firewall_no_rules(self):
|
||||
@ -161,21 +160,23 @@ class IptablesFwaasTestCase(base.BaseTestCase):
|
||||
for ip_version in (4, 6):
|
||||
ingress_chain = ('iv%s%s' % (ip_version, firewall['id']))
|
||||
egress_chain = ('ov%s%s' % (ip_version, firewall['id']))
|
||||
calls = [call.ensure_remove_chain('iv%sfake-fw-uuid' % ip_version),
|
||||
call.ensure_remove_chain('ov%sfake-fw-uuid' % ip_version),
|
||||
call.ensure_remove_chain('fwaas-default-policy'),
|
||||
call.add_chain('fwaas-default-policy'),
|
||||
call.add_rule('fwaas-default-policy', '-j DROP'),
|
||||
call.add_chain(ingress_chain),
|
||||
call.add_rule(ingress_chain, invalid_rule),
|
||||
call.add_rule(ingress_chain, est_rule),
|
||||
call.add_chain(egress_chain),
|
||||
call.add_rule(egress_chain, invalid_rule),
|
||||
call.add_rule(egress_chain, est_rule),
|
||||
call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s-fwaas-defau' % bname),
|
||||
call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s-fwaas-defau' % bname)]
|
||||
calls = [mock.call.ensure_remove_chain(
|
||||
'iv%sfake-fw-uuid' % ip_version),
|
||||
mock.call.ensure_remove_chain(
|
||||
'ov%sfake-fw-uuid' % ip_version),
|
||||
mock.call.ensure_remove_chain('fwaas-default-policy'),
|
||||
mock.call.add_chain('fwaas-default-policy'),
|
||||
mock.call.add_rule('fwaas-default-policy', '-j DROP'),
|
||||
mock.call.add_chain(ingress_chain),
|
||||
mock.call.add_rule(ingress_chain, invalid_rule),
|
||||
mock.call.add_rule(ingress_chain, est_rule),
|
||||
mock.call.add_chain(egress_chain),
|
||||
mock.call.add_rule(egress_chain, invalid_rule),
|
||||
mock.call.add_rule(egress_chain, est_rule),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-o qr-+ -j %s-fwaas-defau' % bname),
|
||||
mock.call.add_rule('FORWARD',
|
||||
'-i qr-+ -j %s-fwaas-defau' % bname)]
|
||||
if ip_version == 4:
|
||||
v4filter_inst = apply_list[0].iptables_manager.ipv4['filter']
|
||||
v4filter_inst.assert_has_calls(calls)
|
||||
@ -199,9 +200,9 @@ class IptablesFwaasTestCase(base.BaseTestCase):
|
||||
self.firewall.delete_firewall(apply_list, firewall)
|
||||
ingress_chain = 'iv4%s' % firewall['id']
|
||||
egress_chain = 'ov4%s' % firewall['id']
|
||||
calls = [call.ensure_remove_chain(ingress_chain),
|
||||
call.ensure_remove_chain(egress_chain),
|
||||
call.ensure_remove_chain('fwaas-default-policy')]
|
||||
calls = [mock.call.ensure_remove_chain(ingress_chain),
|
||||
mock.call.ensure_remove_chain(egress_chain),
|
||||
mock.call.ensure_remove_chain('fwaas-default-policy')]
|
||||
apply_list[0].iptables_manager.ipv4['filter'].assert_has_calls(calls)
|
||||
|
||||
def test_create_firewall_with_admin_down(self):
|
||||
@ -209,9 +210,9 @@ class IptablesFwaasTestCase(base.BaseTestCase):
|
||||
rule_list = self._fake_rules_v4(FAKE_FW_ID, apply_list)
|
||||
firewall = self._fake_firewall_with_admin_down(rule_list)
|
||||
self.firewall.create_firewall(apply_list, firewall)
|
||||
calls = [call.ensure_remove_chain('iv4fake-fw-uuid'),
|
||||
call.ensure_remove_chain('ov4fake-fw-uuid'),
|
||||
call.ensure_remove_chain('fwaas-default-policy'),
|
||||
call.add_chain('fwaas-default-policy'),
|
||||
call.add_rule('fwaas-default-policy', '-j DROP')]
|
||||
calls = [mock.call.ensure_remove_chain('iv4fake-fw-uuid'),
|
||||
mock.call.ensure_remove_chain('ov4fake-fw-uuid'),
|
||||
mock.call.ensure_remove_chain('fwaas-default-policy'),
|
||||
mock.call.add_chain('fwaas-default-policy'),
|
||||
mock.call.add_rule('fwaas-default-policy', '-j DROP')]
|
||||
apply_list[0].iptables_manager.ipv4['filter'].assert_has_calls(calls)
|
||||
|
@ -23,7 +23,7 @@ from neutron import manager
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.services.loadbalancer.drivers.netscaler import ncc_client
|
||||
from neutron.services.loadbalancer.drivers.netscaler import netscaler_driver
|
||||
from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
|
||||
from neutron.tests.unit.db import loadbalancer
|
||||
|
||||
|
||||
LBAAS_DRIVER_CLASS = ('neutron.services.loadbalancer.drivers'
|
||||
@ -55,7 +55,7 @@ TESTVIP_IP = '10.0.1.100'
|
||||
TESTMEMBER_IP = '10.0.0.5'
|
||||
|
||||
|
||||
class TestLoadBalancerPluginBase(test_db_loadbalancer
|
||||
class TestLoadBalancerPluginBase(loadbalancer.test_db_loadbalancer
|
||||
.LoadBalancerPluginDbTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -19,7 +19,7 @@
|
||||
import contextlib
|
||||
|
||||
import mock
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
from webob import exc
|
||||
|
||||
from neutron import context
|
||||
@ -91,7 +91,7 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase):
|
||||
# add 3 pools and 2 vips directly to DB
|
||||
# to create 2 "ready" devices and one pool without vip
|
||||
pools = []
|
||||
for i in xrange(3):
|
||||
for i in moves.xrange(3):
|
||||
pools.append(ldb.Pool(id=uuidutils.generate_uuid(),
|
||||
subnet_id=self._subnet_id,
|
||||
protocol="HTTP",
|
||||
|
@ -17,7 +17,6 @@
|
||||
import copy
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.services.metering.drivers.iptables import iptables_driver
|
||||
@ -80,13 +79,16 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
'tenant_id': '6c5f5d2a1fa2441e88e35422926f48e8'}]
|
||||
|
||||
self.metering.add_metering_label(None, routers)
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
@ -121,27 +123,34 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
'tenant_id': '6c5f5d2a1fa2441e88e35422926f48e8'}]
|
||||
|
||||
self.metering.add_metering_label(None, routers)
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.add_chain('neutron-meter-l-eeef45da-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-eeef45da-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-eeef45da-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-eeef45da-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-eeef45da-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24 -j RETURN',
|
||||
wrap=False, top=True)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.add_chain('neutron-meter-l-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-eeef45da-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-eeef45da-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24'
|
||||
' -j RETURN',
|
||||
wrap=False, top=True)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
@ -178,25 +187,30 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
|
||||
self.metering.update_metering_label_rules(None, updates)
|
||||
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.empty_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-o qg-6d411f48-ec -d 10.0.0.0/24 -j RETURN',
|
||||
wrap=False, top=True),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 20.0.0.0/24 -j '
|
||||
'neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.empty_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-o qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j RETURN',
|
||||
wrap=False, top=True),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 20.0.0.0/24 -j '
|
||||
'neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
@ -241,26 +255,30 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
'tenant_id': '6c5f5d2a1fa2441e88e35422926f48e8'}]
|
||||
|
||||
self.metering.update_metering_label_rules(None, routers)
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.empty_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.empty_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
@ -283,19 +301,24 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
|
||||
self.metering.add_metering_label(None, routers)
|
||||
self.metering.remove_metering_label(None, routers)
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.remove_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.remove_chain('neutron-meter-r-c5df2fe5-c60', wrap=False)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-7d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.remove_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.remove_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
||||
@ -335,39 +358,51 @@ class IptablesDriverTestCase(base.BaseTestCase):
|
||||
updates[0]['gw_port_id'] = '587b63c1-22a3-40b3-9834-486d1fb215a5'
|
||||
|
||||
self.metering.update_routers(None, updates)
|
||||
calls = [call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
call.add_chain('neutron-meter-l-eeef45da-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-eeef45da-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-eeef45da-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-eeef45da-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-eeef45da-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24 -j RETURN',
|
||||
wrap=False, top=True),
|
||||
call.remove_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.remove_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-l-c5df2fe5-c60', wrap=False),
|
||||
call.add_chain('neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60', wrap=False),
|
||||
call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-587b63c1-22 -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
calls = [mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-6d411f48-ec -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False),
|
||||
mock.call.add_chain('neutron-meter-l-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-eeef45da-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-eeef45da-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-eeef45da-c60',
|
||||
'-i qg-7d411f48-ec -d 20.0.0.0/24'
|
||||
' -j RETURN',
|
||||
wrap=False, top=True),
|
||||
mock.call.remove_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.remove_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_chain('neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-FORWARD', '-j '
|
||||
'neutron-meter-r-c5df2fe5-c60',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-l-c5df2fe5-c60',
|
||||
'',
|
||||
wrap=False),
|
||||
mock.call.add_rule('neutron-meter-r-c5df2fe5-c60',
|
||||
'-i qg-587b63c1-22 -d 10.0.0.0/24'
|
||||
' -j neutron-meter-l-c5df2fe5-c60',
|
||||
wrap=False, top=False)]
|
||||
|
||||
self.v4filter_inst.assert_has_calls(calls)
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from functools import wraps
|
||||
import functools
|
||||
# import httmock
|
||||
import requests
|
||||
from requests import exceptions as r_exc
|
||||
@ -26,10 +26,12 @@ from requests import exceptions as r_exc
|
||||
from neutron.openstack.common import log as logging
|
||||
# TODO(pcm) Remove once httmock package is added to test-requirements. For
|
||||
# now, uncomment and include httmock source to UT
|
||||
from neutron.tests.unit.services.vpn.device_drivers import httmock
|
||||
from neutron.tests.unit.services.vpn import device_drivers
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
httmock = device_drivers.httmock
|
||||
|
||||
|
||||
def repeat(n):
|
||||
"""Decorator to limit the number of times a handler is called.
|
||||
@ -43,7 +45,7 @@ def repeat(n):
|
||||
retries = n
|
||||
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
@functools.wraps(func)
|
||||
def wrapped(*args, **kwargs):
|
||||
if static.retries == 0:
|
||||
return None
|
||||
@ -66,7 +68,7 @@ def filter_request(methods, resource):
|
||||
target_resource = resource
|
||||
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
@functools.wraps(func)
|
||||
def wrapped(*args, **kwargs):
|
||||
if (args[1].method in static.target_methods and
|
||||
static.target_resource in args[0].path):
|
||||
|
@ -27,11 +27,9 @@ from neutron.openstack.common import log as logging
|
||||
from neutron.services.vpn.device_drivers import (
|
||||
cisco_csr_rest_client as csr_client)
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.services.vpn.device_drivers import (
|
||||
cisco_csr_mock as csr_request)
|
||||
from neutron.tests.unit.services.vpn import device_drivers
|
||||
# TODO(pcm) Remove once httmock is available. In the meantime, use
|
||||
# temporary local copy of httmock source to run UT
|
||||
from neutron.tests.unit.services.vpn.device_drivers import httmock
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -42,6 +40,8 @@ if True:
|
||||
|
||||
dummy_policy_id = 'dummy-ipsec-policy-id-name'
|
||||
|
||||
httmock = device_drivers.httmock
|
||||
|
||||
|
||||
# Note: Helper functions to test reuse of IDs.
|
||||
def generate_pre_shared_key_id():
|
||||
@ -67,7 +67,7 @@ class TestCsrLoginRestApi(base.BaseTestCase):
|
||||
|
||||
def test_get_token(self):
|
||||
"""Obtain the token and its expiration time."""
|
||||
with httmock.HTTMock(csr_request.token):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token):
|
||||
self.assertTrue(self.csr.authenticate())
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
self.assertIsNotNone(self.csr.token)
|
||||
@ -75,7 +75,7 @@ class TestCsrLoginRestApi(base.BaseTestCase):
|
||||
def test_unauthorized_token_request(self):
|
||||
"""Negative test of invalid user/password."""
|
||||
self.csr.auth = ('stack', 'bogus')
|
||||
with httmock.HTTMock(csr_request.token_unauthorized):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token_unauthorized):
|
||||
self.assertIsNone(self.csr.authenticate())
|
||||
self.assertEqual(requests.codes.UNAUTHORIZED, self.csr.status)
|
||||
|
||||
@ -83,14 +83,14 @@ class TestCsrLoginRestApi(base.BaseTestCase):
|
||||
"""Negative test of request to non-existent host."""
|
||||
self.csr.host = 'wrong-host'
|
||||
self.csr.token = 'Set by some previously successful access'
|
||||
with httmock.HTTMock(csr_request.token_wrong_host):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token_wrong_host):
|
||||
self.assertIsNone(self.csr.authenticate())
|
||||
self.assertEqual(requests.codes.NOT_FOUND, self.csr.status)
|
||||
self.assertIsNone(self.csr.token)
|
||||
|
||||
def test_timeout_on_token_access(self):
|
||||
"""Negative test of a timeout on a request."""
|
||||
with httmock.HTTMock(csr_request.token_timeout):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token_timeout):
|
||||
self.assertIsNone(self.csr.authenticate())
|
||||
self.assertEqual(requests.codes.REQUEST_TIMEOUT, self.csr.status)
|
||||
self.assertIsNone(self.csr.token)
|
||||
@ -112,7 +112,8 @@ class TestCsrGetRestApi(base.BaseTestCase):
|
||||
that there are two interfaces on the CSR.
|
||||
"""
|
||||
|
||||
with httmock.HTTMock(csr_request.token, csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.normal_get):
|
||||
content = self.csr.get_request('global/host-name')
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
self.assertIn('host-name', content)
|
||||
@ -139,7 +140,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
that there are two interfaces (Ge1 and Ge2) on the CSR.
|
||||
"""
|
||||
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
content = self.csr.post_request(
|
||||
'interfaces/GigabitEthernet1/statistics',
|
||||
payload={'action': 'clear'})
|
||||
@ -153,7 +155,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
|
||||
def test_post_with_location(self):
|
||||
"""Create a user and verify that location returned."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
location = self.csr.post_request(
|
||||
'global/local-users',
|
||||
payload={'username': 'test-user',
|
||||
@ -164,7 +167,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
|
||||
def test_post_missing_required_attribute(self):
|
||||
"""Negative test of POST with missing mandatory info."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
self.csr.post_request('global/local-users',
|
||||
payload={'password': 'pass12345',
|
||||
'privilege': 15})
|
||||
@ -172,7 +176,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
|
||||
def test_post_invalid_attribute(self):
|
||||
"""Negative test of POST with invalid info."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
self.csr.post_request('global/local-users',
|
||||
payload={'username': 'test-user',
|
||||
'password': 'pass12345',
|
||||
@ -185,7 +190,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
Uses the lower level _do_request() API to just perform the POST and
|
||||
obtain the response, without any error processing.
|
||||
"""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
location = self.csr._do_request(
|
||||
'POST',
|
||||
'global/local-users',
|
||||
@ -195,8 +201,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
more_headers=csr_client.HEADER_CONTENT_TYPE_JSON)
|
||||
self.assertEqual(requests.codes.CREATED, self.csr.status)
|
||||
self.assertIn('global/local-users/test-user', location)
|
||||
with httmock.HTTMock(csr_request.token,
|
||||
csr_request.post_change_attempt):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_change_attempt):
|
||||
self.csr._do_request(
|
||||
'POST',
|
||||
'global/local-users',
|
||||
@ -210,7 +216,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
|
||||
def test_post_changing_value(self):
|
||||
"""Negative test of a POST trying to change a value."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
location = self.csr.post_request(
|
||||
'global/local-users',
|
||||
payload={'username': 'test-user',
|
||||
@ -218,8 +225,8 @@ class TestCsrPostRestApi(base.BaseTestCase):
|
||||
'privilege': 15})
|
||||
self.assertEqual(requests.codes.CREATED, self.csr.status)
|
||||
self.assertIn('global/local-users/test-user', location)
|
||||
with httmock.HTTMock(csr_request.token,
|
||||
csr_request.post_change_attempt):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_change_attempt):
|
||||
content = self.csr.post_request('global/local-users',
|
||||
payload={'username': 'test-user',
|
||||
'password': 'changed',
|
||||
@ -235,7 +242,8 @@ class TestCsrPutRestApi(base.BaseTestCase):
|
||||
"""Test CSR PUT REST API."""
|
||||
|
||||
def _save_resources(self):
|
||||
with httmock.HTTMock(csr_request.token, csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.normal_get):
|
||||
details = self.csr.get_request('global/host-name')
|
||||
if self.csr.status != requests.codes.OK:
|
||||
self.fail("Unable to save original host name")
|
||||
@ -258,7 +266,8 @@ class TestCsrPutRestApi(base.BaseTestCase):
|
||||
|
||||
self.csr.auth = (user, password)
|
||||
self.csr.token = None
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put):
|
||||
payload = {'host-name': self.original_host}
|
||||
self.csr.put_request('global/host-name', payload=payload)
|
||||
if self.csr.status != requests.codes.NO_CONTENT:
|
||||
@ -288,8 +297,9 @@ class TestCsrPutRestApi(base.BaseTestCase):
|
||||
that there are two interfaces on the CSR (Ge1 and Ge2).
|
||||
"""
|
||||
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.normal_get):
|
||||
payload = {'host-name': 'TestHost'}
|
||||
content = self.csr.put_request('global/host-name',
|
||||
payload=payload)
|
||||
@ -308,8 +318,9 @@ class TestCsrPutRestApi(base.BaseTestCase):
|
||||
This was a problem with an earlier version of the CSR image and is
|
||||
here to prevent regression.
|
||||
"""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.normal_get):
|
||||
payload = {'description': u'Changed description',
|
||||
'if-name': self.original_if['if-name'],
|
||||
'ip-address': self.original_if['ip-address'],
|
||||
@ -334,8 +345,9 @@ class TestCsrPutRestApi(base.BaseTestCase):
|
||||
test setup to change the description to a non-empty string to
|
||||
avoid failures in other tests.
|
||||
"""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.normal_get):
|
||||
payload = {'description': '',
|
||||
'if-name': self.original_if['if-name'],
|
||||
'ip-address': self.original_if['ip-address'],
|
||||
@ -370,8 +382,9 @@ class TestCsrDeleteRestApi(base.BaseTestCase):
|
||||
|
||||
def test_delete_requests(self):
|
||||
"""Simple DELETE requests (creating entry first)."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.delete):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.delete):
|
||||
self._make_dummy_user()
|
||||
self.csr.token = None # Force login
|
||||
self.csr.delete_request('global/local-users/dummy')
|
||||
@ -383,7 +396,8 @@ class TestCsrDeleteRestApi(base.BaseTestCase):
|
||||
|
||||
def test_delete_non_existent_entry(self):
|
||||
"""Negative test of trying to delete a non-existent user."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete_unknown):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete_unknown):
|
||||
content = self.csr.delete_request('global/local-users/unknown')
|
||||
self.assertEqual(requests.codes.NOT_FOUND, self.csr.status)
|
||||
expected = {u'error-code': -1,
|
||||
@ -392,8 +406,8 @@ class TestCsrDeleteRestApi(base.BaseTestCase):
|
||||
|
||||
def test_delete_not_allowed(self):
|
||||
"""Negative test of trying to delete the host-name."""
|
||||
with httmock.HTTMock(csr_request.token,
|
||||
csr_request.delete_not_allowed):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete_not_allowed):
|
||||
self.csr.delete_request('global/host-name')
|
||||
self.assertEqual(requests.codes.METHOD_NOT_ALLOWED,
|
||||
self.csr.status)
|
||||
@ -414,14 +428,16 @@ class TestCsrRestApiFailures(base.BaseTestCase):
|
||||
|
||||
def test_request_for_non_existent_resource(self):
|
||||
"""Negative test of non-existent resource on REST request."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
self.csr.post_request('no/such/request')
|
||||
self.assertEqual(requests.codes.NOT_FOUND, self.csr.status)
|
||||
# The result is HTTP 404 message, so no error content to check
|
||||
|
||||
def test_timeout_during_request(self):
|
||||
"""Negative test of timeout during REST request."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.timeout):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.timeout):
|
||||
self.csr._do_request('GET', 'global/host-name')
|
||||
self.assertEqual(requests.codes.REQUEST_TIMEOUT, self.csr.status)
|
||||
|
||||
@ -433,8 +449,9 @@ class TestCsrRestApiFailures(base.BaseTestCase):
|
||||
token by changing it.
|
||||
"""
|
||||
|
||||
with httmock.HTTMock(csr_request.token, csr_request.expired_request,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.expired_request,
|
||||
device_drivers.csr_request.normal_get):
|
||||
self.csr.token = '123' # These are 44 characters, so won't match
|
||||
content = self.csr._do_request('GET', 'global/host-name')
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
@ -444,7 +461,7 @@ class TestCsrRestApiFailures(base.BaseTestCase):
|
||||
def test_failed_to_obtain_token_for_request(self):
|
||||
"""Negative test of unauthorized user for REST request."""
|
||||
self.csr.auth = ('stack', 'bogus')
|
||||
with httmock.HTTMock(csr_request.token_unauthorized):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token_unauthorized):
|
||||
self.csr._do_request('GET', 'global/host-name')
|
||||
self.assertEqual(requests.codes.UNAUTHORIZED, self.csr.status)
|
||||
|
||||
@ -460,8 +477,9 @@ class TestCsrRestIkePolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_delete_ike_policy(self):
|
||||
"""Create and then delete IKE policy."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
policy_id = '2'
|
||||
policy_info = {u'priority-id': u'%s' % policy_id,
|
||||
u'encryption': u'aes256',
|
||||
@ -480,8 +498,9 @@ class TestCsrRestIkePolicyCreate(base.BaseTestCase):
|
||||
expected_policy.update(policy_info)
|
||||
self.assertEqual(expected_policy, content)
|
||||
# Now delete and verify the IKE policy is gone
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
self.csr.delete_ike_policy(policy_id)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
content = self.csr.get_request(location, full_url=True)
|
||||
@ -489,8 +508,9 @@ class TestCsrRestIkePolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_ike_policy_with_defaults(self):
|
||||
"""Create IKE policy using defaults for all optional values."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_defaults):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_defaults):
|
||||
policy_id = '2'
|
||||
policy_info = {u'priority-id': u'%s' % policy_id}
|
||||
location = self.csr.create_ike_policy(policy_info)
|
||||
@ -512,8 +532,9 @@ class TestCsrRestIkePolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_duplicate_ike_policy(self):
|
||||
"""Negative test of trying to create a duplicate IKE policy."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
policy_id = '2'
|
||||
policy_info = {u'priority-id': u'%s' % policy_id,
|
||||
u'encryption': u'aes',
|
||||
@ -523,7 +544,8 @@ class TestCsrRestIkePolicyCreate(base.BaseTestCase):
|
||||
location = self.csr.create_ike_policy(policy_info)
|
||||
self.assertEqual(requests.codes.CREATED, self.csr.status)
|
||||
self.assertIn('vpn-svc/ike/policies/%s' % policy_id, location)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post_duplicate):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_duplicate):
|
||||
location = self.csr.create_ike_policy(policy_info)
|
||||
self.assertEqual(requests.codes.BAD_REQUEST, self.csr.status)
|
||||
expected = {u'error-code': -1,
|
||||
@ -543,8 +565,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_delete_ipsec_policy(self):
|
||||
"""Create and then delete IPSec policy."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
policy_id = '123'
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % policy_id,
|
||||
@ -572,8 +595,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
expected_policy[u'anti-replay-window-size'] = u'Disable'
|
||||
self.assertEqual(expected_policy, content)
|
||||
# Now delete and verify the IPSec policy is gone
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
self.csr.delete_ipsec_policy(policy_id)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
content = self.csr.get_request(location, full_url=True)
|
||||
@ -581,8 +605,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_ipsec_policy_with_defaults(self):
|
||||
"""Create IPSec policy with default for all optional values."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_defaults):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_defaults):
|
||||
policy_id = '123'
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % policy_id,
|
||||
@ -606,8 +631,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_ipsec_policy_with_uuid(self):
|
||||
"""Create IPSec policy using UUID for id."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % dummy_policy_id,
|
||||
u'protection-suite': {
|
||||
@ -637,8 +663,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_ipsec_policy_without_ah(self):
|
||||
"""Create IPSec policy."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_no_ah):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_no_ah):
|
||||
policy_id = '10'
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % policy_id,
|
||||
@ -665,8 +692,8 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_invalid_ipsec_policy_lifetime(self):
|
||||
"""Failure test of IPSec policy with unsupported lifetime."""
|
||||
with httmock.HTTMock(csr_request.token,
|
||||
csr_request.post_bad_lifetime):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_bad_lifetime):
|
||||
policy_id = '123'
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % policy_id,
|
||||
@ -684,8 +711,9 @@ class TestCsrRestIPSecPolicyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_ipsec_policy_with_invalid_name(self):
|
||||
"""Failure test of creating IPSec policy with name too long."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post_bad_name,
|
||||
csr_request.get_defaults):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_bad_name,
|
||||
device_drivers.csr_request.get_defaults):
|
||||
policy_id = 'policy-name-is-too-long-32-chars'
|
||||
policy_info = {
|
||||
u'policy-id': u'%s' % policy_id,
|
||||
@ -705,8 +733,9 @@ class TestCsrRestPreSharedKeyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_delete_pre_shared_key(self):
|
||||
"""Create and then delete a keyring entry for pre-shared key."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
psk_id = '5'
|
||||
psk_info = {u'keyring-name': u'%s' % psk_id,
|
||||
u'pre-shared-key-list': [
|
||||
@ -727,8 +756,9 @@ class TestCsrRestPreSharedKeyCreate(base.BaseTestCase):
|
||||
u'10.10.10.20 255.255.255.0')
|
||||
self.assertEqual(expected_policy, content)
|
||||
# Now delete and verify pre-shared key is gone
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
self.csr.delete_pre_shared_key(psk_id)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
content = self.csr.get_request(location, full_url=True)
|
||||
@ -736,8 +766,9 @@ class TestCsrRestPreSharedKeyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_pre_shared_key_with_fqdn_peer(self):
|
||||
"""Create pre-shared key using FQDN for peer address."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_fqdn):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_fqdn):
|
||||
psk_id = '5'
|
||||
psk_info = {u'keyring-name': u'%s' % psk_id,
|
||||
u'pre-shared-key-list': [
|
||||
@ -757,8 +788,9 @@ class TestCsrRestPreSharedKeyCreate(base.BaseTestCase):
|
||||
|
||||
def test_create_pre_shared_key_with_duplicate_peer_address(self):
|
||||
"""Negative test of creating a second pre-shared key with same peer."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
psk_id = '5'
|
||||
psk_info = {u'keyring-name': u'%s' % psk_id,
|
||||
u'pre-shared-key-list': [
|
||||
@ -769,7 +801,8 @@ class TestCsrRestPreSharedKeyCreate(base.BaseTestCase):
|
||||
location = self.csr.create_pre_shared_key(psk_info)
|
||||
self.assertEqual(requests.codes.CREATED, self.csr.status)
|
||||
self.assertIn('vpn-svc/ike/keyrings/%s' % psk_id, location)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post_duplicate):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_duplicate):
|
||||
psk_id = u'6'
|
||||
another_psk_info = {u'keyring-name': psk_id,
|
||||
u'pre-shared-key-list': [
|
||||
@ -799,7 +832,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
psk_id = generate_pre_shared_key_id()
|
||||
self._remove_resource_for_test(self.csr.delete_pre_shared_key,
|
||||
psk_id)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
psk_info = {u'keyring-name': u'%d' % psk_id,
|
||||
u'pre-shared-key-list': [
|
||||
{u'key': u'super-secret',
|
||||
@ -817,7 +851,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
policy_id = generate_ike_policy_id()
|
||||
self._remove_resource_for_test(self.csr.delete_ike_policy,
|
||||
policy_id)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
policy_info = {u'priority-id': u'%d' % policy_id,
|
||||
u'encryption': u'aes',
|
||||
u'hash': u'sha',
|
||||
@ -834,7 +869,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
policy_id = generate_ipsec_policy_id()
|
||||
self._remove_resource_for_test(self.csr.delete_ipsec_policy,
|
||||
policy_id)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
policy_info = {
|
||||
u'policy-id': u'%d' % policy_id,
|
||||
u'protection-suite': {
|
||||
@ -854,7 +890,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
return policy_id
|
||||
|
||||
def _remove_resource_for_test(self, delete_resource, resource_id):
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete):
|
||||
delete_resource(resource_id)
|
||||
|
||||
def _prepare_for_site_conn_create(self, skip_psk=False, skip_ike=False,
|
||||
@ -876,8 +913,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
def test_create_delete_ipsec_connection(self):
|
||||
"""Create and then delete an IPSec connection."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -903,8 +941,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
expected_connection.update(connection_info)
|
||||
self.assertEqual(expected_connection, content)
|
||||
# Now delete and verify that site-to-site connection is gone
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
# Only delete connection. Cleanup will take care of prerequisites
|
||||
self.csr.delete_ipsec_connection('Tunnel%d' % tunnel_id)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
@ -914,8 +953,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
def test_create_ipsec_connection_with_no_tunnel_subnet(self):
|
||||
"""Create an IPSec connection without an IP address on tunnel."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_unnumbered):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_unnumbered):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -949,8 +989,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create(
|
||||
skip_psk=True)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -985,8 +1026,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create(
|
||||
skip_ike=True)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1016,7 +1058,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
"""Create IPSec connection in admin down state."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
tunnel = u'Tunnel%d' % tunnel_id
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': tunnel,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1038,14 +1081,16 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
u'vpn-interface-name': tunnel,
|
||||
u'line-protocol-state': u'down',
|
||||
u'enabled': False}
|
||||
with httmock.HTTMock(csr_request.put, csr_request.get_admin_down):
|
||||
with httmock.HTTMock(device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.get_admin_down):
|
||||
self.csr.set_ipsec_connection_state(tunnel, admin_up=False)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
content = self.csr.get_request(state_uri, full_url=True)
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
self.assertEqual(expected_state, content)
|
||||
|
||||
with httmock.HTTMock(csr_request.put, csr_request.get_admin_up):
|
||||
with httmock.HTTMock(device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.get_admin_up):
|
||||
self.csr.set_ipsec_connection_state(tunnel, admin_up=True)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
content = self.csr.get_request(state_uri, full_url=True)
|
||||
@ -1057,8 +1102,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
"""Negative test of connection create without IPSec policy."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create(
|
||||
skip_ipsec=True)
|
||||
with httmock.HTTMock(csr_request.token,
|
||||
csr_request.post_missing_ipsec_policy):
|
||||
with httmock.HTTMock(
|
||||
device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_missing_ipsec_policy):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1073,7 +1119,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
self.assertEqual(requests.codes.BAD_REQUEST, self.csr.status)
|
||||
|
||||
def _determine_conflicting_ip(self):
|
||||
with httmock.HTTMock(csr_request.token, csr_request.get_local_ip):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.get_local_ip):
|
||||
details = self.csr.get_request('interfaces/GigabitEthernet3')
|
||||
if self.csr.status != requests.codes.OK:
|
||||
self.fail("Unable to obtain interface GigabitEthernet3's IP")
|
||||
@ -1091,7 +1138,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
|
||||
conflicting_ip = self._determine_conflicting_ip()
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post_bad_ip):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_bad_ip):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1108,8 +1156,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
def test_create_ipsec_connection_with_max_mtu(self):
|
||||
"""Create an IPSec connection with max MTU value."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.get_mtu):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.get_mtu):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1137,7 +1186,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
def test_create_ipsec_connection_with_bad_mtu(self):
|
||||
"""Negative test of connection create with unsupported MTU value."""
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post_bad_mtu):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post_bad_mtu):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel%d' % tunnel_id,
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1154,7 +1204,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
|
||||
def test_status_when_no_tunnels_exist(self):
|
||||
"""Get status, when there are no tunnels."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.get_none):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.get_none):
|
||||
tunnels = self.csr.read_tunnel_statuses()
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
self.assertEqual([], tunnels)
|
||||
@ -1164,8 +1215,9 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
# Create the IPsec site-to-site connection first
|
||||
tunnel_id, ipsec_policy_id = self._prepare_for_site_conn_create()
|
||||
tunnel_id = 123 # Must hard code to work with mock
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
connection_info = {
|
||||
u'vpn-interface-name': u'Tunnel123',
|
||||
u'ipsec-policy-id': u'%d' % ipsec_policy_id,
|
||||
@ -1180,7 +1232,8 @@ class TestCsrRestIPSecConnectionCreate(base.BaseTestCase):
|
||||
self.assertEqual(requests.codes.CREATED, self.csr.status)
|
||||
self.assertIn('vpn-svc/site-to-site/Tunnel%d' % tunnel_id,
|
||||
location)
|
||||
with httmock.HTTMock(csr_request.token, csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.normal_get):
|
||||
tunnels = self.csr.read_tunnel_statuses()
|
||||
self.assertEqual(requests.codes.OK, self.csr.status)
|
||||
self.assertEqual([(u'Tunnel123', u'DOWN-NEGOTIATING'), ], tunnels)
|
||||
@ -1197,7 +1250,8 @@ class TestCsrRestIkeKeepaliveCreate(base.BaseTestCase):
|
||||
"""
|
||||
|
||||
def _save_dpd_info(self):
|
||||
with httmock.HTTMock(csr_request.token, csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.normal_get):
|
||||
details = self.csr.get_request('vpn-svc/ike/keepalive')
|
||||
if self.csr.status == requests.codes.OK:
|
||||
self.dpd = details
|
||||
@ -1206,7 +1260,8 @@ class TestCsrRestIkeKeepaliveCreate(base.BaseTestCase):
|
||||
self.fail("Unable to save original DPD info")
|
||||
|
||||
def _restore_dpd_info(self):
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put):
|
||||
payload = {'interval': self.dpd['interval'],
|
||||
'retry': self.dpd['retry']}
|
||||
self.csr.put_request('vpn-svc/ike/keepalive', payload=payload)
|
||||
@ -1222,8 +1277,9 @@ class TestCsrRestIkeKeepaliveCreate(base.BaseTestCase):
|
||||
|
||||
def test_configure_ike_keepalive(self):
|
||||
"""Set IKE keep-alive (aka Dead Peer Detection) for the CSR."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.put,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.normal_get):
|
||||
keepalive_info = {'interval': 60, 'retry': 4}
|
||||
self.csr.configure_ike_keepalive(keepalive_info)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
@ -1235,8 +1291,10 @@ class TestCsrRestIkeKeepaliveCreate(base.BaseTestCase):
|
||||
|
||||
def test_disable_ike_keepalive(self):
|
||||
"""Disable IKE keep-alive (aka Dead Peer Detection) for the CSR."""
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.put, csr_request.get_not_configured):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.put,
|
||||
device_drivers.csr_request.get_not_configured):
|
||||
keepalive_info = {'interval': 0, 'retry': 4}
|
||||
self.csr.configure_ike_keepalive(keepalive_info)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
@ -1260,8 +1318,9 @@ class TestCsrRestStaticRoute(base.BaseTestCase):
|
||||
cidr = u'10.1.0.0/24'
|
||||
interface = u'GigabitEthernet1'
|
||||
expected_id = '10.1.0.0_24_GigabitEthernet1'
|
||||
with httmock.HTTMock(csr_request.token, csr_request.post,
|
||||
csr_request.normal_get):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.post,
|
||||
device_drivers.csr_request.normal_get):
|
||||
route_info = {u'destination-network': cidr,
|
||||
u'outgoing-interface': interface}
|
||||
location = self.csr.create_static_route(route_info)
|
||||
@ -1277,8 +1336,9 @@ class TestCsrRestStaticRoute(base.BaseTestCase):
|
||||
expected_route.update(route_info)
|
||||
self.assertEqual(expected_route, content)
|
||||
# Now delete and verify that static route is gone
|
||||
with httmock.HTTMock(csr_request.token, csr_request.delete,
|
||||
csr_request.no_such_resource):
|
||||
with httmock.HTTMock(device_drivers.csr_request.token,
|
||||
device_drivers.csr_request.delete,
|
||||
device_drivers.csr_request.no_such_resource):
|
||||
route_id = csr_client.make_route_id(cidr, interface)
|
||||
self.csr.delete_static_route(route_id)
|
||||
self.assertEqual(requests.codes.NO_CONTENT, self.csr.status)
|
||||
|
@ -25,14 +25,14 @@ from webob import exc
|
||||
import webtest
|
||||
|
||||
from neutron.api import api_common
|
||||
from neutron.api.extensions import PluginAwareExtensionManager
|
||||
from neutron.api import extensions
|
||||
from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base as v2_base
|
||||
from neutron.api.v2 import router
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron import context
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common.notifier import api as notifer_api
|
||||
from neutron.openstack.common import policy as common_policy
|
||||
from neutron.openstack.common import uuidutils
|
||||
@ -94,7 +94,7 @@ class APIv2TestBase(base.BaseTestCase):
|
||||
|
||||
plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'
|
||||
# Ensure existing ExtensionManager is not used
|
||||
PluginAwareExtensionManager._instance = None
|
||||
extensions.PluginAwareExtensionManager._instance = None
|
||||
# Create the default configurations
|
||||
self.config_parse()
|
||||
# Update the plugin
|
||||
@ -1122,7 +1122,7 @@ class SubresourceTest(base.BaseTestCase):
|
||||
super(SubresourceTest, self).setUp()
|
||||
|
||||
plugin = 'neutron.tests.unit.test_api_v2.TestSubresourcePlugin'
|
||||
PluginAwareExtensionManager._instance = None
|
||||
extensions.PluginAwareExtensionManager._instance = None
|
||||
|
||||
# Save the global RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
@ -1394,7 +1394,7 @@ class ExtensionTestCase(base.BaseTestCase):
|
||||
plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'
|
||||
|
||||
# Ensure existing ExtensionManager is not used
|
||||
PluginAwareExtensionManager._instance = None
|
||||
extensions.PluginAwareExtensionManager._instance = None
|
||||
|
||||
# Save the global RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
@ -1412,7 +1412,8 @@ class ExtensionTestCase(base.BaseTestCase):
|
||||
self.plugin = self._plugin_patcher.start()
|
||||
|
||||
# Instantiate mock plugin and enable the V2attributes extension
|
||||
NeutronManager.get_plugin().supported_extension_aliases = ["v2attrs"]
|
||||
manager.NeutronManager.get_plugin().supported_extension_aliases = (
|
||||
["v2attrs"])
|
||||
|
||||
api = router.APIRouter()
|
||||
self.api = webtest.TestApp(api)
|
||||
|
@ -25,18 +25,17 @@ import webob.exc
|
||||
|
||||
import neutron
|
||||
from neutron.api import api_common
|
||||
from neutron.api.extensions import PluginAwareExtensionManager
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2.attributes import ATTR_NOT_SPECIFIED
|
||||
from neutron.api.v2.router import APIRouter
|
||||
from neutron.api.v2 import router
|
||||
from neutron.common import constants
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.common.test_lib import test_config
|
||||
from neutron.common import test_lib
|
||||
from neutron import context
|
||||
from neutron.db import api as db
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import models_v2
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import importutils
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import test_extensions
|
||||
@ -73,7 +72,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
super(NeutronDbPluginV2TestCase, self).setUp()
|
||||
cfg.CONF.set_override('notify_nova_on_port_status_changes', False)
|
||||
# Make sure at each test according extensions for the plugin is loaded
|
||||
PluginAwareExtensionManager._instance = None
|
||||
extensions.PluginAwareExtensionManager._instance = None
|
||||
# Save the attributes map in case the plugin will alter it
|
||||
# loading extensions
|
||||
# Note(salvatore-orlando): shallow copy is not good enough in
|
||||
@ -92,14 +91,14 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
# Create the default configurations
|
||||
args = ['--config-file', base.etcdir('neutron.conf.test')]
|
||||
# If test_config specifies some config-file, use it, as well
|
||||
for config_file in test_config.get('config_files', []):
|
||||
for config_file in test_lib.test_config.get('config_files', []):
|
||||
args.extend(['--config-file', config_file])
|
||||
self.config_parse(args=args)
|
||||
# Update the plugin
|
||||
self.setup_coreplugin(plugin)
|
||||
cfg.CONF.set_override(
|
||||
'service_plugins',
|
||||
[test_config.get(key, default)
|
||||
[test_lib.test_config.get(key, default)
|
||||
for key, default in (service_plugins or {}).iteritems()]
|
||||
)
|
||||
|
||||
@ -108,13 +107,13 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
cfg.CONF.set_override('max_subnet_host_routes', 2)
|
||||
cfg.CONF.set_override('allow_pagination', True)
|
||||
cfg.CONF.set_override('allow_sorting', True)
|
||||
self.api = APIRouter()
|
||||
self.api = router.APIRouter()
|
||||
# Set the defualt status
|
||||
self.net_create_status = 'ACTIVE'
|
||||
self.port_create_status = 'ACTIVE'
|
||||
|
||||
def _is_native_bulk_supported():
|
||||
plugin_obj = NeutronManager.get_plugin()
|
||||
plugin_obj = manager.NeutronManager.get_plugin()
|
||||
native_bulk_attr_name = ("_%s__native_bulk_support"
|
||||
% plugin_obj.__class__.__name__)
|
||||
return getattr(plugin_obj, native_bulk_attr_name, False)
|
||||
@ -124,9 +123,9 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
def _is_native_pagination_support():
|
||||
native_pagination_attr_name = (
|
||||
"_%s__native_pagination_support" %
|
||||
NeutronManager.get_plugin().__class__.__name__)
|
||||
manager.NeutronManager.get_plugin().__class__.__name__)
|
||||
return (cfg.CONF.allow_pagination and
|
||||
getattr(NeutronManager.get_plugin(),
|
||||
getattr(manager.NeutronManager.get_plugin(),
|
||||
native_pagination_attr_name, False))
|
||||
|
||||
self._skip_native_pagination = not _is_native_pagination_support()
|
||||
@ -134,9 +133,9 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
def _is_native_sorting_support():
|
||||
native_sorting_attr_name = (
|
||||
"_%s__native_sorting_support" %
|
||||
NeutronManager.get_plugin().__class__.__name__)
|
||||
manager.NeutronManager.get_plugin().__class__.__name__)
|
||||
return (cfg.CONF.allow_sorting and
|
||||
getattr(NeutronManager.get_plugin(),
|
||||
getattr(manager.NeutronManager.get_plugin(),
|
||||
native_sorting_attr_name, False))
|
||||
|
||||
self._skip_native_sorting = not _is_native_sorting_support()
|
||||
@ -309,7 +308,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
data['subnet'][arg] = kwargs[arg]
|
||||
|
||||
if ('gateway_ip' in kwargs and
|
||||
kwargs['gateway_ip'] is not ATTR_NOT_SPECIFIED):
|
||||
kwargs['gateway_ip'] is not attributes.ATTR_NOT_SPECIFIED):
|
||||
data['subnet']['gateway_ip'] = kwargs['gateway_ip']
|
||||
|
||||
subnet_req = self.new_create_request('subnets', data, fmt)
|
||||
@ -525,7 +524,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
|
||||
|
||||
@contextlib.contextmanager
|
||||
def subnet(self, network=None,
|
||||
gateway_ip=ATTR_NOT_SPECIFIED,
|
||||
gateway_ip=attributes.ATTR_NOT_SPECIFIED,
|
||||
cidr='10.0.0.0/24',
|
||||
fmt=None,
|
||||
ip_version=4,
|
||||
@ -888,8 +887,8 @@ class TestPortsV2(NeutronDbPluginV2TestCase):
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
new=fakehasattr):
|
||||
orig = NeutronManager.get_plugin().create_port
|
||||
with mock.patch.object(NeutronManager.get_plugin(),
|
||||
orig = manager.NeutronManager.get_plugin().create_port
|
||||
with mock.patch.object(manager.NeutronManager.get_plugin(),
|
||||
'create_port') as patched_plugin:
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
@ -912,8 +911,8 @@ class TestPortsV2(NeutronDbPluginV2TestCase):
|
||||
self.skipTest("Plugin does not support native bulk port create")
|
||||
ctx = context.get_admin_context()
|
||||
with self.network() as net:
|
||||
orig = NeutronManager._instance.plugin.create_port
|
||||
with mock.patch.object(NeutronManager._instance.plugin,
|
||||
orig = manager.NeutronManager._instance.plugin.create_port
|
||||
with mock.patch.object(manager.NeutronManager._instance.plugin,
|
||||
'create_port') as patched_plugin:
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
@ -1350,7 +1349,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
net_id=net_id,
|
||||
cidr='10.0.0.225/28',
|
||||
ip_version=4,
|
||||
gateway_ip=ATTR_NOT_SPECIFIED)
|
||||
gateway_ip=attributes.ATTR_NOT_SPECIFIED)
|
||||
self.assertEqual(res.status_int, webob.exc.HTTPClientError.code)
|
||||
|
||||
def test_requested_subnet_id_v4_and_v6(self):
|
||||
@ -1358,12 +1357,13 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
# Get a IPv4 and IPv6 address
|
||||
tenant_id = subnet['subnet']['tenant_id']
|
||||
net_id = subnet['subnet']['network_id']
|
||||
res = self._create_subnet(self.fmt,
|
||||
tenant_id=tenant_id,
|
||||
net_id=net_id,
|
||||
cidr='2607:f0d0:1002:51::/124',
|
||||
ip_version=6,
|
||||
gateway_ip=ATTR_NOT_SPECIFIED)
|
||||
res = self._create_subnet(
|
||||
self.fmt,
|
||||
tenant_id=tenant_id,
|
||||
net_id=net_id,
|
||||
cidr='2607:f0d0:1002:51::/124',
|
||||
ip_version=6,
|
||||
gateway_ip=attributes.ATTR_NOT_SPECIFIED)
|
||||
subnet2 = self.deserialize(self.fmt, res)
|
||||
kwargs = {"fixed_ips":
|
||||
[{'subnet_id': subnet['subnet']['id']},
|
||||
@ -1639,7 +1639,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
webob.exc.HTTPClientError.code)
|
||||
|
||||
def test_delete_ports_by_device_id(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
ctx = context.get_admin_context()
|
||||
with self.subnet() as subnet:
|
||||
with contextlib.nested(
|
||||
@ -1685,7 +1685,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
expected_code=webob.exc.HTTPOk.code)
|
||||
|
||||
def test_delete_ports_by_device_id_second_call_failure(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
self._test_delete_ports_by_device_id_second_call_failure(plugin)
|
||||
|
||||
def _test_delete_ports_ignores_port_not_found(self, plugin):
|
||||
@ -1710,7 +1710,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
||||
"deleting some of the same ports.")
|
||||
|
||||
def test_delete_ports_ignores_port_not_found(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
self._test_delete_ports_ignores_port_not_found(plugin)
|
||||
|
||||
|
||||
@ -1798,7 +1798,7 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
|
||||
# must query db to see whether subnet's shared attribute
|
||||
# has been updated or not
|
||||
ctx = context.Context('', '', is_admin=True)
|
||||
subnet_db = NeutronManager.get_plugin()._get_subnet(
|
||||
subnet_db = manager.NeutronManager.get_plugin()._get_subnet(
|
||||
ctx, subnet['subnet']['id'])
|
||||
self.assertEqual(subnet_db['shared'], True)
|
||||
|
||||
@ -1965,11 +1965,11 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
|
||||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
orig = NeutronManager.get_plugin().create_network
|
||||
orig = manager.NeutronManager.get_plugin().create_network
|
||||
#ensures the API choose the emulation code path
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
new=fakehasattr):
|
||||
with mock.patch.object(NeutronManager.get_plugin(),
|
||||
with mock.patch.object(manager.NeutronManager.get_plugin(),
|
||||
'create_network') as patched_plugin:
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
@ -1986,8 +1986,8 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
|
||||
def test_create_networks_bulk_native_plugin_failure(self):
|
||||
if self._skip_native_bulk:
|
||||
self.skipTest("Plugin does not support native bulk network create")
|
||||
orig = NeutronManager.get_plugin().create_network
|
||||
with mock.patch.object(NeutronManager.get_plugin(),
|
||||
orig = manager.NeutronManager.get_plugin().create_network
|
||||
with mock.patch.object(manager.NeutronManager.get_plugin(),
|
||||
'create_network') as patched_plugin:
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
@ -2384,8 +2384,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
new=fakehasattr):
|
||||
orig = NeutronManager.get_plugin().create_subnet
|
||||
with mock.patch.object(NeutronManager.get_plugin(),
|
||||
orig = manager.NeutronManager.get_plugin().create_subnet
|
||||
with mock.patch.object(manager.NeutronManager.get_plugin(),
|
||||
'create_subnet') as patched_plugin:
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
@ -2405,8 +2405,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
def test_create_subnets_bulk_native_plugin_failure(self):
|
||||
if self._skip_native_bulk:
|
||||
self.skipTest("Plugin does not support native bulk subnet create")
|
||||
orig = NeutronManager._instance.plugin.create_subnet
|
||||
with mock.patch.object(NeutronManager._instance.plugin,
|
||||
orig = manager.NeutronManager._instance.plugin.create_subnet
|
||||
with mock.patch.object(manager.NeutronManager._instance.plugin,
|
||||
'create_subnet') as patched_plugin:
|
||||
def side_effect(*args, **kwargs):
|
||||
return self._fail_second_call(patched_plugin, orig,
|
||||
@ -3728,7 +3728,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
'dns_nameservers': ['8.8.8.8'],
|
||||
'host_routes': [{'destination': '135.207.0.0/16',
|
||||
'nexthop': '1.2.3.4'}]}
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
e = self.assertRaises(exception,
|
||||
plugin._validate_subnet,
|
||||
context.get_admin_context(
|
||||
|
@ -23,9 +23,7 @@ from oslo.config import cfg
|
||||
from neutron.agent.common import config
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.debug import commands
|
||||
from neutron.debug.debug_agent import DEVICE_OWNER_COMPUTE_PROBE
|
||||
from neutron.debug.debug_agent import DEVICE_OWNER_NETWORK_PROBE
|
||||
from neutron.debug.debug_agent import NeutronDebugAgent
|
||||
from neutron.debug import debug_agent
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
@ -38,7 +36,7 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestDebugCommands, self).setUp()
|
||||
cfg.CONF.register_opts(interface.OPTS)
|
||||
cfg.CONF.register_opts(NeutronDebugAgent.OPTS)
|
||||
cfg.CONF.register_opts(debug_agent.NeutronDebugAgent.OPTS)
|
||||
cfg.CONF(args=[], project='neutron')
|
||||
config.register_interface_driver_opts_helper(cfg.CONF)
|
||||
config.register_use_namespaces_opts_helper(cfg.CONF)
|
||||
@ -102,14 +100,14 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
self.client = client_inst
|
||||
mock_std = mock.Mock()
|
||||
self.app = MyApp(mock_std)
|
||||
self.app.debug_agent = NeutronDebugAgent(cfg.CONF,
|
||||
client_inst,
|
||||
mock_driver)
|
||||
self.app.debug_agent = debug_agent.NeutronDebugAgent(cfg.CONF,
|
||||
client_inst,
|
||||
mock_driver)
|
||||
|
||||
def _test_create_probe(self, device_owner):
|
||||
cmd = commands.CreateProbe(self.app, None)
|
||||
cmd_parser = cmd.get_parser('create_probe')
|
||||
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||
if device_owner == debug_agent.DEVICE_OWNER_COMPUTE_PROBE:
|
||||
args = ['fake_net', '--device-owner', 'compute']
|
||||
else:
|
||||
args = ['fake_net']
|
||||
@ -141,10 +139,10 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
)])
|
||||
|
||||
def test_create_network_probe(self):
|
||||
self._test_create_probe(DEVICE_OWNER_NETWORK_PROBE)
|
||||
self._test_create_probe(debug_agent.DEVICE_OWNER_NETWORK_PROBE)
|
||||
|
||||
def test_create_nova_probe(self):
|
||||
self._test_create_probe(DEVICE_OWNER_COMPUTE_PROBE)
|
||||
self._test_create_probe(debug_agent.DEVICE_OWNER_COMPUTE_PROBE)
|
||||
|
||||
def _test_create_probe_external(self, device_owner):
|
||||
fake_network = {'network': {'id': 'fake_net',
|
||||
@ -154,7 +152,7 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
self.client.show_network.return_value = fake_network
|
||||
cmd = commands.CreateProbe(self.app, None)
|
||||
cmd_parser = cmd.get_parser('create_probe')
|
||||
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||
if device_owner == debug_agent.DEVICE_OWNER_COMPUTE_PROBE:
|
||||
args = ['fake_net', '--device-owner', 'compute']
|
||||
else:
|
||||
args = ['fake_net']
|
||||
@ -186,10 +184,12 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
)])
|
||||
|
||||
def test_create_network_probe_external(self):
|
||||
self._test_create_probe_external(DEVICE_OWNER_NETWORK_PROBE)
|
||||
self._test_create_probe_external(
|
||||
debug_agent.DEVICE_OWNER_NETWORK_PROBE)
|
||||
|
||||
def test_create_nova_probe_external(self):
|
||||
self._test_create_probe_external(DEVICE_OWNER_COMPUTE_PROBE)
|
||||
self._test_create_probe_external(
|
||||
debug_agent.DEVICE_OWNER_COMPUTE_PROBE)
|
||||
|
||||
def test_delete_probe(self):
|
||||
cmd = commands.DeleteProbe(self.app, None)
|
||||
@ -250,8 +250,9 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
self.client.assert_has_calls(
|
||||
[mock.call.list_ports(device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE])])
|
||||
[mock.call.list_ports(
|
||||
device_owner=[debug_agent.DEVICE_OWNER_NETWORK_PROBE,
|
||||
debug_agent.DEVICE_OWNER_COMPUTE_PROBE])])
|
||||
|
||||
def test_exec_command(self):
|
||||
cmd = commands.ExecProbe(self.app, None)
|
||||
@ -282,9 +283,10 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
cmd.run(parsed_args)
|
||||
namespace = 'qprobe-fake_port'
|
||||
self.client.assert_has_calls(
|
||||
[mock.call.list_ports(device_id=socket.gethostname(),
|
||||
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE]),
|
||||
[mock.call.list_ports(
|
||||
device_id=socket.gethostname(),
|
||||
device_owner=[debug_agent.DEVICE_OWNER_NETWORK_PROBE,
|
||||
debug_agent.DEVICE_OWNER_COMPUTE_PROBE]),
|
||||
mock.call.show_port('fake_port'),
|
||||
mock.call.show_network('fake_net'),
|
||||
mock.call.show_subnet('fake_subnet'),
|
||||
@ -312,7 +314,7 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
cmd.run(parsed_args)
|
||||
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
||||
fake_port = {'port':
|
||||
{'device_owner': DEVICE_OWNER_NETWORK_PROBE,
|
||||
{'device_owner': debug_agent.DEVICE_OWNER_NETWORK_PROBE,
|
||||
'admin_state_up': True,
|
||||
'network_id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
@ -340,7 +342,7 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
expected = [mock.call.list_ports(),
|
||||
mock.call.list_ports(
|
||||
network_id='fake_net',
|
||||
device_owner=DEVICE_OWNER_NETWORK_PROBE,
|
||||
device_owner=debug_agent.DEVICE_OWNER_NETWORK_PROBE,
|
||||
device_id=socket.gethostname()),
|
||||
mock.call.show_subnet('fake_subnet'),
|
||||
mock.call.show_port('fake_port')]
|
||||
|
@ -26,7 +26,6 @@ import testtools
|
||||
|
||||
from neutron.agent.common import config
|
||||
from neutron.agent import dhcp_agent
|
||||
from neutron.agent.dhcp_agent import DhcpAgentWithStateReport
|
||||
from neutron.agent.linux import dhcp
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.common import constants as const
|
||||
@ -141,10 +140,10 @@ class TestDhcpAgent(base.BaseTestCase):
|
||||
state_rpc_str = 'neutron.agent.rpc.PluginReportStateAPI'
|
||||
# sync_state is needed for this test
|
||||
cfg.CONF.set_override('report_interval', 1, 'AGENT')
|
||||
with mock.patch.object(DhcpAgentWithStateReport,
|
||||
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
|
||||
'sync_state',
|
||||
autospec=True) as mock_sync_state:
|
||||
with mock.patch.object(DhcpAgentWithStateReport,
|
||||
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
|
||||
'periodic_resync',
|
||||
autospec=True) as mock_periodic_resync:
|
||||
with mock.patch(state_rpc_str) as state_rpc:
|
||||
@ -159,7 +158,8 @@ class TestDhcpAgent(base.BaseTestCase):
|
||||
cfg.CONF.register_opts(dhcp.OPTS)
|
||||
cfg.CONF.register_opts(interface.OPTS)
|
||||
cfg.CONF(project='neutron')
|
||||
agent_mgr = DhcpAgentWithStateReport('testhost')
|
||||
agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
|
||||
'testhost')
|
||||
eventlet.greenthread.sleep(1)
|
||||
agent_mgr.after_start()
|
||||
mock_sync_state.assert_called_once_with(agent_mgr)
|
||||
|
@ -20,7 +20,7 @@ from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import portsecurity_db
|
||||
from neutron.extensions import allowedaddresspairs as addr_pair
|
||||
from neutron.extensions import portsecurity as psec
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
|
||||
DB_PLUGIN_KLASS = ('neutron.tests.unit.test_extension_allowedaddresspairs.'
|
||||
@ -32,7 +32,7 @@ class AllowedAddressPairTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
super(AllowedAddressPairTestCase, self).setUp(plugin)
|
||||
|
||||
# Check if a plugin supports security groups
|
||||
plugin_obj = NeutronManager.get_plugin()
|
||||
plugin_obj = manager.NeutronManager.get_plugin()
|
||||
self._skip_port_security = ('port-security' not in
|
||||
plugin_obj.supported_extension_aliases)
|
||||
|
||||
@ -266,7 +266,7 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
|
||||
update_port = {'port': {psec.PORTSECURITY: False}}
|
||||
# If plugin implements security groups we also need to remove
|
||||
# the security group on port.
|
||||
plugin_obj = NeutronManager.get_plugin()
|
||||
plugin_obj = manager.NeutronManager.get_plugin()
|
||||
if 'security-groups' in plugin_obj.supported_extension_aliases:
|
||||
update_port['port']['security_groups'] = []
|
||||
req = self.new_update_request('ports', update_port,
|
||||
|
@ -25,7 +25,7 @@ from webob import exc
|
||||
from neutron import context
|
||||
from neutron.db import models_v2
|
||||
from neutron.extensions import external_net as external_net
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.tests.unit import test_api_v2
|
||||
@ -105,20 +105,20 @@ class ExtNetDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
query_params='router:external=False')
|
||||
|
||||
def test_get_network_succeeds_without_filter(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
ctx = context.Context(None, None, is_admin=True)
|
||||
result = plugin.get_networks(ctx, filters=None)
|
||||
self.assertEqual(result, [])
|
||||
|
||||
def test_network_filter_hook_admin_context(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
ctx = context.Context(None, None, is_admin=True)
|
||||
model = models_v2.Network
|
||||
conditions = plugin._network_filter_hook(ctx, model, [])
|
||||
self.assertEqual(conditions, [])
|
||||
|
||||
def test_network_filter_hook_nonadmin_context(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
ctx = context.Context('edinson', 'cavani')
|
||||
model = models_v2.Network
|
||||
txt = "externalnetworks.network_id IS NOT NULL"
|
||||
@ -160,7 +160,7 @@ class ExtNetDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
True)
|
||||
|
||||
def test_delete_network_check_disassociated_floatingips(self):
|
||||
with mock.patch.object(NeutronManager,
|
||||
with mock.patch.object(manager.NeutronManager,
|
||||
'get_service_plugins') as srv_plugins:
|
||||
l3_mock = mock.Mock()
|
||||
srv_plugins.return_value = {'L3_ROUTER_NAT': l3_mock}
|
||||
|
@ -28,7 +28,7 @@ from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import router
|
||||
from neutron import context
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron import quota
|
||||
from neutron.tests.unit import test_api_v2
|
||||
@ -77,7 +77,7 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
|
||||
instance = self.plugin.return_value
|
||||
instance.get_networks_count.return_value = 1
|
||||
# Instantiate mock plugin and enable the 'provider' extension
|
||||
NeutronManager.get_plugin().supported_extension_aliases = (
|
||||
manager.NeutronManager.get_plugin().supported_extension_aliases = (
|
||||
["provider"])
|
||||
ext_mgr = ProviderExtensionManager()
|
||||
self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr)
|
||||
|
@ -21,7 +21,7 @@ from neutron.db import portsecurity_db
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.extensions import portsecurity as psec
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
from neutron.tests.unit import test_extension_security_group
|
||||
|
||||
@ -39,7 +39,7 @@ class PortSecurityTestCase(
|
||||
super(PortSecurityTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr)
|
||||
|
||||
# Check if a plugin supports security groups
|
||||
plugin_obj = NeutronManager.get_plugin()
|
||||
plugin_obj = manager.NeutronManager.get_plugin()
|
||||
self._skip_security_group = ('security-group' not in
|
||||
plugin_obj.supported_extension_aliases)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@ from neutron.db import l3_rpc_base
|
||||
from neutron.db import model_base
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import importutils
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.openstack.common.notifier import test_notifier
|
||||
@ -244,7 +244,7 @@ class TestL3NatBasePlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
super(TestL3NatBasePlugin, self).delete_network(context, id)
|
||||
|
||||
def delete_port(self, context, id, l3_port_check=True):
|
||||
plugin = NeutronManager.get_service_plugins().get(
|
||||
plugin = manager.NeutronManager.get_service_plugins().get(
|
||||
service_constants.L3_ROUTER_NAT)
|
||||
if plugin:
|
||||
if l3_port_check:
|
||||
@ -1808,7 +1808,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
|
||||
def _test_notify_op_agent(self, target_func, *args):
|
||||
l3_rpc_agent_api_str = (
|
||||
'neutron.api.rpc.agentnotifiers.l3_rpc_agent_api.L3AgentNotifyAPI')
|
||||
plugin = NeutronManager.get_service_plugins()[
|
||||
plugin = manager.NeutronManager.get_service_plugins()[
|
||||
service_constants.L3_ROUTER_NAT]
|
||||
oldNotify = plugin.l3_rpc_notifier
|
||||
try:
|
||||
@ -1927,7 +1927,7 @@ class L3NatDBIntAgentSchedulingTestCase(L3BaseForIntTests,
|
||||
self.adminContext = context.get_admin_context()
|
||||
|
||||
def _assert_router_on_agent(self, router_id, agent_host):
|
||||
plugin = NeutronManager.get_service_plugins().get(
|
||||
plugin = manager.NeutronManager.get_service_plugins().get(
|
||||
service_constants.L3_ROUTER_NAT)
|
||||
agents = plugin.list_l3_agents_hosting_router(
|
||||
self.adminContext, router_id)['agents']
|
||||
|
@ -22,7 +22,7 @@ from neutron.agent.linux import dhcp
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.extensions.flavor import (FLAVOR_NETWORK)
|
||||
from neutron.extensions import flavor
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.tests import base
|
||||
|
||||
@ -417,7 +417,7 @@ class TestMetaInterfaceDriver(TestBase):
|
||||
self.client_inst = mock.Mock()
|
||||
client_cls.return_value = self.client_inst
|
||||
|
||||
fake_network = {'network': {FLAVOR_NETWORK: 'fake1'}}
|
||||
fake_network = {'network': {flavor.FLAVOR_NETWORK: 'fake1'}}
|
||||
fake_port = {'ports':
|
||||
[{'mac_address':
|
||||
'aa:bb:cc:dd:ee:ffa', 'network_id': 'test'}]}
|
||||
|
@ -21,9 +21,7 @@ import fixtures
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron.manager import validate_post_plugin_load
|
||||
from neutron.manager import validate_pre_plugin_load
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.tests import base
|
||||
@ -57,7 +55,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
cfg.CONF.set_override("service_plugins",
|
||||
["neutron.tests.unit.dummy_plugin."
|
||||
"DummyServicePlugin"])
|
||||
mgr = NeutronManager.get_instance()
|
||||
mgr = manager.NeutronManager.get_instance()
|
||||
plugin = mgr.get_service_plugins()[constants.DUMMY]
|
||||
|
||||
self.assertTrue(
|
||||
@ -68,7 +66,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
def test_service_plugin_by_name_is_loaded(self):
|
||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||
cfg.CONF.set_override("service_plugins", ["dummy"])
|
||||
mgr = NeutronManager.get_instance()
|
||||
mgr = manager.NeutronManager.get_instance()
|
||||
plugin = mgr.get_service_plugins()[constants.DUMMY]
|
||||
|
||||
self.assertTrue(
|
||||
@ -83,19 +81,19 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
"neutron.tests.unit.dummy_plugin."
|
||||
"DummyServicePlugin"])
|
||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||
self.assertRaises(ValueError, NeutronManager.get_instance)
|
||||
self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||
|
||||
def test_multiple_plugins_by_name_specified_for_service_type(self):
|
||||
cfg.CONF.set_override("service_plugins", ["dummy", "dummy"])
|
||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||
self.assertRaises(ValueError, NeutronManager.get_instance)
|
||||
self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||
|
||||
def test_multiple_plugins_mixed_specified_for_service_type(self):
|
||||
cfg.CONF.set_override("service_plugins",
|
||||
["neutron.tests.unit.dummy_plugin."
|
||||
"DummyServicePlugin", "dummy"])
|
||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||
self.assertRaises(ValueError, NeutronManager.get_instance)
|
||||
self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||
|
||||
def test_service_plugin_conflicts_with_core_plugin(self):
|
||||
cfg.CONF.set_override("service_plugins",
|
||||
@ -104,13 +102,13 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
cfg.CONF.set_override("core_plugin",
|
||||
"neutron.tests.unit.test_neutron_manager."
|
||||
"MultiServiceCorePlugin")
|
||||
self.assertRaises(ValueError, NeutronManager.get_instance)
|
||||
self.assertRaises(ValueError, manager.NeutronManager.get_instance)
|
||||
|
||||
def test_core_plugin_supports_services(self):
|
||||
cfg.CONF.set_override("core_plugin",
|
||||
"neutron.tests.unit.test_neutron_manager."
|
||||
"MultiServiceCorePlugin")
|
||||
mgr = NeutronManager.get_instance()
|
||||
mgr = manager.NeutronManager.get_instance()
|
||||
svc_plugins = mgr.get_service_plugins()
|
||||
self.assertEqual(3, len(svc_plugins))
|
||||
self.assertIn(constants.CORE, svc_plugins.keys())
|
||||
@ -121,18 +119,18 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
cfg.CONF.import_opt('dhcp_agents_per_network',
|
||||
'neutron.db.agentschedulers_db')
|
||||
|
||||
self.assertIsNone(validate_post_plugin_load())
|
||||
self.assertIsNone(manager.validate_post_plugin_load())
|
||||
cfg.CONF.set_override('dhcp_agents_per_network', 2)
|
||||
self.assertIsNone(validate_post_plugin_load())
|
||||
self.assertIsNone(manager.validate_post_plugin_load())
|
||||
cfg.CONF.set_override('dhcp_agents_per_network', 0)
|
||||
self.assertIsNotNone(validate_post_plugin_load())
|
||||
self.assertIsNotNone(manager.validate_post_plugin_load())
|
||||
cfg.CONF.set_override('dhcp_agents_per_network', -1)
|
||||
self.assertIsNotNone(validate_post_plugin_load())
|
||||
self.assertIsNotNone(manager.validate_post_plugin_load())
|
||||
|
||||
def test_pre_plugin_validation(self):
|
||||
self.assertIsNotNone(validate_pre_plugin_load())
|
||||
self.assertIsNotNone(manager.validate_pre_plugin_load())
|
||||
cfg.CONF.set_override('core_plugin', 'dummy.plugin')
|
||||
self.assertIsNone(validate_pre_plugin_load())
|
||||
self.assertIsNone(manager.validate_pre_plugin_load())
|
||||
|
||||
def test_manager_gathers_agent_notifiers_from_service_plugins(self):
|
||||
cfg.CONF.set_override("service_plugins",
|
||||
@ -144,5 +142,5 @@ class NeutronManagerTestCase(base.BaseTestCase):
|
||||
expected = {'l3': 'l3_agent_notifier',
|
||||
'dhcp': 'dhcp_agent_notifier',
|
||||
'dummy': 'dummy_agent_notifier'}
|
||||
core_plugin = NeutronManager.get_plugin()
|
||||
core_plugin = manager.NeutronManager.get_plugin()
|
||||
self.assertEqual(expected, core_plugin.agent_notifiers)
|
||||
|
@ -18,7 +18,7 @@
|
||||
import sys
|
||||
|
||||
import mock
|
||||
from six.moves import xrange
|
||||
from six import moves
|
||||
|
||||
from neutron.tests import base
|
||||
from neutron.tests import post_mortem_debug
|
||||
@ -66,7 +66,7 @@ class TestGetIgnoredTraceback(base.BaseTestCase):
|
||||
|
||||
tb = root_tb
|
||||
tracebacks = [tb]
|
||||
for x in xrange(len(ignored_bit_array) - 1):
|
||||
for x in moves.xrange(len(ignored_bit_array) - 1):
|
||||
tb.tb_next = mock.Mock()
|
||||
tb = tb.tb_next
|
||||
tracebacks.append(tb)
|
||||
|
@ -15,11 +15,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from contextlib import contextmanager
|
||||
from contextlib import nested
|
||||
import contextlib
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
from oslo.config import cfg
|
||||
from testtools import matchers
|
||||
import webob.exc
|
||||
@ -35,7 +33,7 @@ from neutron import context
|
||||
from neutron.db import securitygroups_rpc_base as sg_db_rpc
|
||||
from neutron.extensions import allowedaddresspairs as addr_pair
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common.rpc import proxy
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import test_extension_security_group as test_sg
|
||||
@ -71,9 +69,9 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
def test_security_group_rules_for_devices_ipv4_ingress(self):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv4]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -123,15 +121,15 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
self._delete('ports', port_id1)
|
||||
|
||||
def test_security_group_rules_for_devices_ipv4_ingress_addr_pair(self):
|
||||
plugin_obj = NeutronManager.get_plugin()
|
||||
plugin_obj = manager.NeutronManager.get_plugin()
|
||||
if ('allowed-address-pairs'
|
||||
not in plugin_obj.supported_extension_aliases):
|
||||
self.skipTest("Test depeneds on allowed-address-pairs extension")
|
||||
fake_prefix = FAKE_PREFIX['IPv4']
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -188,9 +186,9 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
def test_security_group_rules_for_devices_ipv4_egress(self):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv4]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -242,11 +240,11 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
def test_security_group_rules_for_devices_ipv4_source_group(self):
|
||||
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n),
|
||||
self.security_group(),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1,
|
||||
sg2):
|
||||
with contextlib.nested(self.subnet(n),
|
||||
self.security_group(),
|
||||
self.security_group()) as (subnet_v4,
|
||||
sg1,
|
||||
sg2):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
sg2_id = sg2['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
@ -302,12 +300,12 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP[const.IPv6]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -369,13 +367,13 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP['IPv6_GLOBAL']
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -439,13 +437,13 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP['IPv6_GLOBAL']
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -516,13 +514,13 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP['IPv6_LLA']
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -567,13 +565,13 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
def test_security_group_ra_rules_for_devices_ipv6_no_gateway_port(self):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=None,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=None,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6,
|
||||
ipv6_ra_mode=const.IPV6_SLAAC),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -614,12 +612,12 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP[const.IPv6]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
sg1_id,
|
||||
@ -679,14 +677,14 @@ class SGServerRpcCallBackMixinTestCase(test_sg.SecurityGroupDBTestCase):
|
||||
fake_prefix = FAKE_PREFIX[const.IPv6]
|
||||
fake_gateway = FAKE_IP[const.IPv6]
|
||||
with self.network() as n:
|
||||
with nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group(),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1,
|
||||
sg2):
|
||||
with contextlib.nested(self.subnet(n,
|
||||
gateway_ip=fake_gateway,
|
||||
cidr=fake_prefix,
|
||||
ip_version=6),
|
||||
self.security_group(),
|
||||
self.security_group()) as (subnet_v6,
|
||||
sg1,
|
||||
sg2):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
sg2_id = sg2['security_group']['id']
|
||||
rule1 = self._build_security_group_rule(
|
||||
@ -759,18 +757,18 @@ class SGAgentRpcCallBackMixinTestCase(base.BaseTestCase):
|
||||
self.rpc.security_groups_rule_updated(None,
|
||||
security_groups=['fake_sgid'])
|
||||
self.rpc.sg_agent.assert_has_calls(
|
||||
[call.security_groups_rule_updated(['fake_sgid'])])
|
||||
[mock.call.security_groups_rule_updated(['fake_sgid'])])
|
||||
|
||||
def test_security_groups_member_updated(self):
|
||||
self.rpc.security_groups_member_updated(None,
|
||||
security_groups=['fake_sgid'])
|
||||
self.rpc.sg_agent.assert_has_calls(
|
||||
[call.security_groups_member_updated(['fake_sgid'])])
|
||||
[mock.call.security_groups_member_updated(['fake_sgid'])])
|
||||
|
||||
def test_security_groups_provider_updated(self):
|
||||
self.rpc.security_groups_provider_updated(None)
|
||||
self.rpc.sg_agent.assert_has_calls(
|
||||
[call.security_groups_provider_updated()])
|
||||
[mock.call.security_groups_provider_updated()])
|
||||
|
||||
|
||||
class SecurityGroupAgentRpcTestCaseForNoneDriver(base.BaseTestCase):
|
||||
@ -816,11 +814,11 @@ class SecurityGroupAgentRpcTestCase(base.BaseTestCase):
|
||||
self.agent.prepare_devices_filter(['fake_device'])
|
||||
self.agent.remove_devices_filter(['fake_device'])
|
||||
# ignore device which is not filtered
|
||||
self.firewall.assert_has_calls([call.defer_apply(),
|
||||
call.prepare_port_filter(
|
||||
self.firewall.assert_has_calls([mock.call.defer_apply(),
|
||||
mock.call.prepare_port_filter(
|
||||
self.fake_device),
|
||||
call.defer_apply(),
|
||||
call.remove_port_filter(
|
||||
mock.call.defer_apply(),
|
||||
mock.call.remove_port_filter(
|
||||
self.fake_device),
|
||||
])
|
||||
|
||||
@ -829,7 +827,7 @@ class SecurityGroupAgentRpcTestCase(base.BaseTestCase):
|
||||
self.agent.prepare_devices_filter(['fake_port_id'])
|
||||
self.agent.security_groups_rule_updated(['fake_sgid1', 'fake_sgid3'])
|
||||
self.agent.refresh_firewall.assert_has_calls(
|
||||
[call.refresh_firewall([self.fake_device['device']])])
|
||||
[mock.call.refresh_firewall([self.fake_device['device']])])
|
||||
|
||||
def test_security_groups_rule_not_updated(self):
|
||||
self.agent.refresh_firewall = mock.Mock()
|
||||
@ -842,7 +840,7 @@ class SecurityGroupAgentRpcTestCase(base.BaseTestCase):
|
||||
self.agent.prepare_devices_filter(['fake_port_id'])
|
||||
self.agent.security_groups_member_updated(['fake_sgid2', 'fake_sgid3'])
|
||||
self.agent.refresh_firewall.assert_has_calls(
|
||||
[call.refresh_firewall([self.fake_device['device']])])
|
||||
[mock.call.refresh_firewall([self.fake_device['device']])])
|
||||
|
||||
def test_security_groups_member_not_updated(self):
|
||||
self.agent.refresh_firewall = mock.Mock()
|
||||
@ -854,24 +852,24 @@ class SecurityGroupAgentRpcTestCase(base.BaseTestCase):
|
||||
self.agent.refresh_firewall = mock.Mock()
|
||||
self.agent.security_groups_provider_updated()
|
||||
self.agent.refresh_firewall.assert_has_calls(
|
||||
[call.refresh_firewall()])
|
||||
[mock.call.refresh_firewall()])
|
||||
|
||||
def test_refresh_firewall(self):
|
||||
self.agent.prepare_devices_filter(['fake_port_id'])
|
||||
self.agent.refresh_firewall()
|
||||
calls = [call.defer_apply(),
|
||||
call.prepare_port_filter(self.fake_device),
|
||||
call.defer_apply(),
|
||||
call.update_port_filter(self.fake_device)]
|
||||
calls = [mock.call.defer_apply(),
|
||||
mock.call.prepare_port_filter(self.fake_device),
|
||||
mock.call.defer_apply(),
|
||||
mock.call.update_port_filter(self.fake_device)]
|
||||
self.firewall.assert_has_calls(calls)
|
||||
|
||||
def test_refresh_firewall_devices(self):
|
||||
self.agent.prepare_devices_filter(['fake_port_id'])
|
||||
self.agent.refresh_firewall([self.fake_device])
|
||||
calls = [call.defer_apply(),
|
||||
call.prepare_port_filter(self.fake_device),
|
||||
call.defer_apply(),
|
||||
call.update_port_filter(self.fake_device)]
|
||||
calls = [mock.call.defer_apply(),
|
||||
mock.call.prepare_port_filter(self.fake_device),
|
||||
mock.call.defer_apply(),
|
||||
mock.call.update_port_filter(self.fake_device)]
|
||||
self.firewall.assert_has_calls(calls)
|
||||
|
||||
def test_refresh_firewall_none(self):
|
||||
@ -886,7 +884,7 @@ class SecurityGroupAgentRpcWithDeferredRefreshTestCase(
|
||||
super(SecurityGroupAgentRpcWithDeferredRefreshTestCase, self).setUp(
|
||||
defer_refresh_firewall=True)
|
||||
|
||||
@contextmanager
|
||||
@contextlib.contextmanager
|
||||
def add_fake_device(self, device, sec_groups, source_sec_groups=None):
|
||||
fake_device = {'device': device,
|
||||
'security_groups': sec_groups,
|
||||
@ -1095,7 +1093,7 @@ class SecurityGroupServerRpcApiTestCase(base.BaseTestCase):
|
||||
def test_security_group_rules_for_devices(self):
|
||||
self.rpc.security_group_rules_for_devices(None, ['fake_device'])
|
||||
self.rpc.call.assert_has_calls(
|
||||
[call(None,
|
||||
[mock.call(None,
|
||||
{'args':
|
||||
{'devices': ['fake_device']},
|
||||
'method': 'security_group_rules_for_devices',
|
||||
@ -1120,25 +1118,25 @@ class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase):
|
||||
self.notifier.security_groups_rule_updated(
|
||||
None, security_groups=['fake_sgid'])
|
||||
self.notifier.fanout_cast.assert_has_calls(
|
||||
[call(None,
|
||||
{'args':
|
||||
{'security_groups': ['fake_sgid']},
|
||||
'method': 'security_groups_rule_updated',
|
||||
'namespace': None},
|
||||
version=sg_rpc.SG_RPC_VERSION,
|
||||
topic='fake-security_group-update')])
|
||||
[mock.call(None,
|
||||
{'args':
|
||||
{'security_groups': ['fake_sgid']},
|
||||
'method': 'security_groups_rule_updated',
|
||||
'namespace': None},
|
||||
version=sg_rpc.SG_RPC_VERSION,
|
||||
topic='fake-security_group-update')])
|
||||
|
||||
def test_security_groups_member_updated(self):
|
||||
self.notifier.security_groups_member_updated(
|
||||
None, security_groups=['fake_sgid'])
|
||||
self.notifier.fanout_cast.assert_has_calls(
|
||||
[call(None,
|
||||
{'args':
|
||||
{'security_groups': ['fake_sgid']},
|
||||
'method': 'security_groups_member_updated',
|
||||
'namespace': None},
|
||||
version=sg_rpc.SG_RPC_VERSION,
|
||||
topic='fake-security_group-update')])
|
||||
[mock.call(None,
|
||||
{'args':
|
||||
{'security_groups': ['fake_sgid']},
|
||||
'method': 'security_groups_member_updated',
|
||||
'namespace': None},
|
||||
version=sg_rpc.SG_RPC_VERSION,
|
||||
topic='fake-security_group-update')])
|
||||
|
||||
def test_security_groups_rule_not_updated(self):
|
||||
self.notifier.security_groups_rule_updated(
|
||||
@ -1822,7 +1820,7 @@ class TestSecurityGroupAgentWithIptables(base.BaseTestCase):
|
||||
|
||||
if has_process_input:
|
||||
kwargs['process_input'] = mock.ANY
|
||||
self.expected_calls.append(call(*args, **kwargs))
|
||||
self.expected_calls.append(mock.call(*args, **kwargs))
|
||||
self.expected_call_count += 1
|
||||
|
||||
def _verify_mock_calls(self):
|
||||
@ -1921,10 +1919,10 @@ class SGNotificationTestMixin():
|
||||
):
|
||||
pass
|
||||
self.notifier.assert_has_calls(
|
||||
[call.security_groups_rule_updated(mock.ANY,
|
||||
[security_group_id]),
|
||||
call.security_groups_rule_updated(mock.ANY,
|
||||
[security_group_id])])
|
||||
[mock.call.security_groups_rule_updated(mock.ANY,
|
||||
[security_group_id]),
|
||||
mock.call.security_groups_rule_updated(mock.ANY,
|
||||
[security_group_id])])
|
||||
|
||||
def test_security_group_member_updated(self):
|
||||
with self.network() as n:
|
||||
@ -1947,7 +1945,7 @@ class SGNotificationTestMixin():
|
||||
security_group_id)
|
||||
self._delete('ports', port['port']['id'])
|
||||
self.notifier.assert_has_calls(
|
||||
[call.security_groups_member_updated(
|
||||
[mock.call.security_groups_member_updated(
|
||||
mock.ANY, [mock.ANY])])
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import httplib
|
||||
|
||||
from neutron.plugins.vmware.api_client import ctrl_conn_to_str
|
||||
from neutron.plugins.vmware import api_client
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
@ -25,11 +25,11 @@ class ApiCommonTest(base.BaseTestCase):
|
||||
def test_ctrl_conn_to_str(self):
|
||||
conn = httplib.HTTPSConnection('localhost', 4242, timeout=0)
|
||||
self.assertTrue(
|
||||
ctrl_conn_to_str(conn) == 'https://localhost:4242')
|
||||
api_client.ctrl_conn_to_str(conn) == 'https://localhost:4242')
|
||||
|
||||
conn = httplib.HTTPConnection('localhost', 4242, timeout=0)
|
||||
self.assertTrue(
|
||||
ctrl_conn_to_str(conn) == 'http://localhost:4242')
|
||||
api_client.ctrl_conn_to_str(conn) == 'http://localhost:4242')
|
||||
|
||||
self.assertRaises(TypeError, ctrl_conn_to_str,
|
||||
self.assertRaises(TypeError, api_client.ctrl_conn_to_str,
|
||||
('not an httplib.HTTPSConnection'))
|
||||
|
@ -19,13 +19,12 @@ import random
|
||||
|
||||
import eventlet
|
||||
from eventlet.green import urllib2
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
import mock
|
||||
|
||||
from neutron.plugins.vmware.api_client import eventlet_client as client
|
||||
from neutron.plugins.vmware.api_client import eventlet_request as request
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.vmware import CLIENT_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@ -70,7 +69,7 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
for i in range(10):
|
||||
a = request.EventletApiRequest(
|
||||
self.client, self.url, request_timeout=0.1)
|
||||
a._handle_request = Mock()
|
||||
a._handle_request = mock.Mock()
|
||||
a.start()
|
||||
eventlet.greenthread.sleep(0.1)
|
||||
logging.info('_handle_request called: %s' %
|
||||
@ -78,13 +77,13 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
request.EventletApiRequest.joinall()
|
||||
|
||||
def test_join_with_handle_request(self):
|
||||
self.req._handle_request = Mock()
|
||||
self.req._handle_request = mock.Mock()
|
||||
self.req.start()
|
||||
self.req.join()
|
||||
self.assertTrue(self.req._handle_request.called)
|
||||
|
||||
def test_join_without_handle_request(self):
|
||||
self.req._handle_request = Mock()
|
||||
self.req._handle_request = mock.Mock()
|
||||
self.req.join()
|
||||
self.assertFalse(self.req._handle_request.called)
|
||||
|
||||
@ -101,7 +100,7 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
|
||||
def test_run_and_handle_request(self):
|
||||
self.req._request_timeout = None
|
||||
self.req._handle_request = Mock()
|
||||
self.req._handle_request = mock.Mock()
|
||||
self.req.start()
|
||||
self.req.join()
|
||||
self.assertTrue(self.req._handle_request.called)
|
||||
@ -119,34 +118,34 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
self.assertIsNone(self.req.join())
|
||||
|
||||
def prep_issue_request(self):
|
||||
mysock = Mock()
|
||||
mysock = mock.Mock()
|
||||
mysock.gettimeout.return_value = 4242
|
||||
|
||||
myresponse = Mock()
|
||||
myresponse = mock.Mock()
|
||||
myresponse.read.return_value = 'body'
|
||||
myresponse.getheaders.return_value = 'headers'
|
||||
myresponse.status = httplib.MOVED_PERMANENTLY
|
||||
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
myconn.request.return_value = None
|
||||
myconn.sock = mysock
|
||||
myconn.getresponse.return_value = myresponse
|
||||
myconn.__str__ = Mock()
|
||||
myconn.__str__ = mock.Mock()
|
||||
myconn.__str__.return_value = 'myconn string'
|
||||
|
||||
req = self.req
|
||||
req._redirect_params = Mock()
|
||||
req._redirect_params = mock.Mock()
|
||||
req._redirect_params.return_value = (myconn, 'url')
|
||||
req._request_str = Mock()
|
||||
req._request_str = mock.Mock()
|
||||
req._request_str.return_value = 'http://cool/cool'
|
||||
|
||||
client = self.client
|
||||
client.need_login = False
|
||||
client._auto_login = False
|
||||
client._auth_cookie = False
|
||||
client.acquire_connection = Mock()
|
||||
client.acquire_connection = mock.Mock()
|
||||
client.acquire_connection.return_value = myconn
|
||||
client.release_connection = Mock()
|
||||
client.release_connection = mock.Mock()
|
||||
|
||||
return (mysock, myresponse, myconn)
|
||||
|
||||
@ -186,34 +185,34 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
self.assertTrue(self.client.acquire_connection.called)
|
||||
|
||||
def test_redirect_params_break_on_location(self):
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', None)])
|
||||
self.assertIsNone(retval)
|
||||
|
||||
def test_redirect_params_parse_a_url(self):
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', '/path/a/b/c')])
|
||||
self.assertIsNotNone(retval)
|
||||
|
||||
def test_redirect_params_invalid_redirect_location(self):
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', '+path/a/b/c')])
|
||||
self.assertIsNone(retval)
|
||||
|
||||
def test_redirect_params_invalid_scheme(self):
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', 'invalidscheme://hostname:1/path')])
|
||||
self.assertIsNone(retval)
|
||||
|
||||
def test_redirect_params_setup_https_with_cooki(self):
|
||||
with patch(CLIENT_NAME) as mock:
|
||||
api_client = mock.return_value
|
||||
with mock.patch(vmware.CLIENT_NAME) as mock_client:
|
||||
api_client = mock_client.return_value
|
||||
self.req._api_client = api_client
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', 'https://host:1/path')])
|
||||
|
||||
@ -221,10 +220,10 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||
|
||||
def test_redirect_params_setup_htttps_and_query(self):
|
||||
with patch(CLIENT_NAME) as mock:
|
||||
api_client = mock.return_value
|
||||
with mock.patch(vmware.CLIENT_NAME) as mock_client:
|
||||
api_client = mock_client.return_value
|
||||
self.req._api_client = api_client
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(myconn, [
|
||||
('location', 'https://host:1/path?q=1')])
|
||||
|
||||
@ -232,10 +231,10 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||
|
||||
def test_redirect_params_setup_https_connection_no_cookie(self):
|
||||
with patch(CLIENT_NAME) as mock:
|
||||
api_client = mock.return_value
|
||||
with mock.patch(vmware.CLIENT_NAME) as mock_client:
|
||||
api_client = mock_client.return_value
|
||||
self.req._api_client = api_client
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(myconn, [
|
||||
('location', 'https://host:1/path')])
|
||||
|
||||
@ -243,49 +242,49 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||
|
||||
def test_redirect_params_setup_https_and_query_no_cookie(self):
|
||||
with patch(CLIENT_NAME) as mock:
|
||||
api_client = mock.return_value
|
||||
with mock.patch(vmware.CLIENT_NAME) as mock_client:
|
||||
api_client = mock_client.return_value
|
||||
self.req._api_client = api_client
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(
|
||||
myconn, [('location', 'https://host:1/path?q=1')])
|
||||
self.assertIsNotNone(retval)
|
||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||
|
||||
def test_redirect_params_path_only_with_query(self):
|
||||
with patch(CLIENT_NAME) as mock:
|
||||
api_client = mock.return_value
|
||||
with mock.patch(vmware.CLIENT_NAME) as mock_client:
|
||||
api_client = mock_client.return_value
|
||||
api_client.wait_for_login.return_value = None
|
||||
api_client.auth_cookie = None
|
||||
api_client.acquire_connection.return_value = True
|
||||
myconn = Mock()
|
||||
myconn = mock.Mock()
|
||||
(conn, retval) = self.req._redirect_params(myconn, [
|
||||
('location', '/path?q=1')])
|
||||
self.assertIsNotNone(retval)
|
||||
|
||||
def test_handle_request_auto_login(self):
|
||||
self.req._auto_login = True
|
||||
self.req._api_client = Mock()
|
||||
self.req._api_client = mock.Mock()
|
||||
self.req._api_client.need_login = True
|
||||
self.req._request_str = Mock()
|
||||
self.req._request_str = mock.Mock()
|
||||
self.req._request_str.return_value = 'http://cool/cool'
|
||||
self.req.spawn = Mock()
|
||||
self.req.spawn = mock.Mock()
|
||||
self.req._handle_request()
|
||||
|
||||
def test_handle_request_auto_login_unauth(self):
|
||||
self.req._auto_login = True
|
||||
self.req._api_client = Mock()
|
||||
self.req._api_client = mock.Mock()
|
||||
self.req._api_client.need_login = True
|
||||
self.req._request_str = Mock()
|
||||
self.req._request_str = mock.Mock()
|
||||
self.req._request_str.return_value = 'http://cool/cool'
|
||||
|
||||
import socket
|
||||
resp = httplib.HTTPResponse(socket.socket())
|
||||
resp.status = httplib.UNAUTHORIZED
|
||||
mywaiter = Mock()
|
||||
mywaiter.wait = Mock()
|
||||
mywaiter = mock.Mock()
|
||||
mywaiter.wait = mock.Mock()
|
||||
mywaiter.wait.return_value = resp
|
||||
self.req.spawn = Mock(return_value=mywaiter)
|
||||
self.req.spawn = mock.Mock(return_value=mywaiter)
|
||||
self.req._handle_request()
|
||||
|
||||
def test_construct_eventlet_login_request(self):
|
||||
@ -294,19 +293,19 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
|
||||
def test_session_cookie_session_cookie_retrieval(self):
|
||||
r = request.LoginRequestEventlet(self.client, 'user', 'password')
|
||||
r.successful = Mock()
|
||||
r.successful = mock.Mock()
|
||||
r.successful.return_value = True
|
||||
r.value = Mock()
|
||||
r.value.get_header = Mock()
|
||||
r.value = mock.Mock()
|
||||
r.value.get_header = mock.Mock()
|
||||
r.value.get_header.return_value = 'cool'
|
||||
self.assertIsNotNone(r.session_cookie())
|
||||
|
||||
def test_session_cookie_not_retrieved(self):
|
||||
r = request.LoginRequestEventlet(self.client, 'user', 'password')
|
||||
r.successful = Mock()
|
||||
r.successful = mock.Mock()
|
||||
r.successful.return_value = False
|
||||
r.value = Mock()
|
||||
r.value.get_header = Mock()
|
||||
r.value = mock.Mock()
|
||||
r.value.get_header = mock.Mock()
|
||||
r.value.get_header.return_value = 'cool'
|
||||
self.assertIsNone(r.session_cookie())
|
||||
|
||||
@ -316,17 +315,17 @@ class ApiRequestEventletTest(base.BaseTestCase):
|
||||
|
||||
def test_api_providers_none_api_providers(self):
|
||||
r = request.GetApiProvidersRequestEventlet(self.client)
|
||||
r.successful = Mock(return_value=False)
|
||||
r.successful = mock.Mock(return_value=False)
|
||||
self.assertIsNone(r.api_providers())
|
||||
|
||||
def test_api_providers_non_none_api_providers(self):
|
||||
r = request.GetApiProvidersRequestEventlet(self.client)
|
||||
r.value = Mock()
|
||||
r.value = mock.Mock()
|
||||
r.value.body = """{
|
||||
"results": [
|
||||
{ "roles": [
|
||||
{ "role": "api_provider",
|
||||
"listen_addr": "pssl:1.1.1.1:1" }]}]}"""
|
||||
r.successful = Mock(return_value=True)
|
||||
r.successful = mock.Mock(return_value=True)
|
||||
LOG.info('%s' % r.api_providers())
|
||||
self.assertIsNotNone(r.api_providers())
|
||||
|
@ -19,18 +19,14 @@ import mock
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common.test_lib import test_config
|
||||
from neutron.common import test_lib
|
||||
from neutron import context
|
||||
from neutron.extensions import agent
|
||||
from neutron.plugins.vmware.api_client.version import Version
|
||||
from neutron.plugins.vmware.api_client import version
|
||||
from neutron.plugins.vmware.common import sync
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
|
||||
class MacLearningExtensionManager(object):
|
||||
@ -56,28 +52,29 @@ class MacLearningDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.adminContext = context.get_admin_context()
|
||||
test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
test_lib.test_config['config_files'] = [
|
||||
vmware.get_fake_conf('nsx.ini.full.test')]
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
# Save the original RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
|
||||
self.saved_attr_map[resource] = attrs.copy()
|
||||
ext_mgr = MacLearningExtensionManager()
|
||||
# mock api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsx.start()
|
||||
# Avoid runs of the synchronizer looping call
|
||||
patch_sync = mock.patch.object(sync, '_start_loopingcall')
|
||||
patch_sync.start()
|
||||
|
||||
# Emulate tests against NSX 2.x
|
||||
instance.return_value.get_version.return_value = Version("3.0")
|
||||
instance.return_value.get_version.return_value = version.Version("3.0")
|
||||
instance.return_value.request.side_effect = self.fc.fake_request
|
||||
cfg.CONF.set_override('metadata_mode', None, 'NSX')
|
||||
self.addCleanup(self.fc.reset_all)
|
||||
self.addCleanup(self.restore_resource_attribute_map)
|
||||
super(MacLearningDBTestCase, self).setUp(plugin=PLUGIN_NAME,
|
||||
super(MacLearningDBTestCase, self).setUp(plugin=vmware.PLUGIN_NAME,
|
||||
ext_mgr=ext_mgr)
|
||||
|
||||
def restore_resource_attribute_map(self):
|
||||
|
@ -20,7 +20,6 @@ from webob import exc
|
||||
import webtest
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.extensions import PluginAwareExtensionManager
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron import context
|
||||
from neutron.db import api as db_api
|
||||
@ -37,9 +36,8 @@ from neutron.tests import base
|
||||
from neutron.tests.unit import test_api_v2
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
from neutron.tests.unit import test_extensions
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit.vmware.test_nsx_plugin import NsxPluginV2TestCase
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware import test_nsx_plugin
|
||||
|
||||
_uuid = test_api_v2._uuid
|
||||
_get_path = test_api_v2._get_path
|
||||
@ -88,7 +86,7 @@ class NetworkGatewayExtensionTestCase(base.BaseTestCase):
|
||||
manager.NeutronManager.get_plugin().supported_extension_aliases = (
|
||||
[networkgw.EXT_ALIAS])
|
||||
ext_mgr = TestExtensionManager()
|
||||
PluginAwareExtensionManager._instance = ext_mgr
|
||||
extensions.PluginAwareExtensionManager._instance = ext_mgr
|
||||
self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr)
|
||||
self.api = webtest.TestApp(self.ext_mdw)
|
||||
|
||||
@ -863,11 +861,11 @@ class NetworkGatewayDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
self.assertIsNone(dev_query.first())
|
||||
|
||||
|
||||
class TestNetworkGateway(NsxPluginV2TestCase,
|
||||
class TestNetworkGateway(test_nsx_plugin.NsxPluginV2TestCase,
|
||||
NetworkGatewayDbTestCase):
|
||||
|
||||
def setUp(self, plugin=PLUGIN_NAME, ext_mgr=None):
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
def setUp(self, plugin=vmware.PLUGIN_NAME, ext_mgr=None):
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
# Mock l2gwlib calls for gateway devices since this resource is not
|
||||
# mocked through the fake NVP API client
|
||||
create_gw_dev_patcher = mock.patch.object(
|
||||
@ -1046,7 +1044,7 @@ class TestNetworkGatewayPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
def __init__(self, **args):
|
||||
super(TestNetworkGatewayPlugin, self).__init__(**args)
|
||||
extensions.append_api_extensions_path([NSXEXT_PATH])
|
||||
extensions.append_api_extensions_path([vmware.NSXEXT_PATH])
|
||||
|
||||
def delete_port(self, context, id, nw_gw_port_check=True):
|
||||
if nw_gw_port_check:
|
||||
|
@ -18,20 +18,18 @@ import mock
|
||||
from neutron.common import test_lib
|
||||
from neutron.plugins.vmware.common import sync
|
||||
from neutron.tests.unit import test_extension_portsecurity as psec
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
|
||||
class PortSecurityTestCase(psec.PortSecurityDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
test_lib.test_config['config_files'] = [get_fake_conf('nsx.ini.test')]
|
||||
test_lib.test_config['config_files'] = [
|
||||
vmware.get_fake_conf('nsx.ini.test')]
|
||||
# mock api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsx.start()
|
||||
instance.return_value.login.return_value = "the_cookie"
|
||||
# Avoid runs of the synchronizer looping call
|
||||
@ -39,7 +37,7 @@ class PortSecurityTestCase(psec.PortSecurityDBTestCase):
|
||||
patch_sync.start()
|
||||
|
||||
instance.return_value.request.side_effect = self.fc.fake_request
|
||||
super(PortSecurityTestCase, self).setUp(PLUGIN_NAME)
|
||||
super(PortSecurityTestCase, self).setUp(vmware.PLUGIN_NAME)
|
||||
self.addCleanup(self.fc.reset_all)
|
||||
self.addCleanup(self.mock_nsx.stop)
|
||||
self.addCleanup(patch_sync.stop)
|
||||
|
@ -17,11 +17,11 @@ from oslo.config import cfg
|
||||
|
||||
from neutron.extensions import multiprovidernet as mpnet
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware.test_nsx_plugin import NsxPluginV2TestCase
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware import test_nsx_plugin
|
||||
|
||||
|
||||
class TestProvidernet(NsxPluginV2TestCase):
|
||||
class TestProvidernet(test_nsx_plugin.NsxPluginV2TestCase):
|
||||
|
||||
def test_create_provider_network_default_physical_net(self):
|
||||
data = {'network': {'name': 'net1',
|
||||
@ -48,10 +48,10 @@ class TestProvidernet(NsxPluginV2TestCase):
|
||||
self.assertEqual(net['network'][pnet.PHYSICAL_NETWORK], 'physnet1')
|
||||
|
||||
|
||||
class TestMultiProviderNetworks(NsxPluginV2TestCase):
|
||||
class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase):
|
||||
|
||||
def setUp(self, plugin=None):
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
super(TestMultiProviderNetworks, self).setUp()
|
||||
|
||||
def test_create_network_provider(self):
|
||||
|
@ -24,8 +24,8 @@ from neutron.plugins.vmware.dbexts import qos_db
|
||||
from neutron.plugins.vmware.extensions import qos as ext_qos
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
from neutron.tests.unit import test_extensions
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware.test_nsx_plugin import NsxPluginV2TestCase
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware import test_nsx_plugin
|
||||
|
||||
|
||||
class QoSTestExtensionManager(object):
|
||||
@ -40,10 +40,10 @@ class QoSTestExtensionManager(object):
|
||||
return []
|
||||
|
||||
|
||||
class TestQoSQueue(NsxPluginV2TestCase):
|
||||
class TestQoSQueue(test_nsx_plugin.NsxPluginV2TestCase):
|
||||
|
||||
def setUp(self, plugin=None):
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
super(TestQoSQueue, self).setUp()
|
||||
ext_mgr = QoSTestExtensionManager()
|
||||
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
|
||||
|
@ -23,9 +23,8 @@ from neutron.plugins.vmware.common import config # noqa
|
||||
from neutron.plugins.vmware import nsx_cluster as cluster
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import test_api_v2
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
_uuid = test_api_v2._uuid
|
||||
|
||||
@ -33,8 +32,8 @@ _uuid = test_api_v2._uuid
|
||||
class NsxlibTestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsxapi = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsxapi = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsxapi.start()
|
||||
instance.return_value.login.return_value = "the_cookie"
|
||||
fake_version = getattr(self, 'fake_version', "3.0")
|
||||
@ -62,8 +61,8 @@ class NsxlibTestCase(base.BaseTestCase):
|
||||
class NsxlibNegativeBaseTestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsxapi = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsxapi = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsxapi.start()
|
||||
instance.return_value.login.return_value = "the_cookie"
|
||||
# Choose 3.0, but the version is irrelevant for the aim of
|
||||
|
@ -21,7 +21,7 @@ from oslo.config import cfg
|
||||
from neutron.common import exceptions
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||
from neutron.plugins.vmware.api_client.version import Version
|
||||
from neutron.plugins.vmware.api_client import version as version_module
|
||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from neutron.plugins.vmware.common import utils
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
@ -38,7 +38,7 @@ class TestNatRules(base.NsxlibTestCase):
|
||||
def _test_create_lrouter_dnat_rule(self, version):
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
new=lambda: Version(version)):
|
||||
new=lambda: version_module.Version(version)):
|
||||
tenant_id = 'pippo'
|
||||
lrouter = routerlib.create_lrouter(self.fake_cluster,
|
||||
uuidutils.generate_uuid(),
|
||||
@ -319,7 +319,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
def _create_lrouter(self, version, neutron_id=None, distributed=None):
|
||||
with mock.patch.object(
|
||||
self.fake_cluster.api_client, 'get_version',
|
||||
return_value=Version(version)):
|
||||
return_value=version_module.Version(version)):
|
||||
if not neutron_id:
|
||||
neutron_id = uuidutils.generate_uuid()
|
||||
lrouter = routerlib.create_lrouter(
|
||||
@ -380,7 +380,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
return_value=Version(version)):
|
||||
return_value=version_module.Version(version)):
|
||||
with mock.patch.dict(routerlib.ROUTER_FUNC_DICT,
|
||||
foo_func_dict, clear=True):
|
||||
return routerlib.update_lrouter(
|
||||
@ -769,7 +769,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
'10.0.0.1')
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
new=lambda: Version(version)):
|
||||
new=lambda: version_module.Version(version)):
|
||||
routerlib.create_lrouter_snat_rule(
|
||||
self.fake_cluster, lrouter['uuid'],
|
||||
'10.0.0.2', '10.0.0.2', order=200,
|
||||
@ -792,7 +792,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
'10.0.0.1')
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
return_value=Version(version)):
|
||||
return_value=version_module.Version(version)):
|
||||
routerlib.create_lrouter_dnat_rule(
|
||||
self.fake_cluster, lrouter['uuid'], '192.168.0.2', order=200,
|
||||
dest_port=dest_port,
|
||||
@ -838,7 +838,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
'10.0.0.1')
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
new=lambda: Version(version)):
|
||||
new=lambda: version_module.Version(version)):
|
||||
routerlib.create_lrouter_nosnat_rule(
|
||||
self.fake_cluster, lrouter['uuid'],
|
||||
order=100,
|
||||
@ -863,7 +863,7 @@ class TestLogicalRouters(base.NsxlibTestCase):
|
||||
# v2 or v3 makes no difference for this test
|
||||
with mock.patch.object(self.fake_cluster.api_client,
|
||||
'get_version',
|
||||
new=lambda: Version('2.0')):
|
||||
new=lambda: version_module.Version('2.0')):
|
||||
routerlib.create_lrouter_snat_rule(
|
||||
self.fake_cluster, lrouter['uuid'],
|
||||
'10.0.0.2', '10.0.0.2', order=220,
|
||||
|
@ -15,7 +15,7 @@
|
||||
#
|
||||
|
||||
from neutron.plugins.vmware.api_client import exception
|
||||
from neutron.plugins.vmware.api_client.version import Version
|
||||
from neutron.plugins.vmware.api_client import version as version_module
|
||||
from neutron.plugins.vmware.nsxlib import router as routerlib
|
||||
from neutron.plugins.vmware.nsxlib import versioning
|
||||
from neutron.tests import base
|
||||
@ -24,28 +24,28 @@ from neutron.tests import base
|
||||
class TestVersioning(base.BaseTestCase):
|
||||
|
||||
def test_function_handling_missing_minor(self):
|
||||
version = Version('2.0')
|
||||
version = version_module.Version('2.0')
|
||||
function = versioning.get_function_by_version(
|
||||
routerlib.ROUTER_FUNC_DICT, 'create_lrouter', version)
|
||||
self.assertEqual(routerlib.create_implicit_routing_lrouter,
|
||||
function)
|
||||
|
||||
def test_function_handling_with_both_major_and_minor(self):
|
||||
version = Version('3.2')
|
||||
version = version_module.Version('3.2')
|
||||
function = versioning.get_function_by_version(
|
||||
routerlib.ROUTER_FUNC_DICT, 'create_lrouter', version)
|
||||
self.assertEqual(routerlib.create_explicit_routing_lrouter,
|
||||
function)
|
||||
|
||||
def test_function_handling_with_newer_major(self):
|
||||
version = Version('5.2')
|
||||
version = version_module.Version('5.2')
|
||||
function = versioning.get_function_by_version(
|
||||
routerlib.ROUTER_FUNC_DICT, 'create_lrouter', version)
|
||||
self.assertEqual(routerlib.create_explicit_routing_lrouter,
|
||||
function)
|
||||
|
||||
def test_function_handling_with_obsolete_major(self):
|
||||
version = Version('1.2')
|
||||
version = version_module.Version('1.2')
|
||||
self.assertRaises(NotImplementedError,
|
||||
versioning.get_function_by_version,
|
||||
routerlib.ROUTER_FUNC_DICT,
|
||||
|
@ -17,26 +17,24 @@ import mock
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.common import constants
|
||||
from neutron.common.test_lib import test_config
|
||||
from neutron.common import test_lib
|
||||
from neutron.plugins.vmware.common import sync
|
||||
from neutron.plugins.vmware.dhcp_meta import rpc
|
||||
from neutron.tests.unit.openvswitch import test_agent_scheduler as test_base
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
|
||||
class DhcpAgentNotifierTestCase(test_base.OvsDhcpAgentNotifierTestCase):
|
||||
plugin_str = PLUGIN_NAME
|
||||
plugin_str = vmware.PLUGIN_NAME
|
||||
|
||||
def setUp(self):
|
||||
test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]
|
||||
test_lib.test_config['config_files'] = [
|
||||
vmware.get_fake_conf('nsx.ini.full.test')]
|
||||
|
||||
# mock api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsx_api = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsx_api = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsx_api.start()
|
||||
# Avoid runs of the synchronizer looping call
|
||||
patch_sync = mock.patch.object(sync, '_start_loopingcall')
|
||||
|
@ -21,7 +21,7 @@ from neutron.common import constants as n_consts
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron import context
|
||||
from neutron.db import api as db
|
||||
from neutron.plugins.vmware.api_client.exception import NsxApiException
|
||||
from neutron.plugins.vmware.api_client import exception
|
||||
from neutron.plugins.vmware.common import exceptions as p_exc
|
||||
from neutron.plugins.vmware.dbexts import lsn_db
|
||||
from neutron.plugins.vmware.dhcp_meta import constants
|
||||
@ -290,7 +290,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_get_raise_not_found_with_exc(n_exc.NotFound)
|
||||
|
||||
def test_lsn_get_raise_not_found_with_api_error(self):
|
||||
self._test_lsn_get_raise_not_found_with_exc(NsxApiException)
|
||||
self._test_lsn_get_raise_not_found_with_exc(exception.NsxApiException)
|
||||
|
||||
def _test_lsn_get_silent_raise_with_exc(self, exc):
|
||||
self.mock_lsn_api.lsn_for_network_get.side_effect = exc
|
||||
@ -304,7 +304,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_get_silent_raise_with_exc(n_exc.NotFound)
|
||||
|
||||
def test_lsn_get_silent_raise_with_api_error(self):
|
||||
self._test_lsn_get_silent_raise_with_exc(NsxApiException)
|
||||
self._test_lsn_get_silent_raise_with_exc(exception.NsxApiException)
|
||||
|
||||
def test_lsn_create(self):
|
||||
self.mock_lsn_api.lsn_for_network_create.return_value = self.lsn_id
|
||||
@ -313,7 +313,8 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
mock.ANY, self.net_id)
|
||||
|
||||
def test_lsn_create_raise_api_error(self):
|
||||
self.mock_lsn_api.lsn_for_network_create.side_effect = NsxApiException
|
||||
self.mock_lsn_api.lsn_for_network_create.side_effect = (
|
||||
exception.NsxApiException)
|
||||
self.assertRaises(p_exc.NsxPluginException,
|
||||
self.manager.lsn_create,
|
||||
mock.ANY, self.net_id)
|
||||
@ -335,7 +336,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_delete_with_exc(n_exc.NotFound)
|
||||
|
||||
def test_lsn_delete_api_exception(self):
|
||||
self._test_lsn_delete_with_exc(NsxApiException)
|
||||
self._test_lsn_delete_with_exc(exception.NsxApiException)
|
||||
|
||||
def test_lsn_delete_by_network(self):
|
||||
self.mock_lsn_api.lsn_for_network_get.return_value = self.lsn_id
|
||||
@ -355,7 +356,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_delete_by_network_with_exc(n_exc.NotFound)
|
||||
|
||||
def test_lsn_delete_by_network_with_not_api_error(self):
|
||||
self._test_lsn_delete_by_network_with_exc(NsxApiException)
|
||||
self._test_lsn_delete_by_network_with_exc(exception.NsxApiException)
|
||||
|
||||
def test_lsn_port_get(self):
|
||||
self.mock_lsn_api.lsn_port_by_subnet_get.return_value = (
|
||||
@ -412,7 +413,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_port_create_with_exc(n_exc.NotFound, p_exc.LsnNotFound)
|
||||
|
||||
def test_lsn_port_create_api_exception(self):
|
||||
self._test_lsn_port_create_with_exc(NsxApiException,
|
||||
self._test_lsn_port_create_with_exc(exception.NsxApiException,
|
||||
p_exc.NsxPluginException)
|
||||
|
||||
def test_lsn_port_delete(self):
|
||||
@ -430,7 +431,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_port_delete_with_exc(n_exc.NotFound)
|
||||
|
||||
def test_lsn_port_delete_api_exception(self):
|
||||
self._test_lsn_port_delete_with_exc(NsxApiException)
|
||||
self._test_lsn_port_delete_with_exc(exception.NsxApiException)
|
||||
|
||||
def _test_lsn_port_dhcp_setup(self, ret_val, sub):
|
||||
self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
|
||||
@ -639,7 +640,8 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
self._test_lsn_port_dispose_with_values(self.lsn_id, None, 0)
|
||||
|
||||
def test_lsn_port_dispose_api_error(self):
|
||||
self.mock_lsn_api.lsn_port_delete.side_effect = NsxApiException
|
||||
self.mock_lsn_api.lsn_port_delete.side_effect = (
|
||||
exception.NsxApiException)
|
||||
with mock.patch.object(lsn_man.LOG, 'warn') as l:
|
||||
self.manager.lsn_port_dispose(mock.ANY, self.net_id, self.mac)
|
||||
self.assertEqual(1, l.call_count)
|
||||
@ -686,7 +688,7 @@ class LsnManagerTestCase(base.BaseTestCase):
|
||||
|
||||
def test_lsn_port_update_raise_error(self):
|
||||
self.mock_lsn_api.lsn_port_host_entries_update.side_effect = (
|
||||
NsxApiException)
|
||||
exception.NsxApiException)
|
||||
self.assertRaises(p_exc.PortConfigurationError,
|
||||
self.manager.lsn_port_update,
|
||||
mock.ANY, mock.ANY, mock.ANY, mock.ANY)
|
||||
|
@ -18,7 +18,7 @@ import fixtures
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.vmware.api_client import client
|
||||
from neutron.plugins.vmware.api_client import version
|
||||
@ -28,14 +28,13 @@ from neutron.plugins.vmware.common import sync
|
||||
from neutron.plugins.vmware import nsx_cluster
|
||||
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
|
||||
BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
|
||||
NSX_INI_PATH = get_fake_conf('nsx.ini.basic.test')
|
||||
NSX_INI_FULL_PATH = get_fake_conf('nsx.ini.full.test')
|
||||
NSX_INI_AGENTLESS_PATH = get_fake_conf('nsx.ini.agentless.test')
|
||||
NVP_INI_DEPR_PATH = get_fake_conf('nvp.ini.full.test')
|
||||
BASE_CONF_PATH = vmware.get_fake_conf('neutron.conf.test')
|
||||
NSX_INI_PATH = vmware.get_fake_conf('nsx.ini.basic.test')
|
||||
NSX_INI_FULL_PATH = vmware.get_fake_conf('nsx.ini.full.test')
|
||||
NSX_INI_AGENTLESS_PATH = vmware.get_fake_conf('nsx.ini.agentless.test')
|
||||
NVP_INI_DEPR_PATH = vmware.get_fake_conf('nvp.ini.full.test')
|
||||
|
||||
|
||||
class NSXClusterTest(base.BaseTestCase):
|
||||
@ -100,8 +99,8 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
def test_load_plugin_with_full_options(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_FULL_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
plugin = NeutronManager().get_plugin()
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
plugin = manager.NeutronManager().get_plugin()
|
||||
cluster = plugin.cluster
|
||||
self._assert_required_options(cluster)
|
||||
self._assert_extra_options(cluster)
|
||||
@ -109,8 +108,8 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
def test_load_plugin_with_required_options_only(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
plugin = NeutronManager().get_plugin()
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
plugin = manager.NeutronManager().get_plugin()
|
||||
self._assert_required_options(plugin.cluster)
|
||||
|
||||
def test_defaults(self):
|
||||
@ -136,15 +135,15 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
def test_load_api_extensions(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_FULL_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
# Load the configuration, and initialize the plugin
|
||||
NeutronManager().get_plugin()
|
||||
manager.NeutronManager().get_plugin()
|
||||
self.assertIn('extensions', cfg.CONF.api_extensions_path)
|
||||
|
||||
def test_agentless_extensions(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_AGENTLESS_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
self.assertEqual(config.AgentModes.AGENTLESS,
|
||||
cfg.CONF.NSX.agent_mode)
|
||||
# The version returned from NSX does not really matter here
|
||||
@ -154,7 +153,7 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
with mock.patch.object(lsnlib,
|
||||
'service_cluster_exists',
|
||||
return_value=True):
|
||||
plugin = NeutronManager().get_plugin()
|
||||
plugin = manager.NeutronManager().get_plugin()
|
||||
self.assertNotIn('agent',
|
||||
plugin.supported_extension_aliases)
|
||||
self.assertNotIn('dhcp_agent_scheduler',
|
||||
@ -163,18 +162,19 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
def test_agentless_extensions_version_fail(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_AGENTLESS_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
self.assertEqual(config.AgentModes.AGENTLESS,
|
||||
cfg.CONF.NSX.agent_mode)
|
||||
with mock.patch.object(client.NsxApiClient,
|
||||
'get_version',
|
||||
return_value=version.Version("3.2")):
|
||||
self.assertRaises(exceptions.NsxPluginException, NeutronManager)
|
||||
self.assertRaises(exceptions.NsxPluginException,
|
||||
manager.NeutronManager)
|
||||
|
||||
def test_agentless_extensions_unmet_deps_fail(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_AGENTLESS_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
self.assertEqual(config.AgentModes.AGENTLESS,
|
||||
cfg.CONF.NSX.agent_mode)
|
||||
with mock.patch.object(client.NsxApiClient,
|
||||
@ -184,15 +184,15 @@ class ConfigurationTest(base.BaseTestCase):
|
||||
'service_cluster_exists',
|
||||
return_value=False):
|
||||
self.assertRaises(exceptions.NsxPluginException,
|
||||
NeutronManager)
|
||||
manager.NeutronManager)
|
||||
|
||||
def test_agent_extensions(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NSX_INI_FULL_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
self.assertEqual(config.AgentModes.AGENT,
|
||||
cfg.CONF.NSX.agent_mode)
|
||||
plugin = NeutronManager().get_plugin()
|
||||
plugin = manager.NeutronManager().get_plugin()
|
||||
self.assertIn('agent',
|
||||
plugin.supported_extension_aliases)
|
||||
self.assertIn('dhcp_agent_scheduler',
|
||||
@ -219,8 +219,8 @@ class OldNVPConfigurationTest(base.BaseTestCase):
|
||||
def test_load_plugin_with_deprecated_options(self):
|
||||
self.config_parse(args=['--config-file', BASE_CONF_PATH,
|
||||
'--config-file', NVP_INI_DEPR_PATH])
|
||||
cfg.CONF.set_override('core_plugin', PLUGIN_NAME)
|
||||
plugin = NeutronManager().get_plugin()
|
||||
cfg.CONF.set_override('core_plugin', vmware.PLUGIN_NAME)
|
||||
plugin = manager.NeutronManager().get_plugin()
|
||||
cluster = plugin.cluster
|
||||
# Verify old nvp_* params have been fully parsed
|
||||
self._assert_required_options(cluster)
|
||||
|
@ -33,30 +33,25 @@ from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.extensions import securitygroup as secgrp
|
||||
from neutron import manager
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron.openstack.common.db import exception as db_exc
|
||||
from neutron.openstack.common import log
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||
from neutron.plugins.vmware.api_client.version import Version
|
||||
from neutron.plugins.vmware.api_client import version as version_module
|
||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from neutron.plugins.vmware.common import sync
|
||||
from neutron.plugins.vmware.dbexts import db as nsx_db
|
||||
from neutron.plugins.vmware.extensions import distributedrouter as dist_router
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
from neutron.plugins.vmware.plugins.base import NetworkTypes
|
||||
from neutron.plugins.vmware.plugins import base
|
||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
||||
import neutron.tests.unit.test_db_plugin as test_plugin
|
||||
import neutron.tests.unit.test_extension_ext_gw_mode as test_ext_gw_mode
|
||||
import neutron.tests.unit.test_extension_security_group as ext_sg
|
||||
import neutron.tests.unit.test_l3_plugin as test_l3_plugin
|
||||
from neutron.tests.unit import testlib_api
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware import PLUGIN_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -91,13 +86,14 @@ class NsxPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
|
||||
return network_req.get_response(self.api)
|
||||
|
||||
def setUp(self,
|
||||
plugin=PLUGIN_NAME,
|
||||
plugin=vmware.PLUGIN_NAME,
|
||||
ext_mgr=None,
|
||||
service_plugins=None):
|
||||
test_lib.test_config['config_files'] = [get_fake_conf('nsx.ini.test')]
|
||||
test_lib.test_config['config_files'] = [
|
||||
vmware.get_fake_conf('nsx.ini.test')]
|
||||
# mock api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
self.mock_instance = self.mock_nsx.start()
|
||||
# Avoid runs of the synchronizer looping call
|
||||
patch_sync = mock.patch.object(sync, '_start_loopingcall')
|
||||
@ -105,7 +101,7 @@ class NsxPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
|
||||
|
||||
# Emulate tests against NSX 2.x
|
||||
self.mock_instance.return_value.get_version.return_value = (
|
||||
Version("2.9"))
|
||||
version_module.Version("2.9"))
|
||||
self.mock_instance.return_value.request.side_effect = (
|
||||
self.fc.fake_request)
|
||||
super(NsxPluginV2TestCase, self).setUp(plugin=plugin,
|
||||
@ -346,10 +342,11 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxPluginV2TestCase):
|
||||
class SecurityGroupsTestCase(ext_sg.SecurityGroupDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
test_lib.test_config['config_files'] = [get_fake_conf('nsx.ini.test')]
|
||||
test_lib.test_config['config_files'] = [
|
||||
vmware.get_fake_conf('nsx.ini.test')]
|
||||
# mock nsx api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
instance = self.mock_nsx.start()
|
||||
instance.return_value.login.return_value = "the_cookie"
|
||||
# Avoid runs of the synchronizer looping call
|
||||
@ -357,7 +354,7 @@ class SecurityGroupsTestCase(ext_sg.SecurityGroupDBTestCase):
|
||||
patch_sync.start()
|
||||
|
||||
instance.return_value.request.side_effect = self.fc.fake_request
|
||||
super(SecurityGroupsTestCase, self).setUp(PLUGIN_NAME)
|
||||
super(SecurityGroupsTestCase, self).setUp(vmware.PLUGIN_NAME)
|
||||
|
||||
|
||||
class TestSecurityGroup(ext_sg.TestSecurityGroups, SecurityGroupsTestCase):
|
||||
@ -442,18 +439,19 @@ class L3NatTest(test_l3_plugin.L3BaseForIntTests, NsxPluginV2TestCase):
|
||||
def _restore_l3_attribute_map(self):
|
||||
l3.RESOURCE_ATTRIBUTE_MAP = self._l3_attribute_map_bk
|
||||
|
||||
def setUp(self, plugin=PLUGIN_NAME, ext_mgr=None, service_plugins=None):
|
||||
def setUp(self, plugin=vmware.PLUGIN_NAME, ext_mgr=None,
|
||||
service_plugins=None):
|
||||
self._l3_attribute_map_bk = {}
|
||||
for item in l3.RESOURCE_ATTRIBUTE_MAP:
|
||||
self._l3_attribute_map_bk[item] = (
|
||||
l3.RESOURCE_ATTRIBUTE_MAP[item].copy())
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
l3_attribute_map_bk = backup_l3_attribute_map()
|
||||
self.addCleanup(restore_l3_attribute_map, l3_attribute_map_bk)
|
||||
ext_mgr = ext_mgr or TestL3ExtensionManager()
|
||||
super(L3NatTest, self).setUp(
|
||||
plugin=plugin, ext_mgr=ext_mgr, service_plugins=service_plugins)
|
||||
plugin_instance = NeutronManager.get_plugin()
|
||||
plugin_instance = manager.NeutronManager.get_plugin()
|
||||
self._plugin_name = "%s.%s" % (
|
||||
plugin_instance.__module__,
|
||||
plugin_instance.__class__.__name__)
|
||||
@ -461,7 +459,7 @@ class L3NatTest(test_l3_plugin.L3BaseForIntTests, NsxPluginV2TestCase):
|
||||
|
||||
def _create_l3_ext_network(self, vlan_id=None):
|
||||
name = 'l3_ext_net'
|
||||
net_type = NetworkTypes.L3_EXT
|
||||
net_type = base.NetworkTypes.L3_EXT
|
||||
providernet_args = {pnet.NETWORK_TYPE: net_type,
|
||||
pnet.PHYSICAL_NETWORK: 'l3_gw_uuid'}
|
||||
if vlan_id:
|
||||
@ -480,7 +478,7 @@ class TestL3NatTestCase(L3NatTest,
|
||||
|
||||
def _test_create_l3_ext_network(self, vlan_id=None):
|
||||
name = 'l3_ext_net'
|
||||
net_type = NetworkTypes.L3_EXT
|
||||
net_type = base.NetworkTypes.L3_EXT
|
||||
expected = [('subnets', []), ('name', name), ('admin_state_up', True),
|
||||
('status', 'ACTIVE'), ('shared', False),
|
||||
(external_net.EXTERNAL, True),
|
||||
@ -540,7 +538,7 @@ class TestL3NatTestCase(L3NatTest,
|
||||
def _test_router_create_with_distributed(self, dist_input, dist_expected,
|
||||
version='3.1', return_code=201):
|
||||
self.mock_instance.return_value.get_version.return_value = (
|
||||
Version(version))
|
||||
version_module.Version(version))
|
||||
|
||||
data = {'tenant_id': 'whatever'}
|
||||
data['name'] = 'router1'
|
||||
|
@ -37,10 +37,8 @@ from neutron.plugins.vmware import nsxlib
|
||||
from neutron.plugins.vmware import plugin
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import test_api_v2
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.apiclient import fake
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import NSXAPI_NAME
|
||||
from neutron.tests.unit.vmware import STUBS_PATH
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -259,8 +257,8 @@ class SyncTestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
# mock api client
|
||||
self.fc = fake.FakeClient(STUBS_PATH)
|
||||
mock_api = mock.patch(NSXAPI_NAME, autospec=True)
|
||||
self.fc = fake.FakeClient(vmware.STUBS_PATH)
|
||||
mock_api = mock.patch(vmware.NSXAPI_NAME, autospec=True)
|
||||
# Avoid runs of the synchronizer looping call
|
||||
# These unit tests will excplicitly invoke synchronization
|
||||
patch_sync = mock.patch.object(sync, '_start_loopingcall')
|
||||
@ -284,8 +282,8 @@ class SyncTestCase(base.BaseTestCase):
|
||||
redirects=self.fake_cluster.redirects)
|
||||
# Instantiate Neutron plugin
|
||||
# and setup needed config variables
|
||||
args = ['--config-file', get_fake_conf('neutron.conf.test'),
|
||||
'--config-file', get_fake_conf('nsx.ini.test')]
|
||||
args = ['--config-file', vmware.get_fake_conf('neutron.conf.test'),
|
||||
'--config-file', vmware.get_fake_conf('nsx.ini.test')]
|
||||
self.config_parse(args=args)
|
||||
cfg.CONF.set_override('allow_overlapping_ips', True)
|
||||
self._plugin = plugin.NsxPlugin()
|
||||
|
@ -23,7 +23,7 @@ from neutron.plugins.vmware.common import nsx_utils
|
||||
from neutron.plugins.vmware.common import utils
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.vmware import nsx_method
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.nsxlib import base as nsx_base
|
||||
|
||||
|
||||
@ -33,33 +33,33 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# Mock relevant db calls
|
||||
# This will allow for avoiding setting up the plugin
|
||||
# for creating db entries
|
||||
mock.patch(nsx_method('get_nsx_switch_and_port_id',
|
||||
module_name='dbexts.db'),
|
||||
mock.patch(vmware.nsx_method('get_nsx_switch_and_port_id',
|
||||
module_name='dbexts.db'),
|
||||
return_value=ret_value).start()
|
||||
mock.patch(nsx_method('add_neutron_nsx_port_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(nsx_method('delete_neutron_nsx_port_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(vmware.nsx_method('add_neutron_nsx_port_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(vmware.nsx_method('delete_neutron_nsx_port_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
|
||||
def _mock_network_mapping_db_calls(self, ret_value):
|
||||
# Mock relevant db calls
|
||||
# This will allow for avoiding setting up the plugin
|
||||
# for creating db entries
|
||||
mock.patch(nsx_method('get_nsx_switch_ids',
|
||||
module_name='dbexts.db'),
|
||||
mock.patch(vmware.nsx_method('get_nsx_switch_ids',
|
||||
module_name='dbexts.db'),
|
||||
return_value=ret_value).start()
|
||||
mock.patch(nsx_method('add_neutron_nsx_network_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(vmware.nsx_method('add_neutron_nsx_network_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
|
||||
def _mock_router_mapping_db_calls(self, ret_value):
|
||||
# Mock relevant db calls
|
||||
# This will allow for avoiding setting up the plugin
|
||||
# for creating db entries
|
||||
mock.patch(nsx_method('get_nsx_router_id',
|
||||
module_name='dbexts.db'),
|
||||
mock.patch(vmware.nsx_method('get_nsx_router_id',
|
||||
module_name='dbexts.db'),
|
||||
return_value=ret_value).start()
|
||||
mock.patch(nsx_method('add_neutron_nsx_router_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(vmware.nsx_method('add_neutron_nsx_router_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
|
||||
def _verify_get_nsx_switch_and_port_id(self, exp_ls_uuid, exp_lp_uuid):
|
||||
# The nsxlib and db calls are mocked, therefore the cluster
|
||||
@ -101,8 +101,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
exp_lp_uuid = uuidutils.generate_uuid()
|
||||
ret_value = None, exp_lp_uuid
|
||||
self._mock_port_mapping_db_calls(ret_value)
|
||||
with mock.patch(nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
with mock.patch(vmware.nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
return_value=[{'uuid': exp_lp_uuid,
|
||||
'_relations': {
|
||||
'LogicalSwitchConfig': {
|
||||
@ -117,8 +117,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
exp_lp_uuid = uuidutils.generate_uuid()
|
||||
ret_value = None, None
|
||||
self._mock_port_mapping_db_calls(ret_value)
|
||||
with mock.patch(nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
with mock.patch(vmware.nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
return_value=[{'uuid': exp_lp_uuid,
|
||||
'_relations': {
|
||||
'LogicalSwitchConfig': {
|
||||
@ -131,8 +131,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# mappings are not found both in the db and the backend
|
||||
ret_value = None, None
|
||||
self._mock_port_mapping_db_calls(ret_value)
|
||||
with mock.patch(nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
with mock.patch(vmware.nsx_method('query_lswitch_lports',
|
||||
module_name='nsxlib.switch'),
|
||||
return_value=[]):
|
||||
self._verify_get_nsx_switch_and_port_id(None, None)
|
||||
|
||||
@ -148,8 +148,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# found for a given network identifier
|
||||
exp_ls_uuids = [uuidutils.generate_uuid()]
|
||||
self._mock_network_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('get_lswitches',
|
||||
module_name='nsxlib.switch'),
|
||||
with mock.patch(vmware.nsx_method('get_lswitches',
|
||||
module_name='nsxlib.switch'),
|
||||
return_value=[{'uuid': uuid}
|
||||
for uuid in exp_ls_uuids]):
|
||||
self._verify_get_nsx_switch_ids(exp_ls_uuids)
|
||||
@ -158,8 +158,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# This test verifies that the function returns None if the mappings
|
||||
# are not found both in the db and in the backend
|
||||
self._mock_network_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('get_lswitches',
|
||||
module_name='nsxlib.switch'),
|
||||
with mock.patch(vmware.nsx_method('get_lswitches',
|
||||
module_name='nsxlib.switch'),
|
||||
return_value=[]):
|
||||
self._verify_get_nsx_switch_ids(None)
|
||||
|
||||
@ -175,8 +175,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# found for a given port identifier
|
||||
exp_lr_uuid = uuidutils.generate_uuid()
|
||||
self._mock_router_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('query_lrouters',
|
||||
module_name='nsxlib.router'),
|
||||
with mock.patch(vmware.nsx_method('query_lrouters',
|
||||
module_name='nsxlib.router'),
|
||||
return_value=[{'uuid': exp_lr_uuid}]):
|
||||
self._verify_get_nsx_router_id(exp_lr_uuid)
|
||||
|
||||
@ -184,8 +184,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# This test verifies that the function returns None if the mapping
|
||||
# are not found both in the db and in the backend
|
||||
self._mock_router_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('query_lrouters',
|
||||
module_name='nsxlib.router'),
|
||||
with mock.patch(vmware.nsx_method('query_lrouters',
|
||||
module_name='nsxlib.router'),
|
||||
return_value=[]):
|
||||
self._verify_get_nsx_router_id(None)
|
||||
|
||||
@ -267,11 +267,11 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def _mock_sec_group_mapping_db_calls(self, ret_value):
|
||||
mock.patch(nsx_method('get_nsx_security_group_id',
|
||||
module_name='dbexts.db'),
|
||||
mock.patch(vmware.nsx_method('get_nsx_security_group_id',
|
||||
module_name='dbexts.db'),
|
||||
return_value=ret_value).start()
|
||||
mock.patch(nsx_method('add_neutron_nsx_security_group_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
mock.patch(vmware.nsx_method('add_neutron_nsx_security_group_mapping',
|
||||
module_name='dbexts.db')).start()
|
||||
|
||||
def _verify_get_nsx_sec_profile_id(self, exp_sec_prof_uuid):
|
||||
# The nsxlib and db calls are mocked, therefore the cluster
|
||||
@ -292,8 +292,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# found for a given security profile identifier
|
||||
exp_sec_prof_uuid = uuidutils.generate_uuid()
|
||||
self._mock_sec_group_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('query_security_profiles',
|
||||
module_name='nsxlib.secgroup'),
|
||||
with mock.patch(vmware.nsx_method('query_security_profiles',
|
||||
module_name='nsxlib.secgroup'),
|
||||
return_value=[{'uuid': exp_sec_prof_uuid}]):
|
||||
self._verify_get_nsx_sec_profile_id(exp_sec_prof_uuid)
|
||||
|
||||
@ -301,8 +301,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# This test verifies that the function returns None if the mapping
|
||||
# are not found both in the db and in the backend
|
||||
self._mock_sec_group_mapping_db_calls(None)
|
||||
with mock.patch(nsx_method('query_security_profiles',
|
||||
module_name='nsxlib.secgroup'),
|
||||
with mock.patch(vmware.nsx_method('query_security_profiles',
|
||||
module_name='nsxlib.secgroup'),
|
||||
return_value=[]):
|
||||
self._verify_get_nsx_sec_profile_id(None)
|
||||
|
||||
|
@ -22,16 +22,14 @@ from oslo.config import cfg
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron import context
|
||||
from neutron.extensions import l3
|
||||
from neutron.manager import NeutronManager
|
||||
from neutron import manager as n_manager
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.vmware.common import utils
|
||||
from neutron.plugins.vmware.plugins import service as nsp
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import test_l3_plugin
|
||||
from neutron.tests.unit.vmware import NSXEXT_PATH
|
||||
from neutron.tests.unit.vmware import SERVICE_PLUGIN_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware import test_nsx_plugin
|
||||
from neutron.tests.unit.vmware import VCNS_NAME
|
||||
from neutron.tests.unit.vmware.vshield import fake_vcns
|
||||
|
||||
_uuid = uuidutils.generate_uuid
|
||||
@ -95,21 +93,22 @@ class ServiceRouterTest(test_nsx_plugin.L3NatTest,
|
||||
self.fc2.enable_service_loadbalancer)
|
||||
|
||||
def setUp(self, ext_mgr=None, service_plugins=None):
|
||||
cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
|
||||
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH)
|
||||
cfg.CONF.set_override('task_status_check_interval', 200, group="vcns")
|
||||
|
||||
# vcns does not support duplicated router name, ignore router name
|
||||
# validation for unit-test cases
|
||||
self.fc2 = fake_vcns.FakeVcns(unique_router_name=False)
|
||||
self.mock_vcns = mock.patch(VCNS_NAME, autospec=True)
|
||||
self.mock_vcns = mock.patch(vmware.VCNS_NAME, autospec=True)
|
||||
self.vcns_patch()
|
||||
mock_proxy = mock.patch(
|
||||
"%s.%s" % (SERVICE_PLUGIN_NAME, '_set_create_lswitch_proxy'))
|
||||
"%s.%s" % (vmware.SERVICE_PLUGIN_NAME,
|
||||
'_set_create_lswitch_proxy'))
|
||||
mock_proxy.start()
|
||||
|
||||
ext_mgr = ext_mgr or ServiceRouterTestExtensionManager()
|
||||
super(ServiceRouterTest, self).setUp(
|
||||
plugin=SERVICE_PLUGIN_NAME,
|
||||
plugin=vmware.SERVICE_PLUGIN_NAME,
|
||||
service_plugins=service_plugins,
|
||||
ext_mgr=ext_mgr)
|
||||
|
||||
@ -117,7 +116,7 @@ class ServiceRouterTest(test_nsx_plugin.L3NatTest,
|
||||
self.addCleanup(self.fc2.reset_all)
|
||||
|
||||
def tearDown(self):
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = n_manager.NeutronManager.get_plugin()
|
||||
manager = plugin.vcns_driver.task_manager
|
||||
# wait max ~10 seconds for all tasks to be finished
|
||||
for i in range(100):
|
||||
@ -200,7 +199,7 @@ class ServiceRouterTestCase(ServiceRouterTest,
|
||||
with self.router(name=name, admin_state_up=True,
|
||||
tenant_id=tenant_id):
|
||||
# clear router type cache to mimic plugin restart
|
||||
plugin = NeutronManager.get_plugin()
|
||||
plugin = n_manager.NeutronManager.get_plugin()
|
||||
plugin._router_type = {}
|
||||
|
||||
# check an integration lswitch is deleted
|
||||
|
@ -23,8 +23,7 @@ from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.vmware.vshield.common import exceptions as vcns_exc
|
||||
from neutron.plugins.vmware.vshield import vcns_driver
|
||||
from neutron.tests.unit.db.firewall import test_db_firewall
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import VCNS_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.vshield import fake_vcns
|
||||
|
||||
|
||||
@ -33,7 +32,7 @@ _uuid = uuidutils.generate_uuid
|
||||
VSE_ID = 'edge-1'
|
||||
ROUTER_ID = '42f95450-5cc9-44e4-a744-1320e592a9d5'
|
||||
|
||||
VCNS_CONFIG_FILE = get_fake_conf("vcns.ini.test")
|
||||
VCNS_CONFIG_FILE = vmware.get_fake_conf("vcns.ini.test")
|
||||
|
||||
|
||||
class VcnsDriverTestCase(test_db_firewall.FirewallPluginDbTestCase,
|
||||
@ -63,7 +62,7 @@ class VcnsDriverTestCase(test_db_firewall.FirewallPluginDbTestCase,
|
||||
self.config_parse(args=['--config-file', VCNS_CONFIG_FILE])
|
||||
# mock vcns
|
||||
self.fc2 = fake_vcns.FakeVcns(unique_router_name=False)
|
||||
self.mock_vcns = mock.patch(VCNS_NAME, autospec=True)
|
||||
self.mock_vcns = mock.patch(vmware.VCNS_NAME, autospec=True)
|
||||
self.vcns_firewall_patch()
|
||||
|
||||
self.driver = vcns_driver.VcnsDriver(mock.Mock())
|
||||
|
@ -23,8 +23,7 @@ from neutron.plugins.vmware.vshield.common import exceptions as vcns_exc
|
||||
from neutron.plugins.vmware.vshield import vcns_driver
|
||||
from neutron.services.loadbalancer import constants as lb_constants
|
||||
from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import VCNS_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.vshield import fake_vcns
|
||||
|
||||
_uuid = uuidutils.generate_uuid
|
||||
@ -35,7 +34,7 @@ POOL_MAP_INFO = {
|
||||
'edge_id': VSE_ID,
|
||||
'pool_vseid': 'pool-1'}
|
||||
|
||||
VCNS_CONFIG_FILE = get_fake_conf("vcns.ini.test")
|
||||
VCNS_CONFIG_FILE = vmware.get_fake_conf("vcns.ini.test")
|
||||
|
||||
|
||||
class VcnsDriverTestCase(test_db_loadbalancer.LoadBalancerPluginDbTestCase):
|
||||
@ -80,7 +79,7 @@ class VcnsDriverTestCase(test_db_loadbalancer.LoadBalancerPluginDbTestCase):
|
||||
self.config_parse(args=['--config-file', VCNS_CONFIG_FILE])
|
||||
# mock vcns
|
||||
self.fc2 = fake_vcns.FakeVcns(unique_router_name=False)
|
||||
self.mock_vcns = mock.patch(VCNS_NAME, autospec=True)
|
||||
self.mock_vcns = mock.patch(vmware.VCNS_NAME, autospec=True)
|
||||
self.vcns_loadbalancer_patch()
|
||||
|
||||
self.driver = vcns_driver.VcnsDriver(mock.Mock())
|
||||
|
@ -17,17 +17,14 @@ from eventlet import greenthread
|
||||
import mock
|
||||
|
||||
from neutron.plugins.vmware.vshield.common import constants as vcns_const
|
||||
from neutron.plugins.vmware.vshield.common.constants import RouterStatus
|
||||
from neutron.plugins.vmware.vshield.tasks.constants import TaskState
|
||||
from neutron.plugins.vmware.vshield.tasks.constants import TaskStatus
|
||||
from neutron.plugins.vmware.vshield.tasks import constants as ts_const
|
||||
from neutron.plugins.vmware.vshield.tasks import tasks as ts
|
||||
from neutron.plugins.vmware.vshield import vcns_driver
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.vmware import get_fake_conf
|
||||
from neutron.tests.unit.vmware import VCNS_NAME
|
||||
from neutron.tests.unit import vmware
|
||||
from neutron.tests.unit.vmware.vshield import fake_vcns
|
||||
|
||||
VCNS_CONFIG_FILE = get_fake_conf("vcns.ini.test")
|
||||
VCNS_CONFIG_FILE = vmware.get_fake_conf("vcns.ini.test")
|
||||
|
||||
ts.TaskManager.set_default_interval(100)
|
||||
|
||||
@ -67,12 +64,12 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
|
||||
def _exec(task):
|
||||
if not _check_state(task, 1):
|
||||
return TaskStatus.ERROR
|
||||
return ts_const.TaskStatus.ERROR
|
||||
|
||||
if task.userdata['sync_exec']:
|
||||
return TaskStatus.COMPLETED
|
||||
return ts_const.TaskStatus.COMPLETED
|
||||
else:
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
|
||||
def _status(task):
|
||||
if task.userdata['sync_exec']:
|
||||
@ -81,10 +78,10 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
state = task.userdata['state']
|
||||
if state == 3:
|
||||
_check_state(task, 3)
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
else:
|
||||
_check_state(task, 4)
|
||||
return TaskStatus.COMPLETED
|
||||
return ts_const.TaskStatus.COMPLETED
|
||||
|
||||
def _result(task):
|
||||
if task.userdata['sync_exec']:
|
||||
@ -122,7 +119,7 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
|
||||
self.manager.add(task)
|
||||
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
|
||||
self.assertTrue(userdata['result'])
|
||||
|
||||
@ -139,10 +136,10 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
|
||||
def _exec(task):
|
||||
task.userdata['executed'] = True
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
|
||||
def _status(task):
|
||||
return TaskStatus.COMPLETED
|
||||
return ts_const.TaskStatus.COMPLETED
|
||||
|
||||
def _result(task):
|
||||
next_task = task.userdata.get('next')
|
||||
@ -167,7 +164,7 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
for task in tasks:
|
||||
self.manager.add(task)
|
||||
|
||||
last_task.wait(TaskState.RESULT)
|
||||
last_task.wait(ts_const.TaskState.RESULT)
|
||||
|
||||
for task in tasks:
|
||||
self.assertTrue(task.userdata['result'])
|
||||
@ -177,17 +174,17 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
|
||||
def _exec(task):
|
||||
task.userdata['executed'] = True
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
|
||||
def _status(task):
|
||||
for t in tasks:
|
||||
if not t.userdata.get('executed'):
|
||||
t.userdata['resut'] = False
|
||||
return TaskStatus.COMPLETED
|
||||
return ts_const.TaskStatus.COMPLETED
|
||||
|
||||
def _result(task):
|
||||
if (task.userdata.get('result') is None and
|
||||
task.status == TaskStatus.COMPLETED):
|
||||
task.status == ts_const.TaskStatus.COMPLETED):
|
||||
task.userdata['result'] = True
|
||||
else:
|
||||
task.userdata['result'] = False
|
||||
@ -200,7 +197,7 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
self.manager.add(task)
|
||||
|
||||
for task in tasks:
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(task.userdata['result'])
|
||||
|
||||
def _test_task_manager_stop(self, exec_wait=False, result_wait=False,
|
||||
@ -208,11 +205,11 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
def _exec(task):
|
||||
if exec_wait:
|
||||
greenthread.sleep(0.01)
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
|
||||
def _status(task):
|
||||
greenthread.sleep(0.01)
|
||||
return TaskStatus.PENDING
|
||||
return ts_const.TaskStatus.PENDING
|
||||
|
||||
def _result(task):
|
||||
if result_wait:
|
||||
@ -244,7 +241,7 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
|
||||
for res, tasks in alltasks.iteritems():
|
||||
for task in tasks:
|
||||
self.assertEqual(task.status, TaskStatus.ABORT)
|
||||
self.assertEqual(task.status, ts_const.TaskStatus.ABORT)
|
||||
|
||||
def test_task_manager_stop_1(self):
|
||||
self._test_task_manager_stop(True, True, 0)
|
||||
@ -264,7 +261,7 @@ class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
|
||||
while not task.userdata['tested']:
|
||||
greenthread.sleep(0)
|
||||
task.userdata['executing'] = False
|
||||
return TaskStatus.COMPLETED
|
||||
return ts_const.TaskStatus.COMPLETED
|
||||
|
||||
userdata = {
|
||||
'executing': False,
|
||||
@ -317,7 +314,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
self.config_parse(args=['--config-file', VCNS_CONFIG_FILE])
|
||||
|
||||
self.fc = fake_vcns.FakeVcns()
|
||||
self.mock_vcns = mock.patch(VCNS_NAME, autospec=True)
|
||||
self.mock_vcns = mock.patch(vmware.VCNS_NAME, autospec=True)
|
||||
self.vcns_patch()
|
||||
|
||||
self.addCleanup(self.fc.reset_all)
|
||||
@ -338,46 +335,46 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
task = self.vcns_driver.deploy_edge(
|
||||
'router-id', 'myedge', 'internal-network', {}, wait_for_exec=True)
|
||||
self.assertEqual(self.edge_id, 'edge-1')
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
return task
|
||||
|
||||
def edge_deploy_started(self, task):
|
||||
self.edge_id = task.userdata['edge_id']
|
||||
|
||||
def edge_deploy_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['edge_deploy_result'] = True
|
||||
|
||||
def edge_delete_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['edge_delete_result'] = True
|
||||
|
||||
def snat_create_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['snat_create_result'] = True
|
||||
|
||||
def snat_delete_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['snat_delete_result'] = True
|
||||
|
||||
def dnat_create_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['dnat_create_result'] = True
|
||||
|
||||
def dnat_delete_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['dnat_delete_result'] = True
|
||||
|
||||
def nat_update_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['nat_update_result'] = True
|
||||
|
||||
def routes_update_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['routes_update_result'] = True
|
||||
|
||||
def interface_update_result(self, task):
|
||||
if task.status == TaskStatus.COMPLETED:
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['interface_update_result'] = True
|
||||
|
||||
def test_deploy_edge(self):
|
||||
@ -386,8 +383,8 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
'router-id', 'myedge', 'internal-network', jobdata=jobdata,
|
||||
wait_for_exec=True)
|
||||
self.assertEqual(self.edge_id, 'edge-1')
|
||||
task.wait(TaskState.RESULT)
|
||||
self.assertEqual(task.status, TaskStatus.COMPLETED)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertEqual(task.status, ts_const.TaskStatus.COMPLETED)
|
||||
self.assertTrue(jobdata.get('edge_deploy_result'))
|
||||
|
||||
def test_deploy_edge_fail(self):
|
||||
@ -395,14 +392,14 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
'router-1', 'myedge', 'internal-network', {}, wait_for_exec=True)
|
||||
task2 = self.vcns_driver.deploy_edge(
|
||||
'router-2', 'myedge', 'internal-network', {}, wait_for_exec=True)
|
||||
task1.wait(TaskState.RESULT)
|
||||
task2.wait(TaskState.RESULT)
|
||||
self.assertEqual(task2.status, TaskStatus.ERROR)
|
||||
task1.wait(ts_const.TaskState.RESULT)
|
||||
task2.wait(ts_const.TaskState.RESULT)
|
||||
self.assertEqual(task2.status, ts_const.TaskStatus.ERROR)
|
||||
|
||||
def test_get_edge_status(self):
|
||||
self._deploy_edge()
|
||||
status = self.vcns_driver.get_edge_status(self.edge_id)
|
||||
self.assertEqual(status, RouterStatus.ROUTER_STATUS_ACTIVE)
|
||||
self.assertEqual(status, vcns_const.RouterStatus.ROUTER_STATUS_ACTIVE)
|
||||
|
||||
def test_get_edges(self):
|
||||
self._deploy_edge()
|
||||
@ -424,7 +421,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
task = self.vcns_driver.create_dnat_rule(
|
||||
'router-id', edge_id, org, translated, jobdata=jobdata)
|
||||
key = 'dnat_create_result'
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get(key))
|
||||
|
||||
def _delete_nat_rule(self, edge_id, action, addr):
|
||||
@ -437,7 +434,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
task = self.vcns_driver.delete_dnat_rule(
|
||||
'router-id', edge_id, addr, jobdata=jobdata)
|
||||
key = 'dnat_delete_result'
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get(key))
|
||||
|
||||
def _test_create_nat_rule(self, action):
|
||||
@ -508,7 +505,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
]
|
||||
task = self.vcns_driver.update_nat_rules(
|
||||
'router-id', self.edge_id, snats, dnats, jobdata=jobdata)
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get('nat_update_result'))
|
||||
|
||||
natcfg = self.vcns_driver.get_nat_config(self.edge_id)
|
||||
@ -552,7 +549,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
]
|
||||
task = self.vcns_driver.update_routes(
|
||||
'router-id', self.edge_id, '10.0.0.1', routes, jobdata=jobdata)
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get('routes_update_result'))
|
||||
|
||||
def test_update_interface(self):
|
||||
@ -562,7 +559,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
'router-id', self.edge_id, vcns_const.EXTERNAL_VNIC_INDEX,
|
||||
'network-id', address='100.0.0.3', netmask='255.255.255.0',
|
||||
jobdata=jobdata)
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get('interface_update_result'))
|
||||
|
||||
def test_delete_edge(self):
|
||||
@ -570,7 +567,7 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
jobdata = {}
|
||||
task = self.vcns_driver.delete_edge(
|
||||
'router-id', self.edge_id, jobdata=jobdata)
|
||||
task.wait(TaskState.RESULT)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get('edge_delete_result'))
|
||||
|
||||
def test_create_lswitch(self):
|
||||
|
Loading…
Reference in New Issue
Block a user