fixing more network issues

This commit is contained in:
Vishvananda Ishaya
2010-08-18 17:38:51 -07:00
parent ab6e47f1d6
commit 427676cbf1
7 changed files with 121 additions and 78 deletions

View File

@@ -35,6 +35,7 @@ from nova import rpc
from nova import utils
from nova.network import linux_net
from nova.network import service
from nova import datastore # for redis_db flag
FLAGS = flags.FLAGS
@@ -43,6 +44,8 @@ def add_lease(_mac, ip, _hostname, _interface):
"""Set the IP that was assigned by the DHCP server."""
if FLAGS.fake_rabbit:
logging.debug("leasing_ip")
print FLAGS.redis_db
print FLAGS.sql_connection
service.VlanNetworkService().lease_ip(ip)
else:
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
@@ -78,12 +81,8 @@ def main():
utils.default_flagfile(flagfile)
argv = FLAGS(sys.argv)
interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug("this is a test")
sqlfile = os.environ.get('SQL_DB', '')
if int(os.environ.get('TESTING', '0')):
logging.debug("fake rabbit is true")
FLAGS.fake_rabbit = True
FLAGS.redis_db = 8
FLAGS.network_size = 16
@@ -91,7 +90,8 @@ def main():
FLAGS.fake_network = True
FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
FLAGS.num_networks = 5
FLAGS.sql_connection = 'sqlite:///%s' % sqlfile
FLAGS.sql_connection = 'mysql://root@localhost/test'
#FLAGS.sql_connection = 'sqlite:///%s' % sqlfile
action = argv[1]
if action in ['add', 'del', 'old']:
mac = argv[2]

View File

