summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authormatt.dietz@rackspace.com <>2011-02-18 21:37:57 +0000
committermatt.dietz@rackspace.com <>2011-02-18 21:37:57 +0000
commit62b3eb71384581e900b061e65caa6418c4452fa9 (patch)
treee281474d13608bd773bc9cd356179d0cc7f21c45 /nova
parentbb5624258200f027320327a38c524c389979c97a (diff)
downloadnova-62b3eb71384581e900b061e65caa6418c4452fa9.tar.gz
nova-62b3eb71384581e900b061e65caa6418c4452fa9.tar.xz
nova-62b3eb71384581e900b061e65caa6418c4452fa9.zip
XenAPI tests
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_xenapi.py12
-rw-r--r--nova/tests/xenapi/stubs.py38
-rw-r--r--nova/virt/xenapi/fake.py3
3 files changed, 39 insertions, 14 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index ee4c68e6c..3cbc01e5c 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -362,11 +362,13 @@ class XenAPIMigrateInstance(test.TestCase):
stubs.stub_out_migration_methods(self.stubs)
def test_migrate_disk_and_power_off(self):
- FLAGS.target_host = '127.0.0.1'
- FLAGS.xenapi_connection_url = 'test_url'
- FLAGS.xenapi_connection_password = 'test_pass'
- destination = '127.0.0.1'
instance = db.instance_create(self.values)
stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
conn = xenapi_conn.get_connection(False)
- conn.migrate_disk_and_power_off(instance, destination)
+ conn.migrate_disk_and_power_off(instance, '127.0.0.1')
+
+ def test_attach_disk(self):
+ instance = db.instance_create(self.values)
+ stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
+ conn = xenapi_conn.get_connection(False)
+ conn.attach_disk(instance, {'base_copy': 'hurr', 'cow': 'durr'})
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index d1c367475..054fc434b 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -213,16 +213,36 @@ class FakeSessionForMigrationTests(fake.SessionBase):
super(FakeSessionForMigrationTests, self).__init__(uri)
-class FakeSnapshot(vmops.VMOps):
- def __getattr__(self, key):
- return 'fake'
+def stub_out_migration_methods(stubs):
+ class FakeSnapshot(object):
+ def __getattr__(self, key):
+ return str(key)
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ pass
+
+ def fake_get_snapshot(self, instance):
+ return FakeSnapshot()
- def __exit__(self, type, value, traceback)
+ @classmethod
+ def fake_get_vdi(cls, session, vm_ref):
+ vdi_ref = fake.create_vdi(name_label='derp', read_only=False,
+ sr_ref='herp', sharable=False)
+ vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref)
+ return vdi_ref, {'uuid': vdi_rec['uuid']}
+
+ def fake_shutdown(self, inst, vm, method='clean'):
pass
-def fake_get_snapshot(self, instance):
- return FakeSnapshot()
+ @classmethod
+ def fake_scan_sr(cls, session):
+ pass
-def stub_out_migration_methods(stubs):
- stubs.Set(vmops.VMOps, '_get_snapshot',
- fake_get_snapshot)
+ stubs.Set(vm_utils.VMHelper, 'scan_sr', fake_scan_sr)
+ stubs.Set(vmops.VMOps, '_get_snapshot', fake_get_snapshot)
+ stubs.Set(vm_utils.VMHelper, 'get_vdi_for_vm_safely', fake_get_vdi)
+ stubs.Set(xenapi_conn.XenAPISession, 'wait_for_task', lambda x,y,z: None)
+ stubs.Set(vmops.VMOps, '_shutdown', fake_shutdown)
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py
index e1ae03e70..ba12d4d3a 100644
--- a/nova/virt/xenapi/fake.py
+++ b/nova/virt/xenapi/fake.py
@@ -290,6 +290,9 @@ class SessionBase(object):
#Always return 12GB available
return 12 * 1024 * 1024 * 1024
+ def host_call_plugin(*args):
+ return 'herp'
+
def xenapi_request(self, methodname, params):
if methodname.startswith('login'):
self._login(methodname, params)