summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-01-12 02:41:44 +0000
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-01-12 02:41:44 +0000
commit2f9ac0fd02115ff9af2e96f5a92f3442d273c6b0 (patch)
tree2735a8793d18622d8d4e3eca0f462f1dac1922e1
parenta96c12f13421a7c27e7cb1459f73ca4bd5cdf917 (diff)
Fixed test environments.
Fixed bugs in _fetch_image_objecstore and _lookup_image_objcestore (objectstore was broken!) Added tests for glance NEED TO: - add SR & PBD records to fake xenapi session for find_sr to work - fake somehow stream in _fetch_image_glance
-rw-r--r--nova/tests/test_xenapi.py26
-rw-r--r--nova/tests/xenapi/stubs.py11
-rw-r--r--nova/virt/xenapi/vm_utils.py22
-rw-r--r--nova/virt/xenapi/vmops.py7
4 files changed, 52 insertions, 14 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 7c256968f..5829fa452 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -48,6 +48,7 @@ class XenAPIVolumeTestCase(test.TestCase):
FLAGS.xenapi_connection_url = 'test_url'
FLAGS.xenapi_connection_password = 'test_pass'
db_fakes.stub_out_db_instance_api(self.stubs)
+ stubs.stubout_glance_client(self.stubs)
stubs.stub_out_get_target(self.stubs)
xenapi_fake.reset()
self.values = {'name': 1, 'id': 1,
@@ -104,6 +105,7 @@ class XenAPIVolumeTestCase(test.TestCase):
def test_attach_volume(self):
""" This shows how to test Ops classes' methods """
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
+ stubs.stubout_glance_client(self.stubs)
conn = xenapi_conn.get_connection(False)
volume = self._create_volume()
instance = db.instance_create(self.values)
@@ -126,6 +128,7 @@ class XenAPIVolumeTestCase(test.TestCase):
""" This shows how to test when exceptions are raised """
stubs.stubout_session(self.stubs,
stubs.FakeSessionForVolumeFailedTests)
+ stubs.stubout_glance_client(self.stubs)
conn = xenapi_conn.get_connection(False)
volume = self._create_volume()
instance = db.instance_create(self.values)
@@ -159,6 +162,7 @@ class XenAPIVMTestCase(test.TestCase):
db_fakes.stub_out_db_instance_api(self.stubs)
xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
+ stubs.stubout_glance_client(self.stubs)
self.conn = xenapi_conn.get_connection(False)
def test_list_instances_0(self):
@@ -214,8 +218,8 @@ class XenAPIVMTestCase(test.TestCase):
vm_info = conn.get_info(1)
# Get XenAPI record for VM
- vms = fake.get_all('VM')
- vm = fake.get_record('VM', vms[0])
+ vms = xenapi_fake.get_all('VM')
+ vm = xenapi_fake.get_record('VM', vms[0])
# Check that m1.large above turned into the right thing.
instance_type = instance_types.INSTANCE_TYPES['m1.large']
@@ -238,7 +242,9 @@ class XenAPIVMTestCase(test.TestCase):
def _test_spawn(self, image_id, kernel_id, ramdisk_id):
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
+ stubs.stubout_glance_client(self.stubs)
values = {'name': 1,
+ 'id':1,
'project_id': self.project.id,
'user_id': self.user.id,
'image_id': image_id,
@@ -252,12 +258,24 @@ class XenAPIVMTestCase(test.TestCase):
conn.spawn(instance)
self.check_vm_record(conn)
- def test_spawn_raw(self):
+ def test_spawn_raw_objectstore(self):
+ FLAGS.xenapi_image_service='objectstore'
self._test_spawn(1, None, None)
- def test_spawn(self):
+ def test_spawn_objectstore(self):
+ FLAGS.xenapi_image_service='objectstore'
self._test_spawn(1, 2, 3)
+ def test_spawn_raw_glance(self):
+ xenapi_fake._create_sr('SR',['','',{'other_config':{'i18n-key':'local-storage'}},'',
+ '','','iscsi'])
+ FLAGS.xenapi_image_service='glance'
+ self._test_spawn(1, None, None)
+
+ def test_spawn_glance(self):
+ FLAGS.xenapi_image_service='glance'
+ self._test_spawn(1, 2, 3)
+
def tearDown(self):
super(XenAPIVMTestCase, self).tearDown()
self.manager.delete_project(self.project)
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 55f751f11..1b6cf1182 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -17,6 +17,7 @@
"""Stubouts, mocks and fixtures for the test suite"""
from nova.virt import xenapi_conn
+from nova.virt.xenapi import vmops
from nova.virt.xenapi import fake
from nova.virt.xenapi import volume_utils
from nova.virt.xenapi import vm_utils
@@ -69,6 +70,16 @@ def stubout_instance_snapshot(stubs):
stubs.Set(vm_utils, 'wait_for_vhd_coalesce', fake_wait_for_vhd_coalesce)
+def stubout_glance_client(stubs):
+ """Stubs out glance import method for importing fake client"""
+ def fake_import(self):
+ """Stubs out get_imported_xenapi of XenAPISession"""
+ fake_module = 'nova.tests.glance.fake_client'
+ from_list = ['fake_client']
+ return __import__(fake_module, globals(), locals(), from_list, -1)
+
+ stubs.Set(vmops.VMOps, '_get_imported_glance',fake_import)
+
def stubout_session(stubs, cls):
"""Stubs out two methods from XenAPISession"""
def fake_import(self):
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 4f2c754fa..76b58b247 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -19,7 +19,6 @@ Helper methods for operations related to the management of VM records and
their attributes like VDIs, VIFs, as well as their lookup functions.
"""
-import glance.client
import logging
import os
import pickle
@@ -73,6 +72,8 @@ class VMHelper(HelperBase):
The class that wraps the helper methods together.
"""
+ Glance = None
+
@classmethod
def create_vm(cls, session, instance, kernel, ramdisk, pv_kernel=False):
"""Create a VM record. Returns a Deferred that gives the new
@@ -297,7 +298,7 @@ class VMHelper(HelperBase):
access, type)
else:
return cls._fetch_image_objectstore(session, instance_id, image,
- access, type)
+ user,access, type)
@classmethod
def _fetch_image_glance(cls, session, instance_id, image, access, type):
@@ -305,7 +306,7 @@ class VMHelper(HelperBase):
if sr is None:
raise exception.NotFound('Cannot find SR to write VDI to')
- c = glance.client.Client(FLAGS.glance_host, FLAGS.glance_port)
+ c = cls.Glance.Client(FLAGS.glance_host, FLAGS.glance_port)
meta, image_file = c.get_image(image)
virtual_size = int(meta['size'])
@@ -350,8 +351,8 @@ class VMHelper(HelperBase):
return session.get_xenapi().VDI.get_uuid(vdi)
@classmethod
- def _fetch_image_objectstore(cls, session, instance_id, image, access,
- type):
+ def _fetch_image_objectstore(cls, session, instance_id, image,
+ user,access,type):
url = images.image_url(image)
logging.debug("Asking xapi to fetch %s as %s", url, access)
fn = (type != ImageType.KERNEL_RAMDISK) and 'get_vdi' or 'get_kernel'
@@ -370,20 +371,21 @@ class VMHelper(HelperBase):
return uuid
@classmethod
- def lookup_image(cls, session, vdi_ref):
+ def lookup_image(cls, session, instance_id,vdi_ref):
if FLAGS.xenapi_image_service == 'glance':
return cls._lookup_image_glance(session, vdi_ref)
else:
- return cls._lookup_image_objectstore(session, vdi_ref)
+ return cls._lookup_image_objectstore(session, instance_id,vdi_ref)
@classmethod
- def _lookup_image_objectstore(cls, session, vdi_ref):
+ def _lookup_image_objectstore(cls, session, instance_id,vdi_ref):
logging.debug("Looking up vdi %s for PV kernel", vdi_ref)
fn = "is_vdi_pv"
args = {}
args['vdi-ref'] = vdi_ref
task = session.async_call_plugin('objectstore', fn, args)
- pv_str = session.wait_for_task(task)
+ pv_str = session.wait_for_task(instance_id,task)
+ pv = None
if pv_str.lower() == 'true':
pv = True
elif pv_str.lower() == 'false':
@@ -580,10 +582,12 @@ def get_vdi_for_vm_safely(session, vm_ref):
def find_sr(session):
+ logging.warning("IN find_sr")
host = session.get_xenapi_host()
srs = session.get_xenapi().SR.get_all()
for sr in srs:
sr_rec = session.get_xenapi().SR.get_record(sr)
+ logging.warning("HERE: %s",sr_rec['uuid'])
if not ('i18n-key' in sr_rec['other_config'] and
sr_rec['other_config']['i18n-key'] == 'local-storage'):
continue
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index b6d620782..cec8ecdcc 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -42,6 +42,11 @@ class VMOps(object):
self.XenAPI = session.get_imported_xenapi()
self._session = session
VMHelper.XenAPI = self.XenAPI
+ VMHelper.Glance = self._get_imported_glance()
+
+ def _get_imported_glance(self):
+ """Stubout point. This can be replaced with a mock glance module."""
+ return __import__('glance')
def list_instances(self):
"""List VM instances"""
@@ -77,7 +82,7 @@ class VMOps(object):
#Have a look at the VDI and see if it has a PV kernel
pv_kernel = False
if not instance.kernel_id:
- pv_kernel = VMHelper.lookup_image(self._session, vdi_ref)
+ pv_kernel = VMHelper.lookup_image(self._session, instance.id,vdi_ref)
kernel = None
if instance.kernel_id:
kernel = VMHelper.fetch_image(self._session, instance.id,