move content of quantum/fake.py to test_quantum.py in unit testing class (most original content has been removed anyway)

This commit is contained in:
Dan Wendlandt
2011-09-01 15:02:09 -07:00
parent 306fd3b979
commit 9d335c220b

View File

@@ -20,12 +20,82 @@ from nova import db
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova.db.sqlalchemy.session import get_session from nova.db.sqlalchemy.session import get_session
from nova import exception from nova import exception
from nova import ipv6
from nova import log as logging from nova import log as logging
from nova.network.quantum import manager as quantum_manager from nova.network.quantum import manager as quantum_manager
from nova import test from nova import test
from nova import utils
LOG = logging.getLogger('nova.tests.quantum_network') LOG = logging.getLogger('nova.tests.quantum_network')
# this class can be used for unit functional/testing on nova,
# as it does not actually make remote calls to the Quantum service
class FakeQuantumClientConnection(object):
def __init__(self):
self.nets = {}
def get_networks_for_tenant(self, tenant_id):
net_ids = []
for net_id, n in self.nets.items():
if n['tenant-id'] == tenant_id:
net_ids.append(net_id)
return net_ids
def create_network(self, tenant_id, network_name):
uuid = str(utils.gen_uuid())
self.nets[uuid] = {'net-name': network_name,
'tenant-id': tenant_id,
'ports': {}}
return uuid
def delete_network(self, tenant_id, net_id):
if self.nets[net_id]['tenant-id'] == tenant_id:
del self.nets[net_id]
def network_exists(self, tenant_id, net_id):
try:
return self.nets[net_id]['tenant-id'] == tenant_id
except KeyError:
return False
def _confirm_not_attached(self, interface_id):
for n in self.nets.values():
for p in n['ports'].values():
if p['attachment-id'] == interface_id:
raise Exception(_("interface '%s' is already attached" %
interface_id))
def create_and_attach_port(self, tenant_id, net_id, interface_id):
if not self.network_exists(tenant_id, net_id):
raise Exception(
_("network %(net_id)s does not exist for tenant %(tenant_id)"
% locals()))
self._confirm_not_attached(interface_id)
uuid = str(utils.gen_uuid())
self.nets[net_id]['ports'][uuid] = \
{"port-state": "ACTIVE",
"attachment-id": interface_id}
def detach_and_delete_port(self, tenant_id, net_id, port_id):
if not self.network_exists(tenant_id, net_id):
raise exception.NotFound(
_("network %(net_id)s does not exist "
"for tenant %(tenant_id)s" % locals()))
del self.nets[net_id]['ports'][port_id]
def get_port_by_attachment(self, tenant_id, attachment_id):
for net_id, n in self.nets.items():
if n['tenant-id'] == tenant_id:
for port_id, p in n['ports'].items():
if p['attachment-id'] == attachment_id:
return (net_id, port_id)
return (None, None)
networks = [{'label': 'project1-net1', networks = [{'label': 'project1-net1',
'injected': False, 'injected': False,
'multi_host': False, 'multi_host': False,
@@ -230,8 +300,10 @@ class QuantumNovaIPAMTestCase(QuantumTestCaseBase, test.TestCase):
def setUp(self): def setUp(self):
super(QuantumNovaIPAMTestCase, self).setUp() super(QuantumNovaIPAMTestCase, self).setUp()
self.net_man = quantum_manager.QuantumManager( \
ipam_lib="nova.network.quantum.nova_ipam_lib") self.net_man = quantum_manager.QuantumManager(
ipam_lib="nova.network.quantum.nova_ipam_lib",
q_conn=FakeQuantumClientConnection())
# Tests seem to create some networks by default, which # Tests seem to create some networks by default, which
# we don't want. So we delete them. # we don't want. So we delete them.