Merge trunk.

This commit is contained in:
Soren Hansen
2010-10-12 22:04:46 +02:00
4 changed files with 78 additions and 31 deletions

View File

@@ -89,11 +89,16 @@ class VpnCommands(object):
def list(self): def list(self):
"""Print a listing of the VPNs for all projects.""" """Print a listing of the VPNs for all projects."""
print "%-12s\t" % 'project', print "%-12s\t" % 'project',
print "%-12s\t" % 'ip:port', print "%-20s\t" % 'ip:port',
print "%s" % 'state' print "%s" % 'state'
for project in self.manager.get_projects(): for project in self.manager.get_projects():
print "%-12s\t" % project.name, print "%-12s\t" % project.name,
print "%s:%s\t" % (project.vpn_ip, project.vpn_port),
try:
s = "%s:%s" % (project.vpn_ip, project.vpn_port)
except exception.NotFound:
s = "None"
print "%-20s\t" % s,
vpn = self._vpn_for(project.id) vpn = self._vpn_for(project.id)
if vpn: if vpn:

View File

@@ -655,7 +655,10 @@ class AuthManager(object):
zippy.writestr(FLAGS.credential_key_file, private_key) zippy.writestr(FLAGS.credential_key_file, private_key)
zippy.writestr(FLAGS.credential_cert_file, signed_cert) zippy.writestr(FLAGS.credential_cert_file, signed_cert)
try:
(vpn_ip, vpn_port) = self.get_project_vpn_data(project) (vpn_ip, vpn_port) = self.get_project_vpn_data(project)
except exception.NotFound:
vpn_ip = None
if vpn_ip: if vpn_ip:
configfile = open(FLAGS.vpn_client_template, "r") configfile = open(FLAGS.vpn_client_template, "r")
s = string.Template(configfile.read()) s = string.Template(configfile.read())

View File

