merge trunk
This commit is contained in:
@@ -276,7 +276,7 @@ def _db_error(caught_exception):
|
||||
print caught_exception
|
||||
print _("The above error may show that the database has not "
|
||||
"been created.\nPlease create a database using "
|
||||
"nova-manage sync db before running this command.")
|
||||
"'nova-manage db sync' before running this command.")
|
||||
exit(1)
|
||||
|
||||
|
||||
@@ -437,6 +437,8 @@ class ProjectCommands(object):
|
||||
"been created.\nPlease create a database by running a "
|
||||
"nova-api server on this host.")
|
||||
|
||||
AccountCommands = ProjectCommands
|
||||
|
||||
|
||||
class FixedIpCommands(object):
|
||||
"""Class for managing fixed ip."""
|
||||
@@ -898,6 +900,7 @@ class ImageCommands(object):
|
||||
|
||||
CATEGORIES = [
|
||||
('user', UserCommands),
|
||||
('account', AccountCommands),
|
||||
('project', ProjectCommands),
|
||||
('role', RoleCommands),
|
||||
('shell', ShellCommands),
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
Test suite for XenAPI
|
||||
"""
|
||||
|
||||
import functools
|
||||
import os
|
||||
import re
|
||||
import stubout
|
||||
@@ -48,6 +49,21 @@ LOG = logging.getLogger('nova.tests.test_xenapi')
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
def stub_vm_utils_with_vdi_attached_here(function, should_return=True):
|
||||
"""
|
||||
vm_utils.with_vdi_attached_here needs to be stubbed out because it
|
||||
calls down to the filesystem to attach a vdi. This provides a
|
||||
decorator to handle that.
|
||||
"""
|
||||
@functools.wraps(function)
|
||||
def decorated_function(self, *args, **kwargs):
|
||||
orig_with_vdi_attached_here = vm_utils.with_vdi_attached_here
|
||||
vm_utils.with_vdi_attached_here = lambda *x: should_return
|
||||
function(self, *args, **kwargs)
|
||||
vm_utils.with_vdi_attached_here = orig_with_vdi_attached_here
|
||||
return decorated_function
|
||||
|
||||
|
||||
class XenAPIVolumeTestCase(test.TestCase):
|
||||
"""
|
||||
Unit tests for Volume operations
|
||||
@@ -71,6 +87,7 @@ class XenAPIVolumeTestCase(test.TestCase):
|
||||
'ramdisk_id': 3,
|
||||
'instance_type': 'm1.large',
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
'os_type': 'linux',
|
||||
}
|
||||
|
||||
def _create_volume(self, size='0'):
|
||||
@@ -231,40 +248,43 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
|
||||
check()
|
||||
|
||||
def check_vm_record(self, conn, check_injection=False):
|
||||
def create_vm_record(self, conn, os_type):
|
||||
instances = conn.list_instances()
|
||||
self.assertEquals(instances, ['1'])
|
||||
|
||||
# Get Nova record for VM
|
||||
vm_info = conn.get_info('1')
|
||||
# Get XenAPI record for VM
|
||||
vms = [(ref, rec) for ref, rec
|
||||
vm_info = conn.get_info(1)
|
||||
# Get XenAPI record for VM
|
||||
vms = [rec for ref, rec
|
||||
in xenapi_fake.get_all_records('VM').iteritems()
|
||||
if not rec['is_control_domain']]
|
||||
vm_ref, vm = vms[0]
|
||||
vm = vms[0]
|
||||
self.vm_info = vm_info
|
||||
self.vm = vm
|
||||
|
||||
def check_vm_record(self, conn, check_injection=False):
|
||||
# Check that m1.large above turned into the right thing.
|
||||
instance_type = db.instance_type_get_by_name(conn, 'm1.large')
|
||||
mem_kib = long(instance_type['memory_mb']) << 10
|
||||
mem_bytes = str(mem_kib << 10)
|
||||
vcpus = instance_type['vcpus']
|
||||
self.assertEquals(vm_info['max_mem'], mem_kib)
|
||||
self.assertEquals(vm_info['mem'], mem_kib)
|
||||
self.assertEquals(vm['memory_static_max'], mem_bytes)
|
||||
self.assertEquals(vm['memory_dynamic_max'], mem_bytes)
|
||||
self.assertEquals(vm['memory_dynamic_min'], mem_bytes)
|
||||
self.assertEquals(vm['VCPUs_max'], str(vcpus))
|
||||
self.assertEquals(vm['VCPUs_at_startup'], str(vcpus))
|
||||
LOG.debug("VM:%s", self.vm)
|
||||
self.assertEquals(self.vm_info['max_mem'], mem_kib)
|
||||
self.assertEquals(self.vm_info['mem'], mem_kib)
|
||||
self.assertEquals(self.vm['memory_static_max'], mem_bytes)
|
||||
self.assertEquals(self.vm['memory_dynamic_max'], mem_bytes)
|
||||
self.assertEquals(self.vm['memory_dynamic_min'], mem_bytes)
|
||||
self.assertEquals(self.vm['VCPUs_max'], str(vcpus))
|
||||
self.assertEquals(self.vm['VCPUs_at_startup'], str(vcpus))
|
||||
|
||||
# Check that the VM is running according to Nova
|
||||
self.assertEquals(vm_info['state'], power_state.RUNNING)
|
||||
self.assertEquals(self.vm_info['state'], power_state.RUNNING)
|
||||
|
||||
# Check that the VM is running according to XenAPI.
|
||||
self.assertEquals(vm['power_state'], 'Running')
|
||||
self.assertEquals(self.vm['power_state'], 'Running')
|
||||
|
||||
if check_injection:
|
||||
session = xenapi_conn.XenAPISession('fake', 'fake', 'fake')
|
||||
xenstore_data = session.call_xenapi('VM.get_xenstore_data', vm_ref)
|
||||
xenstore_data = self.vm['xenstore_data']
|
||||
key = 'vm-data/networking/aabbccddeeff'
|
||||
xenstore_value = xenstore_data[key]
|
||||
tcpip_data = ast.literal_eval(xenstore_value)
|
||||
@@ -282,8 +302,40 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
'dns': ['10.0.0.2'],
|
||||
'gateway': '10.0.0.1'})
|
||||
|
||||
def check_vm_params_for_windows(self):
|
||||
self.assertEquals(self.vm['platform']['nx'], 'true')
|
||||
self.assertEquals(self.vm['HVM_boot_params'], {'order': 'dc'})
|
||||
self.assertEquals(self.vm['HVM_boot_policy'], 'BIOS order')
|
||||
|
||||
# check that these are not set
|
||||
self.assertEquals(self.vm['PV_args'], '')
|
||||
self.assertEquals(self.vm['PV_bootloader'], '')
|
||||
self.assertEquals(self.vm['PV_kernel'], '')
|
||||
self.assertEquals(self.vm['PV_ramdisk'], '')
|
||||
|
||||
def check_vm_params_for_linux(self):
|
||||
self.assertEquals(self.vm['platform']['nx'], 'false')
|
||||
self.assertEquals(self.vm['PV_args'], 'clocksource=jiffies')
|
||||
self.assertEquals(self.vm['PV_bootloader'], 'pygrub')
|
||||
|
||||
# check that these are not set
|
||||
self.assertEquals(self.vm['PV_kernel'], '')
|
||||
self.assertEquals(self.vm['PV_ramdisk'], '')
|
||||
self.assertEquals(self.vm['HVM_boot_params'], {})
|
||||
self.assertEquals(self.vm['HVM_boot_policy'], '')
|
||||
|
||||
def check_vm_params_for_linux_with_external_kernel(self):
|
||||
self.assertEquals(self.vm['platform']['nx'], 'false')
|
||||
self.assertEquals(self.vm['PV_args'], 'root=/dev/xvda1')
|
||||
self.assertNotEquals(self.vm['PV_kernel'], '')
|
||||
self.assertNotEquals(self.vm['PV_ramdisk'], '')
|
||||
|
||||
# check that these are not set
|
||||
self.assertEquals(self.vm['HVM_boot_params'], {})
|
||||
self.assertEquals(self.vm['HVM_boot_policy'], '')
|
||||
|
||||
def _test_spawn(self, image_id, kernel_id, ramdisk_id,
|
||||
instance_type="m1.large", check_injection=False):
|
||||
instance_type="m1.large", os_type="linux", check_injection=False):
|
||||
stubs.stubout_loopingcall_start(self.stubs)
|
||||
values = {'id': 1,
|
||||
'project_id': self.project.id,
|
||||
@@ -293,10 +345,12 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
'ramdisk_id': ramdisk_id,
|
||||
'instance_type': instance_type,
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
'os_type': os_type,
|
||||
}
|
||||
instance = db.instance_create(self.context, values)
|
||||
self.conn.spawn(instance)
|
||||
self.check_vm_record(self.conn, check_injection=check_injection)
|
||||
self.create_vm_record(self.conn, os_type)
|
||||
self.check_vm_record(self.conn, check_injection)
|
||||
|
||||
def test_spawn_not_enough_memory(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
@@ -312,19 +366,30 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
FLAGS.xenapi_image_service = 'objectstore'
|
||||
self._test_spawn(1, 2, 3)
|
||||
|
||||
@stub_vm_utils_with_vdi_attached_here
|
||||
def test_spawn_raw_glance(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_RAW, None, None)
|
||||
self.check_vm_params_for_linux()
|
||||
|
||||
def test_spawn_vhd_glance(self):
|
||||
def test_spawn_vhd_glance_linux(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None)
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None,
|
||||
os_type="linux")
|
||||
self.check_vm_params_for_linux()
|
||||
|
||||
def test_spawn_vhd_glance_windows(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None,
|
||||
os_type="windows")
|
||||
self.check_vm_params_for_windows()
|
||||
|
||||
def test_spawn_glance(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE,
|
||||
glance_stubs.FakeGlance.IMAGE_KERNEL,
|
||||
glance_stubs.FakeGlance.IMAGE_RAMDISK)
|
||||
self.check_vm_params_for_linux_with_external_kernel()
|
||||
|
||||
def test_spawn_netinject_file(self):
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
@@ -412,6 +477,8 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
super(XenAPIVMTestCase, self).tearDown()
|
||||
self.manager.delete_project(self.project)
|
||||
self.manager.delete_user(self.user)
|
||||
self.vm_info = None
|
||||
self.vm = None
|
||||
self.stubs.UnsetAll()
|
||||
|
||||
def _create_instance(self):
|
||||
@@ -425,7 +492,8 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
'kernel_id': 2,
|
||||
'ramdisk_id': 3,
|
||||
'instance_type': 'm1.large',
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff'}
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
'os_type': 'linux'}
|
||||
instance = db.instance_create(self.context, values)
|
||||
self.conn.spawn(instance)
|
||||
return instance
|
||||
@@ -485,6 +553,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
'ramdisk_id': None,
|
||||
'instance_type': 'm1.large',
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
'os_type': 'linux',
|
||||
}
|
||||
stubs.stub_out_migration_methods(self.stubs)
|
||||
stubs.stubout_get_this_vm_uuid(self.stubs)
|
||||
@@ -525,6 +594,7 @@ class XenAPIDetermineDiskImageTestCase(test.TestCase):
|
||||
|
||||
self.fake_instance = FakeInstance()
|
||||
self.fake_instance.id = 42
|
||||
self.fake_instance.os_type = 'linux'
|
||||
|
||||
def assert_disk_type(self, disk_type):
|
||||
dt = vm_utils.VMHelper.determine_disk_image_type(
|
||||
|
||||
Reference in New Issue
Block a user