merged trunk

This commit is contained in:
Vishvananda Ishaya
2011-09-21 02:00:07 -07:00
20 changed files with 542 additions and 2142 deletions

View File

@@ -12,6 +12,7 @@ Armando Migliaccio <Armando.Migliaccio@eu.citrix.com>
Arvind Somya <asomya@cisco.com> Arvind Somya <asomya@cisco.com>
Bilal Akhtar <bilalakhtar@ubuntu.com> Bilal Akhtar <bilalakhtar@ubuntu.com>
Brad Hall <brad@nicira.com> Brad Hall <brad@nicira.com>
Brad McConnell <bmcconne@rackspace.com>
Brian Lamar <brian.lamar@rackspace.com> Brian Lamar <brian.lamar@rackspace.com>
Brian Schott <bschott@isi.edu> Brian Schott <bschott@isi.edu>
Brian Waldon <brian.waldon@rackspace.com> Brian Waldon <brian.waldon@rackspace.com>

View File

@@ -37,7 +37,7 @@ include nova/tests/bundle/1mb.manifest.xml
include nova/tests/bundle/1mb.no_kernel_or_ramdisk.manifest.xml include nova/tests/bundle/1mb.no_kernel_or_ramdisk.manifest.xml
include nova/tests/bundle/1mb.part.0 include nova/tests/bundle/1mb.part.0
include nova/tests/bundle/1mb.part.1 include nova/tests/bundle/1mb.part.1
include nova/tests/public_key/* include nova/tests/api/ec2/public_key/*
include nova/tests/db/nova.austin.sqlite include nova/tests/db/nova.austin.sqlite
include plugins/xenapi/README include plugins/xenapi/README
include plugins/xenapi/etc/xapi.d/plugins/objectstore include plugins/xenapi/etc/xapi.d/plugins/objectstore

View File

@@ -61,6 +61,7 @@ import math
import netaddr import netaddr
from optparse import OptionParser from optparse import OptionParser
import os import os
import StringIO
import sys import sys
import time import time
@@ -274,6 +275,58 @@ class ShellCommands(object):
arguments: path""" arguments: path"""
exec(compile(open(path).read(), path, 'exec'), locals(), globals()) exec(compile(open(path).read(), path, 'exec'), locals(), globals())
@args('--filename', dest='filename', metavar='<path>', default=False,
help='Export file path')
def export(self, filename):
"""Export Nova users into a file that can be consumed by Keystone"""
def create_file(filename):
data = generate_data()
with open(filename, 'w') as f:
f.write(data.getvalue())
def tenants(data, am):
for project in am.get_projects():
print >> data, ("tenant add '%s'" %
(project.name))
for u in project.member_ids:
user = am.get_user(u)
print >> data, ("user add '%s' '%s' '%s'" %
(user.name, user.access, project.name))
print >> data, ("credentials add 'EC2' '%s:%s' '%s' '%s'" %
(user.access, project.id, user.secret, project.id))
def roles(data, am):
for role in am.get_roles():
print >> data, ("role add '%s'" % (role))
def grant_roles(data, am):
roles = am.get_roles()
for project in am.get_projects():
for u in project.member_ids:
user = am.get_user(u)
for role in db.user_get_roles_for_project(ctxt, u,
project.id):
print >> data, ("role grant '%s', '%s', '%s')," %
(user.name, role, project.name))
print >> data
def generate_data():
data = StringIO.StringIO()
am = manager.AuthManager()
tenants(data, am)
roles(data, am)
grant_roles(data, am)
data.seek(0)
return data
ctxt = context.get_admin_context()
if filename:
create_file(filename)
else:
data = generate_data()
print data.getvalue()
class RoleCommands(object): class RoleCommands(object):
"""Class for managing roles.""" """Class for managing roles."""
@@ -685,7 +738,7 @@ class NetworkCommands(object):
help='Multi host') help='Multi host')
@args('--dns1', dest="dns1", metavar="<DNS Address>", help='First DNS') @args('--dns1', dest="dns1", metavar="<DNS Address>", help='First DNS')
@args('--dns2', dest="dns2", metavar="<DNS Address>", help='Second DNS') @args('--dns2', dest="dns2", metavar="<DNS Address>", help='Second DNS')
@args('--uuid', dest="net_uuid", metavar="<network uuid>", @args('--uuid', dest="uuid", metavar="<network uuid>",
help='Network UUID') help='Network UUID')
@args('--project_id', dest="project_id", metavar="<project id>", @args('--project_id', dest="project_id", metavar="<project id>",
help='Project id') help='Project id')
@@ -710,22 +763,12 @@ class NetworkCommands(object):
bridge_required = ['nova.network.manager.FlatManager', bridge_required = ['nova.network.manager.FlatManager',
'nova.network.manager.FlatDHCPManager'] 'nova.network.manager.FlatDHCPManager']
if FLAGS.network_manager in bridge_required: if FLAGS.network_manager in bridge_required:
# TODO(tr3buchet) - swap print statement and following line for raise exception.NetworkNotCreated(req='--bridge')
# raise statement in diablo 4
print _('--bridge parameter required or FLAG '
'flat_network_bridge must be set to create networks\n'
'WARNING! ACHTUNG! Setting the bridge to br100 '
'automatically is deprecated and will be removed in '
'Diablo milestone 4. Prepare yourself accordingly.')
time.sleep(10)
bridge = 'br100'
#raise exception.NetworkNotCreated(req='--bridge')
bridge_interface = bridge_interface or FLAGS.flat_interface or \ bridge_interface = bridge_interface or FLAGS.flat_interface or \
FLAGS.vlan_interface FLAGS.vlan_interface
if not bridge_interface: if not bridge_interface:
interface_required = ['nova.network.manager.FlatDHCPManager', interface_required = ['nova.network.manager.VlanManager']
'nova.network.manager.VlanManager']
if FLAGS.network_manager in interface_required: if FLAGS.network_manager in interface_required:
raise exception.NetworkNotCreated(req='--bridge_interface') raise exception.NetworkNotCreated(req='--bridge_interface')

View File

@@ -107,10 +107,13 @@ if __name__ == "__main__":
else: else:
with_auth = auth.VNCNovaAuthMiddleware(with_logging) with_auth = auth.VNCNovaAuthMiddleware(with_logging)
server = wsgi.Server("VNC Proxy", wsgi_server = wsgi.Server("VNC Proxy",
with_auth, with_auth,
host=FLAGS.vncproxy_host, host=FLAGS.vncproxy_host,
port=FLAGS.vncproxy_port) port=FLAGS.vncproxy_port)
server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host) wsgi_server.start_tcp(handle_flash_socket_policy,
service.serve(server) 843,
host=FLAGS.vncproxy_host)
server = service.Service.create(binary='nova-vncproxy')
service.serve(wsgi_server, server)
service.wait() service.wait()

View File

@@ -421,6 +421,9 @@ DEFINE_string('root_helper', 'sudo',
DEFINE_bool('use_ipv6', False, 'use ipv6') DEFINE_bool('use_ipv6', False, 'use ipv6')
DEFINE_integer('password_length', 12,
'Length of generated instance admin passwords')
DEFINE_bool('monkey_patch', False, DEFINE_bool('monkey_patch', False,
'Whether to log monkey patching') 'Whether to log monkey patching')

View File

@@ -20,8 +20,8 @@ customize the behavior: filter_hosts() and weigh_hosts(). The default
behavior is to simply select all hosts and weight them the same. behavior is to simply select all hosts and weight them the same.
""" """
import operator
import json import json
import operator
import M2Crypto import M2Crypto

View File

@@ -27,6 +27,8 @@ from nova.scheduler import abstract_scheduler
from nova.scheduler import host_filter from nova.scheduler import host_filter
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
flags.DEFINE_boolean('spread_first', False,
'Use a spread-first zone scheduler strategy')
LOG = logging.getLogger('nova.scheduler.base_scheduler') LOG = logging.getLogger('nova.scheduler.base_scheduler')
@@ -68,4 +70,9 @@ class BaseScheduler(abstract_scheduler.AbstractScheduler):
if num_instances > 0: if num_instances > 0:
instances.extend(hosts[:num_instances]) instances.extend(hosts[:num_instances])
# Adjust the weights for a spread-first strategy
if FLAGS.spread_first:
for i, host in enumerate(hosts):
host['weight'] = i + 1
return instances return instances

View File

@@ -1 +0,0 @@
1c:87:d1:d9:32:fd:62:3c:78:2b:c0:ad:c0:15:88:df

View File

@@ -1 +0,0 @@
ssh-dss AAAAB3NzaC1kc3MAAACBAMGJlY9XEIm2X234pdO5yFWMp2JuOQx8U0E815IVXhmKxYCBK9ZakgZOIQmPbXoGYyV+mziDPp6HJ0wKYLQxkwLEFr51fAZjWQvRss0SinURRuLkockDfGFtD4pYJthekr/rlqMKlBSDUSpGq8jUWW60UJ18FGooFpxR7ESqQRx/AAAAFQC96LRglaUeeP+E8U/yblEJocuiWwAAAIA3XiMR8Skiz/0aBm5K50SeQznQuMJTyzt9S9uaz5QZWiFu69hOyGSFGw8fqgxEkXFJIuHobQQpGYQubLW0NdaYRqyE/Vud3JUJUb8Texld6dz8vGemyB5d1YvtSeHIo8/BGv2msOqR3u5AZTaGCBD9DhpSGOKHEdNjTtvpPd8S8gAAAIBociGZ5jf09iHLVENhyXujJbxfGRPsyNTyARJfCOGl0oFV6hEzcQyw8U/ePwjgvjc2UizMWLl8tsb2FXKHRdc2v+ND3Us+XqKQ33X3ADP4FZ/+Oj213gMyhCmvFTP0u5FmHog9My4CB7YcIWRuUR42WlhQ2IfPvKwUoTk3R+T6Og== www-data@mk

View File

@@ -515,7 +515,7 @@ class ApiEc2TestCase(test.TestCase):
# be good enough for that. # be good enough for that.
for group in rv: for group in rv:
if group.name == security_group_name: if group.name == security_group_name:
self.assertEquals(len(group.rules), 1) self.assertEquals(len(group.rules), 3)
self.assertEquals(len(group.rules[0].grants), 1) self.assertEquals(len(group.rules[0].grants), 1)
self.assertEquals(str(group.rules[0].grants[0]), '%s-%s' % self.assertEquals(str(group.rules[0].grants[0]), '%s-%s' %
(other_security_group_name, 'fake')) (other_security_group_name, 'fake'))

File diff suppressed because it is too large Load Diff

View File

@@ -21,22 +21,24 @@ Tests For Compute
""" """
from nova import compute from nova import compute
from nova.compute import instance_types
from nova.compute import manager as compute_manager
from nova.compute import power_state
from nova.compute import vm_states
from nova import context from nova import context
from nova import db from nova import db
from nova.db.sqlalchemy import models
from nova.db.sqlalchemy import api as sqlalchemy_api
from nova import exception from nova import exception
from nova import flags from nova import flags
import nova.image.fake
from nova import log as logging from nova import log as logging
from nova import rpc from nova import rpc
from nova import test from nova import test
from nova import utils from nova import utils
from nova.compute import instance_types
from nova.compute import manager as compute_manager
from nova.compute import power_state
from nova.compute import vm_states
from nova.db.sqlalchemy import models
from nova.image import fake as fake_image
from nova.notifier import test_notifier from nova.notifier import test_notifier
from nova.tests import fake_network
LOG = logging.getLogger('nova.tests.compute') LOG = logging.getLogger('nova.tests.compute')
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
@@ -74,7 +76,7 @@ class ComputeTestCase(test.TestCase):
def fake_show(meh, context, id): def fake_show(meh, context, id):
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
self.stubs.Set(nova.image.fake._FakeImageService, 'show', fake_show) self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
def _create_instance(self, params=None): def _create_instance(self, params=None):
"""Create a test instance""" """Create a test instance"""
@@ -174,6 +176,20 @@ class ComputeTestCase(test.TestCase):
self.assertEqual(pre_build_len, self.assertEqual(pre_build_len,
len(db.instance_get_all(context.get_admin_context()))) len(db.instance_get_all(context.get_admin_context())))
def test_create_instance_with_img_ref_associates_config_drive(self):
"""Make sure create associates a config drive."""
instance_id = self._create_instance(params={'config_drive': '1234', })
try:
self.compute.run_instance(self.context, instance_id)
instances = db.instance_get_all(context.get_admin_context())
instance = instances[0]
self.assertTrue(instance.config_drive)
finally:
db.instance_destroy(self.context, instance_id)
def test_create_instance_associates_config_drive(self): def test_create_instance_associates_config_drive(self):
"""Make sure create associates a config drive.""" """Make sure create associates a config drive."""
@@ -300,11 +316,20 @@ class ComputeTestCase(test.TestCase):
self.compute.resume_instance(self.context, instance_id) self.compute.resume_instance(self.context, instance_id)
self.compute.terminate_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id)
def test_reboot(self): def test_soft_reboot(self):
"""Ensure instance can be rebooted""" """Ensure instance can be soft rebooted"""
instance_id = self._create_instance() instance_id = self._create_instance()
reboot_type = "SOFT"
self.compute.run_instance(self.context, instance_id) self.compute.run_instance(self.context, instance_id)
self.compute.reboot_instance(self.context, instance_id) self.compute.reboot_instance(self.context, instance_id, reboot_type)
self.compute.terminate_instance(self.context, instance_id)
def test_hard_reboot(self):
"""Ensure instance can be hard rebooted"""
instance_id = self._create_instance()
reboot_type = "HARD"
self.compute.run_instance(self.context, instance_id)
self.compute.reboot_instance(self.context, instance_id, reboot_type)
self.compute.terminate_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id)
def test_set_admin_password(self): def test_set_admin_password(self):
@@ -638,7 +663,6 @@ class ComputeTestCase(test.TestCase):
dbmock = self.mox.CreateMock(db) dbmock = self.mox.CreateMock(db)
dbmock.instance_get(c, i_id).AndReturn(instance_ref) dbmock.instance_get(c, i_id).AndReturn(instance_ref)
dbmock.instance_get_fixed_addresses(c, i_id).AndReturn(None)
self.compute.db = dbmock self.compute.db = dbmock
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -648,6 +672,9 @@ class ComputeTestCase(test.TestCase):
def test_pre_live_migration_instance_has_volume(self): def test_pre_live_migration_instance_has_volume(self):
"""Confirm setup_compute_volume is called when volume is mounted.""" """Confirm setup_compute_volume is called when volume is mounted."""
def fake_nw_info(*args, **kwargs):
return [(0, {'ips':['dummy']})]
i_ref = self._get_dummy_instance() i_ref = self._get_dummy_instance()
c = context.get_admin_context() c = context.get_admin_context()
@@ -657,13 +684,13 @@ class ComputeTestCase(test.TestCase):
drivermock = self.mox.CreateMock(self.compute_driver) drivermock = self.mox.CreateMock(self.compute_driver)
dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref)
dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy')
for i in range(len(i_ref['volumes'])): for i in range(len(i_ref['volumes'])):
vid = i_ref['volumes'][i]['id'] vid = i_ref['volumes'][i]['id']
volmock.setup_compute_volume(c, vid).InAnyOrder('g1') volmock.setup_compute_volume(c, vid).InAnyOrder('g1')
drivermock.plug_vifs(i_ref, []) drivermock.plug_vifs(i_ref, fake_nw_info())
drivermock.ensure_filtering_rules_for_instance(i_ref, []) drivermock.ensure_filtering_rules_for_instance(i_ref, fake_nw_info())
self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info)
self.compute.db = dbmock self.compute.db = dbmock
self.compute.volume_manager = volmock self.compute.volume_manager = volmock
self.compute.driver = drivermock self.compute.driver = drivermock
@@ -674,6 +701,9 @@ class ComputeTestCase(test.TestCase):
def test_pre_live_migration_instance_has_no_volume(self): def test_pre_live_migration_instance_has_no_volume(self):
"""Confirm log meg when instance doesn't mount any volumes.""" """Confirm log meg when instance doesn't mount any volumes."""
def fake_nw_info(*args, **kwargs):
return [(0, {'ips':['dummy']})]
i_ref = self._get_dummy_instance() i_ref = self._get_dummy_instance()
i_ref['volumes'] = [] i_ref['volumes'] = []
c = context.get_admin_context() c = context.get_admin_context()
@@ -683,12 +713,12 @@ class ComputeTestCase(test.TestCase):
drivermock = self.mox.CreateMock(self.compute_driver) drivermock = self.mox.CreateMock(self.compute_driver)
dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref)
dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy')
self.mox.StubOutWithMock(compute_manager.LOG, 'info') self.mox.StubOutWithMock(compute_manager.LOG, 'info')
compute_manager.LOG.info(_("%s has no volume."), i_ref['hostname']) compute_manager.LOG.info(_("%s has no volume."), i_ref['hostname'])
drivermock.plug_vifs(i_ref, []) drivermock.plug_vifs(i_ref, fake_nw_info())
drivermock.ensure_filtering_rules_for_instance(i_ref, []) drivermock.ensure_filtering_rules_for_instance(i_ref, fake_nw_info())
self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info)
self.compute.db = dbmock self.compute.db = dbmock
self.compute.driver = drivermock self.compute.driver = drivermock
@@ -702,6 +732,8 @@ class ComputeTestCase(test.TestCase):
It retries and raise exception when timeout exceeded. It retries and raise exception when timeout exceeded.
""" """
def fake_nw_info(*args, **kwargs):
return [(0, {'ips':['dummy']})]
i_ref = self._get_dummy_instance() i_ref = self._get_dummy_instance()
c = context.get_admin_context() c = context.get_admin_context()
@@ -713,13 +745,13 @@ class ComputeTestCase(test.TestCase):
drivermock = self.mox.CreateMock(self.compute_driver) drivermock = self.mox.CreateMock(self.compute_driver)
dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref)
dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy')
for i in range(len(i_ref['volumes'])): for i in range(len(i_ref['volumes'])):
volmock.setup_compute_volume(c, i_ref['volumes'][i]['id']) volmock.setup_compute_volume(c, i_ref['volumes'][i]['id'])
for i in range(FLAGS.live_migration_retry_count): for i in range(FLAGS.live_migration_retry_count):
drivermock.plug_vifs(i_ref, []).\ drivermock.plug_vifs(i_ref, fake_nw_info()).\
AndRaise(exception.ProcessExecutionError()) AndRaise(exception.ProcessExecutionError())
self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info)
self.compute.db = dbmock self.compute.db = dbmock
self.compute.network_manager = netmock self.compute.network_manager = netmock
self.compute.volume_manager = volmock self.compute.volume_manager = volmock
@@ -993,190 +1025,19 @@ class ComputeTestCase(test.TestCase):
db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id2)
db.instance_destroy(c, instance_id3) db.instance_destroy(c, instance_id3)
def test_get_by_fixed_ip(self):
"""Test getting 1 instance by Fixed IP"""
c = context.get_admin_context()
instance_id1 = self._create_instance()
instance_id2 = self._create_instance({'id': 20})
instance_id3 = self._create_instance({'id': 30})
vif_ref1 = db.virtual_interface_create(c,
{'address': '12:34:56:78:90:12',
'instance_id': instance_id1,
'network_id': 1})
vif_ref2 = db.virtual_interface_create(c,
{'address': '90:12:34:56:78:90',
'instance_id': instance_id2,
'network_id': 1})
db.fixed_ip_create(c,
{'address': '1.1.1.1',
'instance_id': instance_id1,
'virtual_interface_id': vif_ref1['id']})
db.fixed_ip_create(c,
{'address': '1.1.2.1',
'instance_id': instance_id2,
'virtual_interface_id': vif_ref2['id']})
# regex not allowed
instances = self.compute_api.get_all(c,
search_opts={'fixed_ip': '.*'})
self.assertEqual(len(instances), 0)
instances = self.compute_api.get_all(c,
search_opts={'fixed_ip': '1.1.3.1'})
self.assertEqual(len(instances), 0)
instances = self.compute_api.get_all(c,
search_opts={'fixed_ip': '1.1.1.1'})
self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id1)
instances = self.compute_api.get_all(c,
search_opts={'fixed_ip': '1.1.2.1'})
self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id2)
db.virtual_interface_delete(c, vif_ref1['id'])
db.virtual_interface_delete(c, vif_ref2['id'])
db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2)
def test_get_all_by_ip_regexp(self):
"""Test searching by Floating and Fixed IP"""
c = context.get_admin_context()
instance_id1 = self._create_instance({'display_name': 'woot'})
instance_id2 = self._create_instance({
'display_name': 'woo',
'id': 20})
instance_id3 = self._create_instance({
'display_name': 'not-woot',
'id': 30})
vif_ref1 = db.virtual_interface_create(c,
{'address': '12:34:56:78:90:12',
'instance_id': instance_id1,
'network_id': 1})
vif_ref2 = db.virtual_interface_create(c,
{'address': '90:12:34:56:78:90',
'instance_id': instance_id2,
'network_id': 1})
vif_ref3 = db.virtual_interface_create(c,
{'address': '34:56:78:90:12:34',
'instance_id': instance_id3,
'network_id': 1})
db.fixed_ip_create(c,
{'address': '1.1.1.1',
'instance_id': instance_id1,
'virtual_interface_id': vif_ref1['id']})
db.fixed_ip_create(c,
{'address': '1.1.2.1',
'instance_id': instance_id2,
'virtual_interface_id': vif_ref2['id']})
fix_addr = db.fixed_ip_create(c,
{'address': '1.1.3.1',
'instance_id': instance_id3,
'virtual_interface_id': vif_ref3['id']})
fix_ref = db.fixed_ip_get_by_address(c, fix_addr)
flo_ref = db.floating_ip_create(c,
{'address': '10.0.0.2',
'fixed_ip_id': fix_ref['id']})
# ends up matching 2nd octet here.. so all 3 match
instances = self.compute_api.get_all(c,
search_opts={'ip': '.*\.1'})
self.assertEqual(len(instances), 3)
instances = self.compute_api.get_all(c,
search_opts={'ip': '1.*'})
self.assertEqual(len(instances), 3)
instances = self.compute_api.get_all(c,
search_opts={'ip': '.*\.1.\d+$'})
self.assertEqual(len(instances), 1)
instance_ids = [instance.id for instance in instances]
self.assertTrue(instance_id1 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'ip': '.*\.2.+'})
self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id2)
instances = self.compute_api.get_all(c,
search_opts={'ip': '10.*'})
self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id3)
db.virtual_interface_delete(c, vif_ref1['id'])
db.virtual_interface_delete(c, vif_ref2['id'])
db.virtual_interface_delete(c, vif_ref3['id'])
db.floating_ip_destroy(c, '10.0.0.2')
db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2)
db.instance_destroy(c, instance_id3)
def test_get_all_by_ipv6_regexp(self):
"""Test searching by IPv6 address"""
c = context.get_admin_context()
instance_id1 = self._create_instance({'display_name': 'woot'})
instance_id2 = self._create_instance({
'display_name': 'woo',
'id': 20})
instance_id3 = self._create_instance({
'display_name': 'not-woot',
'id': 30})
vif_ref1 = db.virtual_interface_create(c,
{'address': '12:34:56:78:90:12',
'instance_id': instance_id1,
'network_id': 1})
vif_ref2 = db.virtual_interface_create(c,
{'address': '90:12:34:56:78:90',
'instance_id': instance_id2,
'network_id': 1})
vif_ref3 = db.virtual_interface_create(c,
{'address': '34:56:78:90:12:34',
'instance_id': instance_id3,
'network_id': 1})
# This will create IPv6 addresses of:
# 1: fd00::1034:56ff:fe78:9012
# 20: fd00::9212:34ff:fe56:7890
# 30: fd00::3656:78ff:fe90:1234
instances = self.compute_api.get_all(c,
search_opts={'ip6': '.*1034.*'})
self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id1)
instances = self.compute_api.get_all(c,
search_opts={'ip6': '^fd00.*'})
self.assertEqual(len(instances), 3)
instance_ids = [instance.id for instance in instances]
self.assertTrue(instance_id1 in instance_ids)
self.assertTrue(instance_id2 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'ip6': '^.*12.*34.*'})
self.assertEqual(len(instances), 2)
instance_ids = [instance.id for instance in instances]
self.assertTrue(instance_id2 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
db.virtual_interface_delete(c, vif_ref1['id'])
db.virtual_interface_delete(c, vif_ref2['id'])
db.virtual_interface_delete(c, vif_ref3['id'])
db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2)
db.instance_destroy(c, instance_id3)
def test_get_all_by_multiple_options_at_once(self): def test_get_all_by_multiple_options_at_once(self):
"""Test searching by multiple options at once""" """Test searching by multiple options at once"""
c = context.get_admin_context() c = context.get_admin_context()
instance_id1 = self._create_instance({'display_name': 'woot'}) network_manager = fake_network.FakeNetworkManager()
self.stubs.Set(self.compute_api.network_api,
'get_instance_uuids_by_ip_filter',
network_manager.get_instance_uuids_by_ip_filter)
self.stubs.Set(network_manager.db,
'instance_get_id_to_uuid_mapping',
db.instance_get_id_to_uuid_mapping)
instance_id1 = self._create_instance({'display_name': 'woot',
'id': 0})
instance_id2 = self._create_instance({ instance_id2 = self._create_instance({
'display_name': 'woo', 'display_name': 'woo',
'id': 20}) 'id': 20})
@@ -1184,36 +1045,6 @@ class ComputeTestCase(test.TestCase):
'display_name': 'not-woot', 'display_name': 'not-woot',
'id': 30}) 'id': 30})
vif_ref1 = db.virtual_interface_create(c,
{'address': '12:34:56:78:90:12',
'instance_id': instance_id1,
'network_id': 1})
vif_ref2 = db.virtual_interface_create(c,
{'address': '90:12:34:56:78:90',
'instance_id': instance_id2,
'network_id': 1})
vif_ref3 = db.virtual_interface_create(c,
{'address': '34:56:78:90:12:34',
'instance_id': instance_id3,
'network_id': 1})
db.fixed_ip_create(c,
{'address': '1.1.1.1',
'instance_id': instance_id1,
'virtual_interface_id': vif_ref1['id']})
db.fixed_ip_create(c,
{'address': '1.1.2.1',
'instance_id': instance_id2,
'virtual_interface_id': vif_ref2['id']})
fix_addr = db.fixed_ip_create(c,
{'address': '1.1.3.1',
'instance_id': instance_id3,
'virtual_interface_id': vif_ref3['id']})
fix_ref = db.fixed_ip_get_by_address(c, fix_addr)
flo_ref = db.floating_ip_create(c,
{'address': '10.0.0.2',
'fixed_ip_id': fix_ref['id']})
# ip ends up matching 2nd octet here.. so all 3 match ip # ip ends up matching 2nd octet here.. so all 3 match ip
# but 'name' only matches one # but 'name' only matches one
instances = self.compute_api.get_all(c, instances = self.compute_api.get_all(c,
@@ -1221,18 +1052,18 @@ class ComputeTestCase(test.TestCase):
self.assertEqual(len(instances), 1) self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id3) self.assertEqual(instances[0].id, instance_id3)
# ip ends up matching any ip with a '2' in it.. so instance # ip ends up matching any ip with a '1' in the last octet..
# 2 and 3.. but name should only match #2 # so instance 1 and 3.. but name should only match #1
# but 'name' only matches one # but 'name' only matches one
instances = self.compute_api.get_all(c, instances = self.compute_api.get_all(c,
search_opts={'ip': '.*2', 'name': '^woo.*'}) search_opts={'ip': '.*\.1$', 'name': '^woo.*'})
self.assertEqual(len(instances), 1) self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id2) self.assertEqual(instances[0].id, instance_id1)
# same as above but no match on name (name matches instance_id1 # same as above but no match on name (name matches instance_id1
# but the ip query doesn't # but the ip query doesn't
instances = self.compute_api.get_all(c, instances = self.compute_api.get_all(c,
search_opts={'ip': '.*2.*', 'name': '^woot.*'}) search_opts={'ip': '.*\.2$', 'name': '^woot.*'})
self.assertEqual(len(instances), 0) self.assertEqual(len(instances), 0)
# ip matches all 3... ipv6 matches #2+#3...name matches #3 # ip matches all 3... ipv6 matches #2+#3...name matches #3
@@ -1243,10 +1074,6 @@ class ComputeTestCase(test.TestCase):
self.assertEqual(len(instances), 1) self.assertEqual(len(instances), 1)
self.assertEqual(instances[0].id, instance_id3) self.assertEqual(instances[0].id, instance_id3)
db.virtual_interface_delete(c, vif_ref1['id'])
db.virtual_interface_delete(c, vif_ref2['id'])
db.virtual_interface_delete(c, vif_ref3['id'])
db.floating_ip_destroy(c, '10.0.0.2')
db.instance_destroy(c, instance_id1) db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id2)
db.instance_destroy(c, instance_id3) db.instance_destroy(c, instance_id3)
@@ -1554,12 +1381,16 @@ class ComputeTestCase(test.TestCase):
db.block_device_mapping_destroy(self.context, bdm['id']) db.block_device_mapping_destroy(self.context, bdm['id'])
self.compute.terminate_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id)
def test_ephemeral_size(self): def test_volume_size(self):
local_size = 2 local_size = 2
inst_type = {'local_gb': local_size} swap_size = 3
self.assertEqual(self.compute_api._ephemeral_size(inst_type, inst_type = {'local_gb': local_size, 'swap': swap_size}
self.assertEqual(self.compute_api._volume_size(inst_type,
'ephemeral0'), 'ephemeral0'),
local_size) local_size)
self.assertEqual(self.compute_api._ephemeral_size(inst_type, self.assertEqual(self.compute_api._volume_size(inst_type,
'ephemeral1'), 'ephemeral1'),
0) 0)
self.assertEqual(self.compute_api._volume_size(inst_type,
'swap'),
swap_size)

View File

@@ -18,6 +18,8 @@
"""Unit tests for the DB API""" """Unit tests for the DB API"""
import datetime
from nova import test from nova import test
from nova import context from nova import context
from nova import db from nova import db
@@ -92,6 +94,32 @@ class DbApiTestCase(test.TestCase):
db.instance_destroy(self.context, inst1.id) db.instance_destroy(self.context, inst1.id)
result = db.instance_get_all_by_filters(self.context.elevated(), {}) result = db.instance_get_all_by_filters(self.context.elevated(), {})
self.assertEqual(2, len(result)) self.assertEqual(2, len(result))
self.assertEqual(result[0].id, inst2.id) self.assertIn(inst1.id, [result[0].id, result[1].id])
self.assertEqual(result[1].id, inst1.id) self.assertIn(inst2.id, [result[0].id, result[1].id])
self.assertTrue(result[1].deleted) if inst1.id == result[0].id:
self.assertTrue(result[0].deleted)
else:
self.assertTrue(result[1].deleted)
def test_migration_get_all_unconfirmed(self):
ctxt = context.get_admin_context()
# Ensure no migrations are returned.
results = db.migration_get_all_unconfirmed(ctxt, 10)
self.assertEqual(0, len(results))
# Ensure one migration older than 10 seconds is returned.
updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00)
values = {"status": "FINISHED", "updated_at": updated_at}
migration = db.migration_create(ctxt, values)
results = db.migration_get_all_unconfirmed(ctxt, 10)
self.assertEqual(1, len(results))
db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
# Ensure the new migration is not returned.
updated_at = datetime.datetime.utcnow()
values = {"status": "FINISHED", "updated_at": updated_at}
migration = db.migration_create(ctxt, values)
results = db.migration_get_all_unconfirmed(ctxt, 10)
self.assertEqual(0, len(results))
db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})

View File

@@ -30,7 +30,7 @@ from nova import test
from nova import volume from nova import volume
from nova import utils from nova import utils
from nova.api import direct from nova.api import direct
from nova.tests import test_cloud from nova.tests.api.ec2 import test_cloud
class ArbitraryObject(object): class ArbitraryObject(object):

View File

@@ -35,61 +35,56 @@ from nova import utils
from nova.api.ec2 import cloud from nova.api.ec2 import cloud
from nova.compute import power_state from nova.compute import power_state
from nova.compute import vm_states from nova.compute import vm_states
from nova.virt import driver
from nova.virt.libvirt import connection from nova.virt.libvirt import connection
from nova.virt.libvirt import firewall from nova.virt.libvirt import firewall
from nova.tests import fake_network
libvirt = None libvirt = None
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
_fake_network_info = fake_network.fake_get_instance_nw_info
_ipv4_like = fake_network.ipv4_like
def _concurrency(wait, done, target): def _concurrency(wait, done, target):
wait.wait() wait.wait()
done.send() done.send()
def _create_network_info(count=1, ipv6=None): class FakeVirDomainSnapshot(object):
if ipv6 is None:
ipv6 = FLAGS.use_ipv6 def __init__(self, dom=None):
fake = 'fake' self.dom = dom
fake_ip = '10.11.12.13'
fake_ip_2 = '0.0.0.1' def delete(self, flags):
fake_ip_3 = '0.0.0.1' pass
fake_vlan = 100
fake_bridge_interface = 'eth0'
network = {'bridge': fake,
'cidr': fake_ip,
'cidr_v6': fake_ip,
'gateway_v6': fake,
'vlan': fake_vlan,
'bridge_interface': fake_bridge_interface}
mapping = {'mac': fake,
'dhcp_server': '10.0.0.1',
'gateway': fake,
'gateway6': fake,
'ips': [{'ip': fake_ip}, {'ip': fake_ip}]}
if ipv6:
mapping['ip6s'] = [{'ip': fake_ip},
{'ip': fake_ip_2},
{'ip': fake_ip_3}]
return [(network, mapping) for x in xrange(0, count)]
def _setup_networking(instance_id, ip='1.2.3.4', mac='56:12:12:12:12:12'): class FakeVirtDomain(object):
ctxt = context.get_admin_context()
network_ref = db.project_get_networks(ctxt,
'fake',
associate=True)[0]
vif = {'address': mac,
'network_id': network_ref['id'],
'instance_id': instance_id}
vif_ref = db.virtual_interface_create(ctxt, vif)
fixed_ip = {'address': ip, def __init__(self, fake_xml=None):
'network_id': network_ref['id'], if fake_xml:
'virtual_interface_id': vif_ref['id']} self._fake_dom_xml = fake_xml
db.fixed_ip_create(ctxt, fixed_ip) else:
db.fixed_ip_update(ctxt, ip, {'allocated': True, self._fake_dom_xml = """
'instance_id': instance_id}) <domain type='kvm'>
<devices>
<disk type='file'>
<source file='filename'/>
</disk>
</devices>
</domain>
"""
def snapshotCreateXML(self, *args):
return FakeVirDomainSnapshot(self)
def createWithFlags(self, launch_flags):
pass
def XMLDesc(self, *args):
return self._fake_dom_xml
class CacheConcurrencyTestCase(test.TestCase): class CacheConcurrencyTestCase(test.TestCase):
@@ -163,7 +158,6 @@ class LibvirtConnTestCase(test.TestCase):
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.flags(instances_path='') self.flags(instances_path='')
self.call_libvirt_dependant_setup = False self.call_libvirt_dependant_setup = False
self.test_ip = '10.11.12.13'
test_instance = {'memory_kb': '1024000', test_instance = {'memory_kb': '1024000',
'basepath': '/some/path', 'basepath': '/some/path',
@@ -194,70 +188,24 @@ class LibvirtConnTestCase(test.TestCase):
# A fake libvirt.virConnect # A fake libvirt.virConnect
class FakeLibvirtConnection(object): class FakeLibvirtConnection(object):
pass def defineXML(self, xml):
return FakeVirtDomain()
# A fake connection.IptablesFirewallDriver
class FakeIptablesFirewallDriver(object):
def __init__(self, **kwargs):
pass
def setattr(self, key, val):
self.__setattr__(key, val)
# A fake VIF driver
class FakeVIFDriver(object):
def __init__(self, **kwargs):
pass
def setattr(self, key, val):
self.__setattr__(key, val)
def plug(self, instance, network, mapping):
return {
'id': 'fake',
'bridge_name': 'fake',
'mac_address': 'fake',
'ip_address': 'fake',
'dhcp_server': 'fake',
'extra_params': 'fake',
}
# Creating mocks # Creating mocks
fake = FakeLibvirtConnection() fake = FakeLibvirtConnection()
fakeip = FakeIptablesFirewallDriver
fakevif = FakeVIFDriver()
# Customizing above fake if necessary # Customizing above fake if necessary
for key, val in kwargs.items(): for key, val in kwargs.items():
fake.__setattr__(key, val) fake.__setattr__(key, val)
# Inevitable mocks for connection.LibvirtConnection self.flags(image_service='nova.image.fake.FakeImageService')
self.mox.StubOutWithMock(connection.utils, 'import_class') fw_driver = "nova.tests.fake_network.FakeIptablesFirewallDriver"
connection.utils.import_class(mox.IgnoreArg()).AndReturn(fakeip) self.flags(firewall_driver=fw_driver)
self.mox.StubOutWithMock(connection.utils, 'import_object') self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver")
connection.utils.import_object(mox.IgnoreArg()).AndReturn(fakevif)
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
connection.LibvirtConnection._conn = fake connection.LibvirtConnection._conn = fake
def fake_lookup(self, instance_name): def fake_lookup(self, instance_name):
class FakeVirtDomain(object):
def snapshotCreateXML(self, *args):
return None
def XMLDesc(self, *args):
return """
<domain type='kvm'>
<devices>
<disk type='file'>
<source file='filename'/>
</disk>
</devices>
</domain>
"""
return FakeVirtDomain() return FakeVirtDomain()
def fake_execute(self, *args): def fake_execute(self, *args):
@@ -277,12 +225,12 @@ class LibvirtConnTestCase(test.TestCase):
instance_ref = db.instance_create(self.context, self.test_instance) instance_ref = db.instance_create(self.context, self.test_instance)
result = conn._prepare_xml_info(instance_ref, result = conn._prepare_xml_info(instance_ref,
_create_network_info(), _fake_network_info(self.stubs, 1),
False) False)
self.assertTrue(len(result['nics']) == 1) self.assertTrue(len(result['nics']) == 1)
result = conn._prepare_xml_info(instance_ref, result = conn._prepare_xml_info(instance_ref,
_create_network_info(2), _fake_network_info(self.stubs, 2),
False) False)
self.assertTrue(len(result['nics']) == 2) self.assertTrue(len(result['nics']) == 2)
@@ -321,7 +269,7 @@ class LibvirtConnTestCase(test.TestCase):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
self._check_xml_and_container(instance_data) self._check_xml_and_container(instance_data)
def test_snapshot(self): def test_snapshot_in_raw_format(self):
if not self.lazy_load_library_exists(): if not self.lazy_load_library_exists():
return return
@@ -354,6 +302,44 @@ class LibvirtConnTestCase(test.TestCase):
snapshot = image_service.show(context, recv_meta['id']) snapshot = image_service.show(context, recv_meta['id'])
self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['properties']['image_state'], 'available')
self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['status'], 'active')
self.assertEquals(snapshot['disk_format'], 'raw')
self.assertEquals(snapshot['name'], snapshot_name)
def test_snapshot_in_qcow2_format(self):
if not self.lazy_load_library_exists():
return
self.flags(image_service='nova.image.fake.FakeImageService')
self.flags(snapshot_image_format='qcow2')
# Start test
image_service = utils.import_object(FLAGS.image_service)
# Assuming that base image already exists in image_service
instance_ref = db.instance_create(self.context, self.test_instance)
properties = {'instance_id': instance_ref['id'],
'user_id': str(self.context.user_id)}
snapshot_name = 'test-snap'
sent_meta = {'name': snapshot_name, 'is_public': False,
'status': 'creating', 'properties': properties}
# Create new image. It will be updated in snapshot method
# To work with it from snapshot, the single image_service is needed
recv_meta = image_service.create(context, sent_meta)
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
self.mox.StubOutWithMock(connection.utils, 'execute')
connection.utils.execute = self.fake_execute
self.mox.ReplayAll()
conn = connection.LibvirtConnection(False)
conn.snapshot(self.context, instance_ref, recv_meta['id'])
snapshot = image_service.show(context, recv_meta['id'])
self.assertEquals(snapshot['properties']['image_state'], 'available')
self.assertEquals(snapshot['status'], 'active')
self.assertEquals(snapshot['disk_format'], 'qcow2')
self.assertEquals(snapshot['name'], snapshot_name) self.assertEquals(snapshot['name'], snapshot_name)
def test_snapshot_no_image_architecture(self): def test_snapshot_no_image_architecture(self):
@@ -407,7 +393,7 @@ class LibvirtConnTestCase(test.TestCase):
def test_multi_nic(self): def test_multi_nic(self):
instance_data = dict(self.test_instance) instance_data = dict(self.test_instance)
network_info = _create_network_info(2) network_info = _fake_network_info(self.stubs, 2)
conn = connection.LibvirtConnection(True) conn = connection.LibvirtConnection(True)
instance_ref = db.instance_create(self.context, instance_data) instance_ref = db.instance_create(self.context, instance_data)
xml = conn.to_xml(instance_ref, network_info, False) xml = conn.to_xml(instance_ref, network_info, False)
@@ -417,15 +403,14 @@ class LibvirtConnTestCase(test.TestCase):
parameters = interfaces[0].findall('./filterref/parameter') parameters = interfaces[0].findall('./filterref/parameter')
self.assertEquals(interfaces[0].get('type'), 'bridge') self.assertEquals(interfaces[0].get('type'), 'bridge')
self.assertEquals(parameters[0].get('name'), 'IP') self.assertEquals(parameters[0].get('name'), 'IP')
self.assertEquals(parameters[0].get('value'), '10.11.12.13') self.assertTrue(_ipv4_like(parameters[0].get('value'), '192.168'))
self.assertEquals(parameters[1].get('name'), 'DHCPSERVER') self.assertEquals(parameters[1].get('name'), 'DHCPSERVER')
self.assertEquals(parameters[1].get('value'), '10.0.0.1') self.assertTrue(_ipv4_like(parameters[1].get('value'), '192.168.*.1'))
def _check_xml_and_container(self, instance): def _check_xml_and_container(self, instance):
user_context = context.RequestContext(self.user_id, user_context = context.RequestContext(self.user_id,
self.project_id) self.project_id)
instance_ref = db.instance_create(user_context, instance) instance_ref = db.instance_create(user_context, instance)
_setup_networking(instance_ref['id'], self.test_ip)
self.flags(libvirt_type='lxc') self.flags(libvirt_type='lxc')
conn = connection.LibvirtConnection(True) conn = connection.LibvirtConnection(True)
@@ -433,7 +418,7 @@ class LibvirtConnTestCase(test.TestCase):
uri = conn.get_uri() uri = conn.get_uri()
self.assertEquals(uri, 'lxc:///') self.assertEquals(uri, 'lxc:///')
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
xml = conn.to_xml(instance_ref, network_info) xml = conn.to_xml(instance_ref, network_info)
tree = xml_to_tree(xml) tree = xml_to_tree(xml)
@@ -457,8 +442,6 @@ class LibvirtConnTestCase(test.TestCase):
network_ref = db.project_get_networks(context.get_admin_context(), network_ref = db.project_get_networks(context.get_admin_context(),
self.project_id)[0] self.project_id)[0]
_setup_networking(instance_ref['id'], self.test_ip)
type_uri_map = {'qemu': ('qemu:///system', type_uri_map = {'qemu': ('qemu:///system',
[(lambda t: t.find('.').get('type'), 'qemu'), [(lambda t: t.find('.').get('type'), 'qemu'),
(lambda t: t.find('./os/type').text, 'hvm'), (lambda t: t.find('./os/type').text, 'hvm'),
@@ -504,9 +487,11 @@ class LibvirtConnTestCase(test.TestCase):
common_checks = [ common_checks = [
(lambda t: t.find('.').tag, 'domain'), (lambda t: t.find('.').tag, 'domain'),
(lambda t: t.find(parameter).get('name'), 'IP'), (lambda t: t.find(parameter).get('name'), 'IP'),
(lambda t: t.find(parameter).get('value'), '10.11.12.13'), (lambda t: _ipv4_like(t.find(parameter).get('value'), '192.168'),
True),
(lambda t: t.findall(parameter)[1].get('name'), 'DHCPSERVER'), (lambda t: t.findall(parameter)[1].get('name'), 'DHCPSERVER'),
(lambda t: t.findall(parameter)[1].get('value'), '10.0.0.1'), (lambda t: _ipv4_like(t.findall(parameter)[1].get('value'),
'192.168.*.1'), True),
(lambda t: t.find('./devices/serial/source').get( (lambda t: t.find('./devices/serial/source').get(
'path').split('/')[1], 'console.log'), 'path').split('/')[1], 'console.log'),
(lambda t: t.find('./memory').text, '2097152')] (lambda t: t.find('./memory').text, '2097152')]
@@ -531,7 +516,7 @@ class LibvirtConnTestCase(test.TestCase):
uri = conn.get_uri() uri = conn.get_uri()
self.assertEquals(uri, expected_uri) self.assertEquals(uri, expected_uri)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
xml = conn.to_xml(instance_ref, network_info, rescue) xml = conn.to_xml(instance_ref, network_info, rescue)
tree = xml_to_tree(xml) tree = xml_to_tree(xml)
for i, (check, expected_result) in enumerate(checks): for i, (check, expected_result) in enumerate(checks):
@@ -646,7 +631,7 @@ class LibvirtConnTestCase(test.TestCase):
self.create_fake_libvirt_mock() self.create_fake_libvirt_mock()
instance_ref = db.instance_create(self.context, self.test_instance) instance_ref = db.instance_create(self.context, self.test_instance)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
# Start test # Start test
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -743,7 +728,7 @@ class LibvirtConnTestCase(test.TestCase):
# qemu-img should be mockd since test environment might not have # qemu-img should be mockd since test environment might not have
# large disk space. # large disk space.
self.mox.StubOutWithMock(utils, "execute") self.mox.StubOutWithMock(utils, "execute")
utils.execute('sudo', 'qemu-img', 'create', '-f', 'raw', utils.execute('qemu-img', 'create', '-f', 'raw',
'%s/%s/disk' % (tmpdir, instance_ref.name), '10G') '%s/%s/disk' % (tmpdir, instance_ref.name), '10G')
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -795,7 +780,7 @@ class LibvirtConnTestCase(test.TestCase):
os.path.getsize("/test/disk").AndReturn(10 * 1024 * 1024 * 1024) os.path.getsize("/test/disk").AndReturn(10 * 1024 * 1024 * 1024)
# another is qcow image, so qemu-img should be mocked. # another is qcow image, so qemu-img should be mocked.
self.mox.StubOutWithMock(utils, "execute") self.mox.StubOutWithMock(utils, "execute")
utils.execute('sudo', 'qemu-img', 'info', '/test/disk.local').\ utils.execute('qemu-img', 'info', '/test/disk.local').\
AndReturn((ret, '')) AndReturn((ret, ''))
self.mox.ReplayAll() self.mox.ReplayAll()
@@ -830,7 +815,7 @@ class LibvirtConnTestCase(test.TestCase):
conn.firewall_driver.setattr('setup_basic_filtering', fake_none) conn.firewall_driver.setattr('setup_basic_filtering', fake_none)
conn.firewall_driver.setattr('prepare_instance_filter', fake_none) conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
try: try:
conn.spawn(self.context, instance, network_info) conn.spawn(self.context, instance, network_info)
@@ -840,8 +825,6 @@ class LibvirtConnTestCase(test.TestCase):
shutil.rmtree(os.path.join(FLAGS.instances_path, instance.name)) shutil.rmtree(os.path.join(FLAGS.instances_path, instance.name))
shutil.rmtree(os.path.join(FLAGS.instances_path, '_base')) shutil.rmtree(os.path.join(FLAGS.instances_path, '_base'))
self.assertTrue(count)
def test_get_host_ip_addr(self): def test_get_host_ip_addr(self):
conn = connection.LibvirtConnection(False) conn = connection.LibvirtConnection(False)
ip = conn.get_host_ip_addr() ip = conn.get_host_ip_addr()
@@ -883,6 +866,50 @@ class LibvirtConnTestCase(test.TestCase):
_assert_volume_in_mapping('sdg', False) _assert_volume_in_mapping('sdg', False)
_assert_volume_in_mapping('sdh1', False) _assert_volume_in_mapping('sdh1', False)
def test_reboot_signature(self):
"""Test that libvirt driver method sig matches interface"""
def fake_reboot_with_correct_sig(ignore, instance,
network_info, reboot_type):
pass
def fake_destroy(instance, network_info, cleanup=False):
pass
def fake_plug_vifs(instance, network_info):
pass
def fake_create_new_domain(xml):
return
def fake_none(self, instance):
return
instance = db.instance_create(self.context, self.test_instance)
network_info = _fake_network_info(self.stubs, 1)
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
conn = connection.LibvirtConnection(False)
self.stubs.Set(conn, 'destroy', fake_destroy)
self.stubs.Set(conn, 'plug_vifs', fake_plug_vifs)
self.stubs.Set(conn.firewall_driver,
'setup_basic_filtering',
fake_none)
self.stubs.Set(conn.firewall_driver,
'prepare_instance_filter',
fake_none)
self.stubs.Set(conn, '_create_new_domain', fake_create_new_domain)
self.stubs.Set(conn.firewall_driver,
'apply_instance_filter',
fake_none)
args = [instance, network_info, 'SOFT']
conn.reboot(*args)
compute_driver = driver.ComputeDriver()
self.assertRaises(NotImplementedError, compute_driver.reboot, *args)
class NWFilterFakes: class NWFilterFakes:
def __init__(self): def __init__(self):
@@ -923,7 +950,6 @@ class IptablesFirewallTestCase(test.TestCase):
"""setup_basic_rules in nwfilter calls this.""" """setup_basic_rules in nwfilter calls this."""
pass pass
self.fake_libvirt_connection = FakeLibvirtConnection() self.fake_libvirt_connection = FakeLibvirtConnection()
self.test_ip = '10.11.12.13'
self.fw = firewall.IptablesFirewallDriver( self.fw = firewall.IptablesFirewallDriver(
get_connection=lambda: self.fake_libvirt_connection) get_connection=lambda: self.fake_libvirt_connection)
@@ -987,10 +1013,6 @@ class IptablesFirewallTestCase(test.TestCase):
def test_static_filters(self): def test_static_filters(self):
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
src_instance_ref = self._create_instance_ref() src_instance_ref = self._create_instance_ref()
src_ip = '10.11.12.14'
src_mac = '56:12:12:12:12:13'
_setup_networking(instance_ref['id'], self.test_ip, src_mac)
_setup_networking(src_instance_ref['id'], src_ip)
admin_ctxt = context.get_admin_context() admin_ctxt = context.get_admin_context()
secgroup = db.security_group_create(admin_ctxt, secgroup = db.security_group_create(admin_ctxt,
@@ -1061,10 +1083,17 @@ class IptablesFirewallTestCase(test.TestCase):
return '', '' return '', ''
print cmd, kwargs print cmd, kwargs
def get_fixed_ips(*args, **kwargs):
ips = []
for network, info in network_info:
ips.extend(info['ips'])
return [ip['ip'] for ip in ips]
from nova.network import linux_net from nova.network import linux_net
linux_net.iptables_manager.execute = fake_iptables_execute linux_net.iptables_manager.execute = fake_iptables_execute
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips)
self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info)
@@ -1078,7 +1107,8 @@ class IptablesFirewallTestCase(test.TestCase):
instance_chain = None instance_chain = None
for rule in self.out_rules: for rule in self.out_rules:
# This is pretty crude, but it'll do for now # This is pretty crude, but it'll do for now
if '-d 10.11.12.13 -j' in rule: # last two octets change
if re.search('-d 192.168.[0-9]{1,3}.[0-9]{1,3} -j', rule):
instance_chain = rule.split(' ')[-1] instance_chain = rule.split(' ')[-1]
break break
self.assertTrue(instance_chain, "The instance chain wasn't added") self.assertTrue(instance_chain, "The instance chain wasn't added")
@@ -1101,10 +1131,11 @@ class IptablesFirewallTestCase(test.TestCase):
self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, self.assertTrue(len(filter(regex.match, self.out_rules)) > 0,
"ICMP Echo Request acceptance rule wasn't added") "ICMP Echo Request acceptance rule wasn't added")
regex = re.compile('-A .* -j ACCEPT -p tcp -m multiport ' for ip in get_fixed_ips():
'--dports 80:81 -s %s' % (src_ip,)) regex = re.compile('-A .* -j ACCEPT -p tcp -m multiport '
self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, '--dports 80:81 -s %s' % ip)
"TCP port 80/81 acceptance rule wasn't added") self.assertTrue(len(filter(regex.match, self.out_rules)) > 0,
"TCP port 80/81 acceptance rule wasn't added")
regex = re.compile('-A .* -j ACCEPT -p tcp ' regex = re.compile('-A .* -j ACCEPT -p tcp '
'-m multiport --dports 80:81 -s 192.168.10.0/24') '-m multiport --dports 80:81 -s 192.168.10.0/24')
@@ -1114,24 +1145,27 @@ class IptablesFirewallTestCase(test.TestCase):
def test_filters_for_instance_with_ip_v6(self): def test_filters_for_instance_with_ip_v6(self):
self.flags(use_ipv6=True) self.flags(use_ipv6=True)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info) rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info)
self.assertEquals(len(rulesv4), 2) self.assertEquals(len(rulesv4), 2)
self.assertEquals(len(rulesv6), 3) self.assertEquals(len(rulesv6), 1)
def test_filters_for_instance_without_ip_v6(self): def test_filters_for_instance_without_ip_v6(self):
self.flags(use_ipv6=False) self.flags(use_ipv6=False)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info) rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info)
self.assertEquals(len(rulesv4), 2) self.assertEquals(len(rulesv4), 2)
self.assertEquals(len(rulesv6), 0) self.assertEquals(len(rulesv6), 0)
def test_multinic_iptables(self): def test_multinic_iptables(self):
ipv4_rules_per_network = 2 ipv4_rules_per_addr = 1
ipv6_rules_per_network = 3 ipv4_addr_per_network = 2
ipv6_rules_per_addr = 1
ipv6_addr_per_network = 1
networks_count = 5 networks_count = 5
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
network_info = _create_network_info(networks_count) network_info = _fake_network_info(self.stubs, networks_count,
ipv4_addr_per_network)
ipv4_len = len(self.fw.iptables.ipv4['filter'].rules) ipv4_len = len(self.fw.iptables.ipv4['filter'].rules)
ipv6_len = len(self.fw.iptables.ipv6['filter'].rules) ipv6_len = len(self.fw.iptables.ipv6['filter'].rules)
inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref, inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref,
@@ -1142,9 +1176,9 @@ class IptablesFirewallTestCase(test.TestCase):
ipv4_network_rules = len(ipv4) - len(inst_ipv4) - ipv4_len ipv4_network_rules = len(ipv4) - len(inst_ipv4) - ipv4_len
ipv6_network_rules = len(ipv6) - len(inst_ipv6) - ipv6_len ipv6_network_rules = len(ipv6) - len(inst_ipv6) - ipv6_len
self.assertEquals(ipv4_network_rules, self.assertEquals(ipv4_network_rules,
ipv4_rules_per_network * networks_count) ipv4_rules_per_addr * ipv4_addr_per_network * networks_count)
self.assertEquals(ipv6_network_rules, self.assertEquals(ipv6_network_rules,
ipv6_rules_per_network * networks_count) ipv6_rules_per_addr * ipv6_addr_per_network * networks_count)
def test_do_refresh_security_group_rules(self): def test_do_refresh_security_group_rules(self):
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
@@ -1170,8 +1204,7 @@ class IptablesFirewallTestCase(test.TestCase):
fakefilter.nwfilterLookupByName fakefilter.nwfilterLookupByName
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
_setup_networking(instance_ref['id'], self.test_ip) network_info = _fake_network_info(self.stubs, 1)
network_info = _create_network_info()
self.fw.setup_basic_filtering(instance_ref, network_info) self.fw.setup_basic_filtering(instance_ref, network_info)
self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info)
@@ -1186,13 +1219,12 @@ class IptablesFirewallTestCase(test.TestCase):
def test_provider_firewall_rules(self): def test_provider_firewall_rules(self):
# setup basic instance data # setup basic instance data
instance_ref = self._create_instance_ref() instance_ref = self._create_instance_ref()
_setup_networking(instance_ref['id'], self.test_ip)
# FRAGILE: peeks at how the firewall names chains # FRAGILE: peeks at how the firewall names chains
chain_name = 'inst-%s' % instance_ref['id'] chain_name = 'inst-%s' % instance_ref['id']
# create a firewall via setup_basic_filtering like libvirt_conn.spawn # create a firewall via setup_basic_filtering like libvirt_conn.spawn
# should have a chain with 0 rules # should have a chain with 0 rules
network_info = _create_network_info(1) network_info = _fake_network_info(self.stubs, 1)
self.fw.setup_basic_filtering(instance_ref, network_info) self.fw.setup_basic_filtering(instance_ref, network_info)
self.assertTrue('provider' in self.fw.iptables.ipv4['filter'].chains) self.assertTrue('provider' in self.fw.iptables.ipv4['filter'].chains)
rules = [rule for rule in self.fw.iptables.ipv4['filter'].rules rules = [rule for rule in self.fw.iptables.ipv4['filter'].rules
@@ -1256,7 +1288,6 @@ class NWFilterTestCase(test.TestCase):
self.fake_libvirt_connection = Mock() self.fake_libvirt_connection = Mock()
self.test_ip = '10.11.12.13'
self.fw = firewall.NWFilterFirewall( self.fw = firewall.NWFilterFirewall(
lambda: self.fake_libvirt_connection) lambda: self.fake_libvirt_connection)
@@ -1372,11 +1403,9 @@ class NWFilterTestCase(test.TestCase):
instance_ref = self._create_instance() instance_ref = self._create_instance()
inst_id = instance_ref['id'] inst_id = instance_ref['id']
_setup_networking(instance_ref['id'], self.test_ip) def _ensure_all_called(mac):
def _ensure_all_called():
instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'], instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
'fake') mac.translate(None, ':'))
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id'] secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']
for required in [secgroup_filter, 'allow-dhcp-server', for required in [secgroup_filter, 'allow-dhcp-server',
'no-arp-spoofing', 'no-ip-spoofing', 'no-arp-spoofing', 'no-ip-spoofing',
@@ -1392,17 +1421,22 @@ class NWFilterTestCase(test.TestCase):
self.security_group.id) self.security_group.id)
instance = db.instance_get(self.context, inst_id) instance = db.instance_get(self.context, inst_id)
network_info = _create_network_info() network_info = _fake_network_info(self.stubs, 1)
# since there is one (network_info) there is one vif
# pass this vif's mac to _ensure_all_called()
# to set the instance_filter properly
mac = network_info[0][1]['mac']
self.fw.setup_basic_filtering(instance, network_info) self.fw.setup_basic_filtering(instance, network_info)
self.fw.prepare_instance_filter(instance, network_info) self.fw.prepare_instance_filter(instance, network_info)
self.fw.apply_instance_filter(instance, network_info) self.fw.apply_instance_filter(instance, network_info)
_ensure_all_called() _ensure_all_called(mac)
self.teardown_security_group() self.teardown_security_group()
db.instance_destroy(context.get_admin_context(), instance_ref['id']) db.instance_destroy(context.get_admin_context(), instance_ref['id'])
def test_create_network_filters(self): def test_create_network_filters(self):
instance_ref = self._create_instance() instance_ref = self._create_instance()
network_info = _create_network_info(3) network_info = _fake_network_info(self.stubs, 3)
result = self.fw._create_network_filters(instance_ref, result = self.fw._create_network_filters(instance_ref,
network_info, network_info,
"fake") "fake")
@@ -1425,8 +1459,7 @@ class NWFilterTestCase(test.TestCase):
instance = db.instance_get(self.context, inst_id) instance = db.instance_get(self.context, inst_id)
_setup_networking(instance_ref['id'], self.test_ip) network_info = _fake_network_info(self.stubs, 1)
network_info = _create_network_info()
self.fw.setup_basic_filtering(instance, network_info) self.fw.setup_basic_filtering(instance, network_info)
self.fw.prepare_instance_filter(instance, network_info) self.fw.prepare_instance_filter(instance, network_info)
self.fw.apply_instance_filter(instance, network_info) self.fw.apply_instance_filter(instance, network_info)

View File

@@ -14,6 +14,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mox
from nova import context from nova import context
from nova import db from nova import db
@@ -21,9 +22,7 @@ from nova import exception
from nova import log as logging from nova import log as logging
from nova import test from nova import test
from nova.network import manager as network_manager from nova.network import manager as network_manager
from nova.tests import fake_network
import mox
LOG = logging.getLogger('nova.tests.network') LOG = logging.getLogger('nova.tests.network')
@@ -138,60 +137,50 @@ class FlatNetworkTestCase(test.TestCase):
is_admin=False) is_admin=False)
def test_get_instance_nw_info(self): def test_get_instance_nw_info(self):
self.mox.StubOutWithMock(db, 'fixed_ip_get_by_instance') fake_get_instance_nw_info = fake_network.fake_get_instance_nw_info
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
self.mox.StubOutWithMock(db, 'instance_type_get')
db.fixed_ip_get_by_instance(mox.IgnoreArg(), nw_info = fake_get_instance_nw_info(self.stubs, 0, 2)
mox.IgnoreArg()).AndReturn(fixed_ips) self.assertFalse(nw_info)
db.virtual_interface_get_by_instance(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(vifs)
db.instance_type_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(flavor)
self.mox.ReplayAll()
nw_info = self.network.get_instance_nw_info(None, 0, 0, None) for i, (nw, info) in enumerate(nw_info):
check = {'bridge': 'fake_br%d' % i,
self.assertTrue(nw_info)
for i, nw in enumerate(nw_info):
i8 = i + 8
check = {'bridge': 'fa%s' % i,
'cidr': '192.168.%s.0/24' % i, 'cidr': '192.168.%s.0/24' % i,
'cidr_v6': '2001:db%s::/64' % i8, 'cidr_v6': '2001:db8:0:%x::/64' % i,
'id': i, 'id': i,
'multi_host': False, 'multi_host': False,
'injected': 'DONTCARE', 'injected': False,
'bridge_interface': 'fake_fa%s' % i, 'bridge_interface': 'fake_eth%d' % i,
'vlan': None} 'vlan': None}
self.assertDictMatch(nw[0], check) self.assertDictMatch(nw, check)
check = {'broadcast': '192.168.%s.255' % i, check = {'broadcast': '192.168.%d.255' % i,
'dhcp_server': '192.168.%s.1' % i, 'dhcp_server': '192.168.%d.1' % i,
'dns': 'DONTCARE', 'dns': ['192.168.%d.3' % n, '192.168.%d.4' % n],
'gateway': '192.168.%s.1' % i, 'gateway': '192.168.%d.1' % i,
'gateway6': '2001:db%s::1' % i8, 'gateway6': '2001:db8:0:%x::1' % i,
'ip6s': 'DONTCARE', 'ip6s': 'DONTCARE',
'ips': 'DONTCARE', 'ips': 'DONTCARE',
'label': 'test%s' % i, 'label': 'test%d' % i,
'mac': 'DE:AD:BE:EF:00:0%s' % i, 'mac': 'DE:AD:BE:EF:00:%02x' % i,
'vif_uuid': ('00000000-0000-0000-0000-000000000000000%s' % 'vif_uuid':
i), '00000000-0000-0000-0000-00000000000000%02d' % i,
'rxtx_cap': 'DONTCARE', 'rxtx_cap': 3,
'should_create_vlan': False, 'should_create_vlan': False,
'should_create_bridge': False} 'should_create_bridge': False}
self.assertDictMatch(nw[1], check) self.assertDictMatch(info, check)
check = [{'enabled': 'DONTCARE', check = [{'enabled': 'DONTCARE',
'ip': '2001:db%s::dcad:beff:feef:%s' % (i8, i), 'ip': '2001:db8::dcad:beff:feef:%s' % i,
'netmask': '64'}] 'netmask': '64'}]
self.assertDictListMatch(nw[1]['ip6s'], check) self.assertDictListMatch(info['ip6s'], check)
check = [{'enabled': '1', num_fixed_ips = len(info['ips'])
'ip': '192.168.%s.100' % i, check = [{'enabled': 'DONTCARE',
'netmask': '255.255.255.0'}] 'ip': '192.168.%d.1%02d' % (i, ip_num),
self.assertDictListMatch(nw[1]['ips'], check) 'netmask': '255.255.255.0'}
for ip_num in xrange(num_fixed_ips)]
self.assertDictListMatch(info['ips'], check)
def test_validate_networks(self): def test_validate_networks(self):
self.mox.StubOutWithMock(db, 'network_get_all_by_uuids') self.mox.StubOutWithMock(db, 'network_get_all_by_uuids')
@@ -297,7 +286,8 @@ class VlanNetworkTestCase(test.TestCase):
db.fixed_ip_associate(mox.IgnoreArg(), db.fixed_ip_associate(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.1') mox.IgnoreArg(),
reserved=True).AndReturn('192.168.0.1')
db.fixed_ip_update(mox.IgnoreArg(), db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()) mox.IgnoreArg())
@@ -448,55 +438,23 @@ class VlanNetworkTestCase(test.TestCase):
class CommonNetworkTestCase(test.TestCase): class CommonNetworkTestCase(test.TestCase):
class FakeNetworkManager(network_manager.NetworkManager):
"""This NetworkManager doesn't call the base class so we can bypass all
inherited service cruft and just perform unit tests.
"""
class FakeDB:
def fixed_ip_get_by_instance(self, context, instance_id):
return [dict(address='10.0.0.0'), dict(address='10.0.0.1'),
dict(address='10.0.0.2')]
def network_get_by_cidr(self, context, cidr):
raise exception.NetworkNotFoundForCidr()
def network_create_safe(self, context, net):
fakenet = dict(net)
fakenet['id'] = 999
return fakenet
def network_get_all(self, context):
raise exception.NoNetworksFound()
def __init__(self):
self.db = self.FakeDB()
self.deallocate_called = None
def deallocate_fixed_ip(self, context, address):
self.deallocate_called = address
def _create_fixed_ips(self, context, network_id):
pass
def fake_create_fixed_ips(self, context, network_id): def fake_create_fixed_ips(self, context, network_id):
return None return None
def test_remove_fixed_ip_from_instance(self): def test_remove_fixed_ip_from_instance(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
manager.remove_fixed_ip_from_instance(None, 99, '10.0.0.1') manager.remove_fixed_ip_from_instance(None, 99, '10.0.0.1')
self.assertEquals(manager.deallocate_called, '10.0.0.1') self.assertEquals(manager.deallocate_called, '10.0.0.1')
def test_remove_fixed_ip_from_instance_bad_input(self): def test_remove_fixed_ip_from_instance_bad_input(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.assertRaises(exception.FixedIpNotFoundForSpecificInstance, self.assertRaises(exception.FixedIpNotFoundForSpecificInstance,
manager.remove_fixed_ip_from_instance, manager.remove_fixed_ip_from_instance,
None, 99, 'bad input') None, 99, 'bad input')
def test_validate_cidrs(self): def test_validate_cidrs(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
nets = manager.create_networks(None, 'fake', '192.168.0.0/24', nets = manager.create_networks(None, 'fake', '192.168.0.0/24',
False, 1, 256, None, None, None, False, 1, 256, None, None, None,
None) None)
@@ -505,7 +463,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertTrue('192.168.0.0/24' in cidrs) self.assertTrue('192.168.0.0/24' in cidrs)
def test_validate_cidrs_split_exact_in_half(self): def test_validate_cidrs_split_exact_in_half(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
nets = manager.create_networks(None, 'fake', '192.168.0.0/24', nets = manager.create_networks(None, 'fake', '192.168.0.0/24',
False, 2, 128, None, None, None, False, 2, 128, None, None, None,
None) None)
@@ -515,7 +473,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertTrue('192.168.0.128/25' in cidrs) self.assertTrue('192.168.0.128/25' in cidrs)
def test_validate_cidrs_split_cidr_in_use_middle_of_range(self): def test_validate_cidrs_split_cidr_in_use_middle_of_range(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
manager.db.network_get_all(ctxt).AndReturn([{'id': 1, manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
@@ -533,7 +491,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertFalse('192.168.2.0/24' in cidrs) self.assertFalse('192.168.2.0/24' in cidrs)
def test_validate_cidrs_smaller_subnet_in_use(self): def test_validate_cidrs_smaller_subnet_in_use(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
manager.db.network_get_all(ctxt).AndReturn([{'id': 1, manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
@@ -546,7 +504,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertRaises(ValueError, manager.create_networks, *args) self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_split_smaller_cidr_in_use(self): def test_validate_cidrs_split_smaller_cidr_in_use(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
manager.db.network_get_all(ctxt).AndReturn([{'id': 1, manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
@@ -563,7 +521,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertFalse('192.168.2.0/24' in cidrs) self.assertFalse('192.168.2.0/24' in cidrs)
def test_validate_cidrs_split_smaller_cidr_in_use2(self): def test_validate_cidrs_split_smaller_cidr_in_use2(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
manager.db.network_get_all(ctxt).AndReturn([{'id': 1, manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
@@ -579,7 +537,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertFalse('192.168.2.0/27' in cidrs) self.assertFalse('192.168.2.0/27' in cidrs)
def test_validate_cidrs_split_all_in_use(self): def test_validate_cidrs_split_all_in_use(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
in_use = [{'id': 1, 'cidr': '192.168.2.9/29'}, in_use = [{'id': 1, 'cidr': '192.168.2.9/29'},
@@ -595,14 +553,14 @@ class CommonNetworkTestCase(test.TestCase):
self.assertRaises(ValueError, manager.create_networks, *args) self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_one_in_use(self): def test_validate_cidrs_one_in_use(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
args = (None, 'fake', '192.168.0.0/24', False, 2, 256, None, None, args = (None, 'fake', '192.168.0.0/24', False, 2, 256, None, None,
None, None) None, None)
# ValueError: network_size * num_networks exceeds cidr size # ValueError: network_size * num_networks exceeds cidr size
self.assertRaises(ValueError, manager.create_networks, *args) self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_already_used(self): def test_validate_cidrs_already_used(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
manager.db.network_get_all(ctxt).AndReturn([{'id': 1, manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
@@ -614,7 +572,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertRaises(ValueError, manager.create_networks, *args) self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_too_many(self): def test_validate_cidrs_too_many(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
args = (None, 'fake', '192.168.0.0/24', False, 200, 256, None, None, args = (None, 'fake', '192.168.0.0/24', False, 200, 256, None, None,
None, None) None, None)
# ValueError: Not enough subnets avail to satisfy requested # ValueError: Not enough subnets avail to satisfy requested
@@ -622,7 +580,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertRaises(ValueError, manager.create_networks, *args) self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_split_partial(self): def test_validate_cidrs_split_partial(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
nets = manager.create_networks(None, 'fake', '192.168.0.0/16', nets = manager.create_networks(None, 'fake', '192.168.0.0/16',
False, 2, 256, None, None, None, None) False, 2, 256, None, None, None, None)
returned_cidrs = [str(net['cidr']) for net in nets] returned_cidrs = [str(net['cidr']) for net in nets]
@@ -630,7 +588,7 @@ class CommonNetworkTestCase(test.TestCase):
self.assertTrue('192.168.1.0/24' in returned_cidrs) self.assertTrue('192.168.1.0/24' in returned_cidrs)
def test_validate_cidrs_conflict_existing_supernet(self): def test_validate_cidrs_conflict_existing_supernet(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
fakecidr = [{'id': 1, 'cidr': '192.168.0.0/8'}] fakecidr = [{'id': 1, 'cidr': '192.168.0.0/8'}]
@@ -644,16 +602,15 @@ class CommonNetworkTestCase(test.TestCase):
def test_create_networks(self): def test_create_networks(self):
cidr = '192.168.0.0/24' cidr = '192.168.0.0/24'
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.stubs.Set(manager, '_create_fixed_ips', self.stubs.Set(manager, '_create_fixed_ips',
self.fake_create_fixed_ips) self.fake_create_fixed_ips)
args = [None, 'foo', cidr, None, 1, 256, 'fd00::/48', None, None, args = [None, 'foo', cidr, None, 1, 256, 'fd00::/48', None, None,
None] None]
result = manager.create_networks(*args)
self.assertTrue(manager.create_networks(*args)) self.assertTrue(manager.create_networks(*args))
def test_create_networks_cidr_already_used(self): def test_create_networks_cidr_already_used(self):
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.mox.StubOutWithMock(manager.db, 'network_get_all') self.mox.StubOutWithMock(manager.db, 'network_get_all')
ctxt = mox.IgnoreArg() ctxt = mox.IgnoreArg()
fakecidr = [{'id': 1, 'cidr': '192.168.0.0/24'}] fakecidr = [{'id': 1, 'cidr': '192.168.0.0/24'}]
@@ -665,9 +622,124 @@ class CommonNetworkTestCase(test.TestCase):
def test_create_networks_many(self): def test_create_networks_many(self):
cidr = '192.168.0.0/16' cidr = '192.168.0.0/16'
manager = self.FakeNetworkManager() manager = fake_network.FakeNetworkManager()
self.stubs.Set(manager, '_create_fixed_ips', self.stubs.Set(manager, '_create_fixed_ips',
self.fake_create_fixed_ips) self.fake_create_fixed_ips)
args = [None, 'foo', cidr, None, 10, 256, 'fd00::/48', None, None, args = [None, 'foo', cidr, None, 10, 256, 'fd00::/48', None, None,
None] None]
self.assertTrue(manager.create_networks(*args)) self.assertTrue(manager.create_networks(*args))
def test_get_instance_uuids_by_ip_regex(self):
manager = fake_network.FakeNetworkManager()
_vifs = manager.db.virtual_interface_get_all(None)
# Greedy get eveything
res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '.*'})
self.assertEqual(len(res), len(_vifs))
# Doesn't exist
res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '10.0.0.1'})
self.assertFalse(res)
# Get instance 1
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip': '172.16.0.2'})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
# Get instance 2
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip': '173.16.0.2'})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
# Get instance 0 and 1
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip': '172.16.0.*'})
self.assertTrue(res)
self.assertEqual(len(res), 2)
self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id'])
self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id'])
# Get instance 1 and 2
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip': '17..16.0.2'})
self.assertTrue(res)
self.assertEqual(len(res), 2)
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id'])
def test_get_instance_uuids_by_ipv6_regex(self):
manager = fake_network.FakeNetworkManager()
_vifs = manager.db.virtual_interface_get_all(None)
# Greedy get eveything
res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '.*'})
self.assertEqual(len(res), len(_vifs))
# Doesn't exist
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip6': '.*1034.*'})
self.assertFalse(res)
# Get instance 1
res = manager.get_instance_uuids_by_ip_filter(None,
{'ip6': '2001:.*:2'})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
# Get instance 2
ip6 = '2002:db8::dcad:beff:feef:2'
res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': ip6})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
# Get instance 0 and 1
res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '2001:.*'})
self.assertTrue(res)
self.assertEqual(len(res), 2)
self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id'])
self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id'])
# Get instance 1 and 2
ip6 = '200.:db8::dcad:beff:feef:2'
res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': ip6})
self.assertTrue(res)
self.assertEqual(len(res), 2)
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id'])
def test_get_instance_uuids_by_ip(self):
manager = fake_network.FakeNetworkManager()
_vifs = manager.db.virtual_interface_get_all(None)
# No regex for you!
res = manager.get_instance_uuids_by_ip_filter(None,
{'fixed_ip': '.*'})
self.assertFalse(res)
# Doesn't exist
ip = '10.0.0.1'
res = manager.get_instance_uuids_by_ip_filter(None,
{'fixed_ip': ip})
self.assertFalse(res)
# Get instance 1
ip = '172.16.0.2'
res = manager.get_instance_uuids_by_ip_filter(None,
{'fixed_ip': ip})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
# Get instance 2
ip = '173.16.0.2'
res = manager.get_instance_uuids_by_ip_filter(None,
{'fixed_ip': ip})
self.assertTrue(res)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])

View File

@@ -103,8 +103,9 @@ class _VirtDriverTestCase(test.TestCase):
def test_reboot(self): def test_reboot(self):
instance_ref = test_utils.get_test_instance() instance_ref = test_utils.get_test_instance()
network_info = test_utils.get_test_network_info() network_info = test_utils.get_test_network_info()
reboot_type = "SOFT"
self.connection.spawn(self.ctxt, instance_ref, network_info) self.connection.spawn(self.ctxt, instance_ref, network_info)
self.connection.reboot(instance_ref, network_info) self.connection.reboot(instance_ref, network_info, reboot_type)
@catch_notimplementederror @catch_notimplementederror
def test_get_host_ip_addr(self): def test_get_host_ip_addr(self):
@@ -175,6 +176,10 @@ class _VirtDriverTestCase(test.TestCase):
def test_poll_rescued_instances(self): def test_poll_rescued_instances(self):
self.connection.poll_rescued_instances(10) self.connection.poll_rescued_instances(10)
@catch_notimplementederror
def test_poll_unconfirmed_resizes(self):
self.connection.poll_unconfirmed_resizes(10)
@catch_notimplementederror @catch_notimplementederror
def test_migrate_disk_and_power_off(self): def test_migrate_disk_and_power_off(self):
instance_ref = test_utils.get_test_instance() instance_ref = test_utils.get_test_instance()

View File

@@ -170,7 +170,8 @@ class VMWareAPIVMTestCase(test.TestCase):
self._create_vm() self._create_vm()
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)
self.conn.reboot(self.instance, self.network_info) reboot_type = "SOFT"
self.conn.reboot(self.instance, self.network_info, reboot_type)
info = self.conn.get_info(1) info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING) self._check_vm_info(info, power_state.RUNNING)

View File

@@ -364,7 +364,7 @@ class XenAPIVMTestCase(test.TestCase):
def _test_spawn(self, image_ref, kernel_id, ramdisk_id, def _test_spawn(self, image_ref, kernel_id, ramdisk_id,
instance_type_id="3", os_type="linux", instance_type_id="3", os_type="linux",
architecture="x86-64", instance_id=1, hostname="test", architecture="x86-64", instance_id=1,
check_injection=False, check_injection=False,
create_record=True, empty_dns=False): create_record=True, empty_dns=False):
stubs.stubout_loopingcall_start(self.stubs) stubs.stubout_loopingcall_start(self.stubs)
@@ -377,6 +377,7 @@ class XenAPIVMTestCase(test.TestCase):
'ramdisk_id': ramdisk_id, 'ramdisk_id': ramdisk_id,
'instance_type_id': instance_type_id, 'instance_type_id': instance_type_id,
'os_type': os_type, 'os_type': os_type,
'hostname': hostname,
'architecture': architecture} 'architecture': architecture}
instance = db.instance_create(self.context, values) instance = db.instance_create(self.context, values)
else: else:
@@ -932,8 +933,9 @@ class XenAPIDetermineDiskImageTestCase(test.TestCase):
self.fake_instance.architecture = 'x86-64' self.fake_instance.architecture = 'x86-64'
def assert_disk_type(self, disk_type): def assert_disk_type(self, disk_type):
ctx = context.RequestContext('fake', 'fake')
dt = vm_utils.VMHelper.determine_disk_image_type( dt = vm_utils.VMHelper.determine_disk_image_type(
self.fake_instance) self.fake_instance, ctx)
self.assertEqual(disk_type, dt) self.assertEqual(disk_type, dt)
def test_instance_disk(self): def test_instance_disk(self):

View File

@@ -45,8 +45,6 @@ def set_stubs(stubs):
stubs.Set(vmware_images, 'get_vmdk_size_and_properties', stubs.Set(vmware_images, 'get_vmdk_size_and_properties',
fake.fake_get_vmdk_size_and_properties) fake.fake_get_vmdk_size_and_properties)
stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image) stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object",
fake_get_vim_object)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object", stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object",
fake_get_vim_object) fake_get_vim_object)
stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object", stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object",