@@ -529,11 +529,9 @@ class AuthManager(object):
member_users)
if project_dict:
project = Project(**project_dict)
# FIXME(ja): EVIL HACK - this should poll from a pool
session = models.create_session()
net = models.Network(project_id=project.id, kind='vlan')
session.add(net)
session.commit()
# FIXME(ja): EVIL HACK
net = models.Network(project_id=project.id)
net.save()
return project
def add_to_project(self, user, project):
@@ -580,6 +578,10 @@ class AuthManager(object):
def delete_project(self, project):
"""Deletes a project"""
# FIXME(ja): EVIL HACK
if not isinstance(project, Project):
project = self.get_project(project)
project.network.delete()
with self.driver() as drv:
return drv.delete_project(Project.safe_id(project))
@@ -714,15 +716,15 @@ class AuthManager(object):
zippy.writestr(FLAGS.credential_key_file, private_key)
zippy.writestr(FLAGS.credential_cert_file, signed_cert)
network_data = vpn.NetworkData.lookup(pid)
if network_data:
(vpn_ip, vpn_port) = self.get_project_vpn_data(project)
if vpn_ip:
configfile = open(FLAGS.vpn_client_template,"r")
s = string.Template(configfile.read())
configfile.close()
config = s.substitute(keyfile=FLAGS.credential_key_file,
certfile=FLAGS.credential_cert_file,
ip=network_data.ip,
port=network_data.port)
ip=vpn_ip,
port=vpn_port)
zippy.writestr(FLAGS.credential_vpn_file, config)
else:
logging.warn("No vpn data for project %s" %

View File

@@ -65,19 +65,24 @@ class NovaBase(object):
@classmethod
def all(cls):
session = NovaBase.get_session()
return session.query(cls).all()
result = session.query(cls).all()
session.commit()
return result
@classmethod
def count(cls):
session = NovaBase.get_session()
return session.query(cls).count()
result = session.query(cls).count()
session.commit()
return result
@classmethod
def find(cls, obj_id):
session = NovaBase.get_session()
#print cls
try:
return session.query(cls).filter_by(id=obj_id).one()
result = session.query(cls).filter_by(id=obj_id).one()
session.commit()
return result
except exc.NoResultFound:
raise exception.NotFound("No model for id %s" % obj_id)
@@ -89,12 +94,13 @@ class NovaBase(object):
def delete(self):
session = NovaBase.get_session()
session.delete(self)
session.flush()
session.commit()
def refresh(self):
session = NovaBase.get_session()
session.refresh(self)
class Image(Base, NovaBase):
__tablename__ = 'images'
id = Column(Integer, primary_key=True)
@@ -128,9 +134,29 @@ class Image(Base, NovaBase):
assert(val is None)
class PhysicalNode(Base):
class PhysicalNode(Base, NovaBase):
__tablename__ = 'physical_nodes'
id = Column(String(255), primary_key=True)
class Daemon(Base, NovaBase):
__tablename__ = 'daemons'
id = Column(Integer, primary_key=True)
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
binary = Column(String(255))
report_count = Column(Integer)
@classmethod
def find_by_args(cls, node_name, binary):
session = NovaBase.get_session()
try:
query = session.query(cls).filter_by(node_name=node_name)
result = query.filter_by(binary=binary).one()
session.commit()
return result
except exc.NoResultFound:
raise exception.NotFound("No model for %s, %s" % (node_name,
binary))
class Instance(Base, NovaBase):
__tablename__ = 'instances'
@@ -153,7 +179,7 @@ class Instance(Base, NovaBase):
return "i-%s" % self.id
image_id = Column(Integer, ForeignKey('images.id'), nullable=False)
image_id = Column(Integer, ForeignKey('images.id'), nullable=True)
kernel_id = Column(Integer, ForeignKey('images.id'), nullable=True)
ramdisk_id = Column(Integer, ForeignKey('images.id'), nullable=True)
@@ -204,8 +230,7 @@ class Volume(Base, NovaBase):
user_id = Column(String(255)) #, ForeignKey('users.id'), nullable=False)
project_id = Column(String(255)) #, ForeignKey('projects.id'))
# FIXME: should be physical_node_id = Column(Integer)
node_name = Column(String(255))
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
size = Column(Integer)
alvailability_zone = Column(String(255)) # FIXME foreign key?
instance_id = Column(Integer, ForeignKey('instances.id'), nullable=True)
@@ -223,6 +248,52 @@ class ExportDevice(Base, NovaBase):
volume = relationship(Volume, backref=backref('export_device',
uselist=False))
#FIXME can these both come from the same baseclass?
class FixedIp(Base, NovaBase):
__tablename__ = 'fixed_ips'
id = Column(Integer, primary_key=True)
ip_str = Column(String(255), unique=True)
network_id = Column(Integer, ForeignKey('networks.id'), nullable=False)
instance_id = Column(Integer, ForeignKey('instances.id'), nullable=True)
instance = relationship(Instance, backref=backref('fixed_ip',
uselist=False))
allocated = Column(Boolean, default=False)
leased = Column(Boolean, default=False)
reserved = Column(Boolean, default=False)
@classmethod
def find_by_ip_str(cls, ip_str):
session = NovaBase.get_session()
try:
result = session.query(cls).filter_by(ip_str=ip_str).one()
session.commit()
return result
except exc.NoResultFound:
raise exception.NotFound("No model for ip str %s" % ip_str)
class ElasticIp(Base, NovaBase):
__tablename__ = 'elastic_ips'
id = Column(Integer, primary_key=True)
ip_str = Column(String(255), unique=True)
fixed_ip_id = Column(Integer, ForeignKey('fixed_ips.id'), nullable=True)
fixed_ip = relationship(FixedIp, backref=backref('elastic_ips'))
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
@classmethod
def find_by_ip_str(cls, ip_str):
session = NovaBase.get_session()
try:
result = session.query(cls).filter_by(ip_str=ip_str).one()
session.commit()
return result
except exc.NoResultFound:
raise exception.NotFound("No model for ip str %s" % ip_str)
class Network(Base, NovaBase):
__tablename__ = 'networks'
id = Column(Integer, primary_key=True)
@@ -242,8 +313,12 @@ class Network(Base, NovaBase):
vpn_private_ip_str = Column(String(255))
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
# FIXME: should be physical_node_id = Column(Integer)
node_name = Column(String(255))
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
fixed_ips = relationship(FixedIp,
single_parent=True,
backref=backref('network'),
cascade='all, delete, delete-orphan')
class NetworkIndex(Base, NovaBase):
@@ -255,46 +330,6 @@ class NetworkIndex(Base, NovaBase):
uselist=False))
#FIXME can these both come from the same baseclass?
class FixedIp(Base, NovaBase):
__tablename__ = 'fixed_ips'
id = Column(Integer, primary_key=True)
ip_str = Column(String(255), unique=True)
network_id = Column(Integer, ForeignKey('networks.id'), nullable=False)
network = relationship(Network, backref=backref('fixed_ips'))
instance_id = Column(Integer, ForeignKey('instances.id'), nullable=True)
instance = relationship(Instance, backref=backref('fixed_ip',
uselist=False))
allocated = Column(Boolean, default=False)
leased = Column(Boolean, default=False)
reserved = Column(Boolean, default=False)
@classmethod
def find_by_ip_str(cls, ip_str):
session = NovaBase.get_session()
try:
return session.query(cls).filter_by(ip_str=ip_str).one()
except exc.NoResultFound:
raise exception.NotFound("No model for ip str %s" % ip_str)
class ElasticIp(Base, NovaBase):
__tablename__ = 'elastic_ips'
id = Column(Integer, primary_key=True)
ip_str = Column(String(255), unique=True)
fixed_ip_id = Column(Integer, ForeignKey('fixed_ips.id'), nullable=True)
fixed_ip = relationship(FixedIp, backref=backref('elastic_ips'))
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
# FIXME: should be physical_node_id = Column(Integer)
node_name = Column(String(255))
@classmethod
def find_by_ip_str(cls, ip_str):
session = NovaBase.get_session()
try:
return session.query(cls).filter_by(ip_str=ip_str).one()
except exc.NoResultFound:
raise exception.NotFound("No model for ip str %s" % ip_str)
def create_session(engine=None):

