XenAPI tests

This commit is contained in:
matt.dietz@rackspace.com
2011-02-18 21:37:57 +00:00
parent 5afc241262
commit 38954dbd10
2 changed files with 36 additions and 14 deletions

View File

@@ -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'})

View File

@@ -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 __exit__(self, type, value, traceback)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass
def fake_get_snapshot(self, instance):
return FakeSnapshot()
@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)