@@ -14,7 +14,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from xml.dom.minidom import parseString from xml.etree.ElementTree import fromstring as xml_to_tree
from xml.dom.minidom import parseString as xml_to_dom
from nova import db from nova import db
from nova import flags from nova import flags
@@ -22,39 +23,64 @@ from nova import test
from nova.api import context from nova.api import context
from nova.api.ec2 import cloud from nova.api.ec2 import cloud
from nova.auth import manager from nova.auth import manager
# Needed to get FLAGS.instances_path defined:
from nova.compute import manager as compute_manager
from nova.virt import libvirt_conn from nova.virt import libvirt_conn
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
class LibvirtConnTestCase(test.TrialTestCase): class LibvirtConnTestCase(test.TrialTestCase):
def bitrot_test_get_uri_and_template(self): def setUp(self):
class MockDataModel(object): self.manager = manager.AuthManager()
def __getitem__(self, name): self.user = self.manager.create_user('fake', 'fake', 'fake', admin=True)
return self.datamodel[name] self.project = self.manager.create_project('fake', 'fake', 'fake')
FLAGS.instances_path = ''
def __init__(self): def test_get_uri_and_template(self):
self.datamodel = { 'name' : 'i-cafebabe', ip = '10.11.12.13'
instance = { 'internal_id' : '1',
'memory_kb' : '1024000', 'memory_kb' : '1024000',
'basepath' : '/some/path', 'basepath' : '/some/path',
'bridge_name' : 'br100', 'bridge_name' : 'br100',
'mac_address' : '02:12:34:46:56:67', 'mac_address' : '02:12:34:46:56:67',
'vcpus' : 2, 'vcpus' : 2,
'project_id' : None } 'project_id' : 'fake',
'bridge' : 'br101',
'instance_type' : 'm1.small'}
instance_ref = db.instance_create(None, instance)
network_ref = db.project_get_network(None, self.project.id)
fixed_ip = { 'address' : ip,
'network_id' : network_ref['id'] }
fixed_ip_ref = db.fixed_ip_create(None, fixed_ip)
db.fixed_ip_update(None, ip, { 'allocated' : True,
'instance_id' : instance_ref['id'] })
type_uri_map = { 'qemu' : ('qemu:///system', type_uri_map = { 'qemu' : ('qemu:///system',
[lambda s: '<domain type=\'qemu\'>' in s, [(lambda t: t.find('.').get('type'), 'qemu'),
lambda s: 'type>hvm</type' in s, (lambda t: t.find('./os/type').text, 'hvm'),
lambda s: 'emulator>/usr/bin/kvm' not in s]), (lambda t: t.find('./devices/emulator'), None)]),
'kvm' : ('qemu:///system', 'kvm' : ('qemu:///system',
[lambda s: '<domain type=\'kvm\'>' in s, [(lambda t: t.find('.').get('type'), 'kvm'),
lambda s: 'type>hvm</type' in s, (lambda t: t.find('./os/type').text, 'hvm'),
lambda s: 'emulator>/usr/bin/qemu<' not in s]), (lambda t: t.find('./devices/emulator'), None)]),
'uml' : ('uml:///system', 'uml' : ('uml:///system',
[lambda s: '<domain type=\'uml\'>' in s, [(lambda t: t.find('.').get('type'), 'uml'),
lambda s: 'type>uml</type' in s]), (lambda t: t.find('./os/type').text, 'uml')]),
} }
common_checks = [(lambda t: t.find('.').tag, 'domain'),
(lambda t: \
t.find('./devices/interface/filterref/parameter') \
.get('name'), 'IP'),
(lambda t: \
t.find('./devices/interface/filterref/parameter') \
.get('value'), '10.11.12.13')]
for (libvirt_type,(expected_uri, checks)) in type_uri_map.iteritems(): for (libvirt_type,(expected_uri, checks)) in type_uri_map.iteritems():
FLAGS.libvirt_type = libvirt_type FLAGS.libvirt_type = libvirt_type
conn = libvirt_conn.LibvirtConnection(True) conn = libvirt_conn.LibvirtConnection(True)
@@ -62,9 +88,17 @@ class LibvirtConnTestCase(test.TrialTestCase):
uri, template = conn.get_uri_and_template() uri, template = conn.get_uri_and_template()
self.assertEquals(uri, expected_uri) self.assertEquals(uri, expected_uri)
for i, check in enumerate(checks): xml = conn.to_xml(instance_ref)
xml = conn.to_xml(MockDataModel()) tree = xml_to_tree(xml)
self.assertTrue(check(xml), '%s failed check %d' % (xml, i)) for i, (check, expected_result) in enumerate(checks):
self.assertEqual(check(tree),
expected_result,
'%s failed check %d' % (xml, i))
for i, (check, expected_result) in enumerate(common_checks):
self.assertEqual(check(tree),
expected_result,
'%s failed common check %d' % (xml, i))
# Deliberately not just assigning this string to FLAGS.libvirt_uri and # Deliberately not just assigning this string to FLAGS.libvirt_uri and
# checking against that later on. This way we make sure the # checking against that later on. This way we make sure the
@@ -78,6 +112,10 @@ class LibvirtConnTestCase(test.TrialTestCase):
self.assertEquals(uri, testuri) self.assertEquals(uri, testuri)
def tearDown(self):
self.manager.delete_project(self.project)
self.manager.delete_user(self.user)
class NWFilterTestCase(test.TrialTestCase): class NWFilterTestCase(test.TrialTestCase):
def setUp(self): def setUp(self):
super(NWFilterTestCase, self).setUp() super(NWFilterTestCase, self).setUp()
@@ -118,7 +156,7 @@ class NWFilterTestCase(test.TrialTestCase):
xml = self.fw.security_group_to_nwfilter_xml(security_group.id) xml = self.fw.security_group_to_nwfilter_xml(security_group.id)
dom = parseString(xml) dom = xml_to_dom(xml)
self.assertEqual(dom.firstChild.tagName, 'filter') self.assertEqual(dom.firstChild.tagName, 'filter')
rules = dom.getElementsByTagName('rule') rules = dom.getElementsByTagName('rule')
@@ -172,7 +210,7 @@ class NWFilterTestCase(test.TrialTestCase):
self.recursive_depends[f] = [] self.recursive_depends[f] = []
def _filterDefineXMLMock(xml): def _filterDefineXMLMock(xml):
dom = parseString(xml) dom = xml_to_dom(xml)
name = dom.firstChild.getAttribute('name') name = dom.firstChild.getAttribute('name')
self.recursive_depends[name] = [] self.recursive_depends[name] = []
for f in dom.getElementsByTagName('filterref'): for f in dom.getElementsByTagName('filterref'):

View File

@@ -63,6 +63,7 @@ from nova.tests.rpc_unittest import *
from nova.tests.scheduler_unittest import * from nova.tests.scheduler_unittest import *
from nova.tests.service_unittest import * from nova.tests.service_unittest import *
from nova.tests.validator_unittest import * from nova.tests.validator_unittest import *
from nova.tests.virt_unittest import *
from nova.tests.volume_unittest import * from nova.tests.volume_unittest import *
from nova.tests.virt_unittest import * from nova.tests.virt_unittest import *