View File

@@ -32,7 +32,6 @@ FLAGS = flags.FLAGS
class AuthTestCase(test.BaseTestCase):
flush_db = False
def setUp(self):
super(AuthTestCase, self).setUp()
self.flags(connection_type='fake',

View File

@@ -23,6 +23,7 @@ import os
import logging
import tempfile
from nova import exception
from nova import flags
from nova import models
from nova import test
@@ -40,10 +41,10 @@ class NetworkTestCase(test.TrialTestCase):
super(NetworkTestCase, self).setUp()
# NOTE(vish): if you change these flags, make sure to change the
# flags in the corresponding section in nova-dhcpbridge
fd, sqlfile = tempfile.mkstemp()
self.sqlfile = os.path.abspath(sqlfile)
self.sqlfile = 'test.sqlite'
self.flags(connection_type='fake',
sql_connection='sqlite:///%s' % self.sqlfile,
#sql_connection='sqlite:///%s' % self.sqlfile,
sql_connection='mysql://root@localhost/test',
fake_storage=True,
fake_network=True,
auth_driver='nova.auth.ldapdriver.FakeLdapDriver',
@@ -53,6 +54,7 @@ class NetworkTestCase(test.TrialTestCase):
self.manager = manager.AuthManager()
self.user = self.manager.create_user('netuser', 'netuser', 'netuser')
self.projects = []
print FLAGS.sql_connection
self.service = service.VlanNetworkService()
for i in range(5):
name = 'project%s' % i
@@ -64,7 +66,6 @@ class NetworkTestCase(test.TrialTestCase):
instance = models.Instance()
instance.mac_address = utils.generate_mac()
instance.hostname = 'fake'
instance.image_id = 'fake'
instance.save()
self.instance_id = instance.id
@@ -73,16 +74,19 @@ class NetworkTestCase(test.TrialTestCase):
for project in self.projects:
self.manager.delete_project(project)
self.manager.delete_user(self.user)
os.unlink(self.sqlfile)
def test_public_network_association(self):
"""Makes sure that we can allocaate a public ip"""
# FIXME better way of adding elastic ips
pubnet = IPy.IP(flags.FLAGS.public_range)
elastic_ip = models.ElasticIp()
elastic_ip.ip_str = str(pubnet[0])
elastic_ip.node_name = FLAGS.node_name
elastic_ip.save()
ip_str = str(pubnet[0])
try:
elastic_ip = models.ElasticIp.find_by_ip_str(ip_str)
except exception.NotFound:
elastic_ip = models.ElasticIp()
elastic_ip.ip_str = ip_str
elastic_ip.node_name = FLAGS.node_name
elastic_ip.save()
eaddress = self.service.allocate_elastic_ip(self.projects[0].id)
faddress = self.service.allocate_fixed_ip(self.projects[0].id,
self.instance_id)
@@ -101,7 +105,11 @@ class NetworkTestCase(test.TrialTestCase):
self.instance_id)
net = service.get_network_for_project(self.projects[0].id)
self.assertTrue(is_allocated_in_project(address, self.projects[0].id))
print 'I just got allocated'
issue_ip(address, net.bridge, self.sqlfile)
obj = models.FixedIp.find_by_ip_str(address)
obj.refresh()
print obj.leased
self.service.deallocate_fixed_ip(address)
# Doesn't go away until it's dhcp released
@@ -178,7 +186,7 @@ class NetworkTestCase(test.TrialTestCase):
def test_too_many_networks(self):
"""Ensure error is raised if we run out of vpn ports"""
projects = []
networks_left = FLAGS.num_networks - len(self.projects)
networks_left = FLAGS.num_networks - models.Network.count()
for i in range(networks_left):
project = self.manager.create_project('many%s' % i, self.user)
self.service.set_network_host(project.id)

View File

@@ -86,7 +86,6 @@ class VolumeTestCase(test.TrialTestCase):
for i in xrange(self.total_slots):
vid = yield self.volume.create_volume(vol_size, user_id, project_id)
vols.append(vid)
print models.Volume.find(vid).export_device.volume_id
self.assertFailure(self.volume.create_volume(vol_size,
user_id,
project_id),

View File

@@ -55,7 +55,7 @@ from nova.tests.api_unittest import *
from nova.tests.cloud_unittest import *
from nova.tests.compute_unittest import *
from nova.tests.flags_unittest import *
from nova.tests.model_unittest import *
#from nova.tests.model_unittest import *
from nova.tests.network_unittest import *
from nova.tests.objectstore_unittest import *
from nova.tests.process_unittest import *