def host_call_plugin_swap(self, _1, _2, plugin, method, _5): sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', False, sr_ref, False) vdi_rec = fake.get_record('VDI', vdi_ref) if plugin == "glance" and method == "download_vhd": swap_vdi_ref = fake.create_vdi('', False, sr_ref, False) swap_vdi_rec = fake.get_record('VDI', swap_vdi_ref) ret_str = json.dumps( [dict(vdi_type='os', vdi_uuid=vdi_rec['uuid']), dict(vdi_type='swap', vdi_uuid=swap_vdi_rec['uuid'])]) else: ret_str = vdi_rec['uuid'] return '<string>%s</string>' % ret_str
def test_get_instance_vdis_for_sr(self): vm_ref = fake.create_vm("foo", "Running") sr_ref = fake.create_sr() vdi_1 = fake.create_vdi("vdiname1", sr_ref) vdi_2 = fake.create_vdi("vdiname2", sr_ref) for vdi_ref in [vdi_1, vdi_2]: fake.create_vbd(vm_ref, vdi_ref) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = list(vm_utils.get_instance_vdis_for_sr(driver._session, vm_ref, sr_ref)) self.assertEquals([vdi_1, vdi_2], result)
def fake_fetch_image(cls, session, instance_id, image, user, project, type): # Stubout wait_for_task def fake_wait_for_task(self, task, id): class FakeEvent: def send(self, value): self.rv = value def wait(self): return self.rv done = FakeEvent() self._poll_task(id, task, done) rv = done.wait() return rv def fake_loop(self): pass stubs.Set(xenapi_conn.XenAPISession, 'wait_for_task', fake_wait_for_task) stubs.Set(xenapi_conn.XenAPISession, '_stop_loop', fake_loop) from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance_id #TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec['uuid'] return vdi_uuid
def fake_fetch_image(cls, session, instance_id, image, user, project, type): # Stubout wait_for_task def fake_wait_for_task(self, id, task): class FakeEvent: def send(self, value): self.rv = value def wait(self): return self.rv done = FakeEvent() self._poll_task(id, task, done) rv = done.wait() return rv def fake_loop(self): pass stubs.Set(xenapi_conn.XenAPISession, 'wait_for_task', fake_wait_for_task) stubs.Set(xenapi_conn.XenAPISession, '_stop_loop', fake_loop) from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance_id #TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec['uuid'] return vdi_uuid
def test_get_instance_vdis_for_sr(self): vm_ref = fake.create_vm("foo", "Running") sr_ref = fake.create_sr() vdi_1 = fake.create_vdi('vdiname1', sr_ref) vdi_2 = fake.create_vdi('vdiname2', sr_ref) for vdi_ref in [vdi_1, vdi_2]: fake.create_vbd(vm_ref, vdi_ref) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = list(vm_utils.get_instance_vdis_for_sr( driver._session, vm_ref, sr_ref)) self.assertEquals([vdi_1, vdi_2], result)
def VM_snapshot(self, session_ref, vm_ref, label): status = "Running" template_vm_ref = fake.create_vm(label, status, is_a_template=True, is_control_domain=False) sr_ref = "fakesr" template_vdi_ref = fake.create_vdi(label, read_only=True, sr_ref=sr_ref, sharable=False) template_vbd_ref = fake.create_vbd(template_vm_ref, template_vdi_ref) return template_vm_ref
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 VM_snapshot(self, session_ref, vm_ref, label): status = "Running" template_vm_ref = fake.create_vm(label, status, is_a_template=True, is_control_domain=False) sr_ref = "fakesr" template_vdi_ref = fake.create_vdi(label, sr_ref, read_only=True) template_vbd_ref = fake.create_vbd(template_vm_ref, template_vdi_ref) return template_vm_ref
def fake_wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref, original_parent_uuid): from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance_id # TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec["uuid"] return vdi_uuid
def fake_fetch_image(cls, session, instance_id, image, user, project, type): from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance_id #TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec['uuid'] return [dict(vdi_type='os', vdi_uuid=vdi_uuid)]
def fake_wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref, original_parent_uuid): from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance_id #TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec['uuid'] return vdi_uuid
def fake_fetch_image(cls, context, session, instance, image, user, project, type): from nova.virt.xenapi.fake import create_vdi name_label = "instance-%s" % instance.id #TODO: create fake SR record sr_ref = "fakesr" vdi_ref = create_vdi(name_label=name_label, read_only=False, sr_ref=sr_ref, sharable=False) vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) vdi_uuid = vdi_rec['uuid'] return [dict(vdi_type='os', vdi_uuid=vdi_uuid)]
def host_call_plugin(self, _1, _2, plugin, method, _5): # If the call is for 'copy_kernel_vdi' return None. if method == 'copy_kernel_vdi': return sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', False, sr_ref, False) vdi_rec = fake.get_record('VDI', vdi_ref) if plugin == "glance" and method == "download_vhd": ret_str = json.dumps( [dict(vdi_type='os', vdi_uuid=vdi_rec['uuid'])]) else: ret_str = vdi_rec['uuid'] return '<string>%s</string>' % ret_str
def host_call_plugin(self, _1, _2, plugin, method, _5): # If the call is for 'copy_kernel_vdi' return None. if method == 'copy_kernel_vdi': return sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', False, sr_ref, False) vdi_rec = fake.get_record('VDI', vdi_ref) if plugin == "glance" and method == "download_vhd": ret_str = json.dumps([dict(vdi_type='os', vdi_uuid=vdi_rec['uuid'])]) else: ret_str = vdi_rec['uuid'] return '<string>%s</string>' % ret_str
def host_call_plugin(self, _1, _2, _3, _4, _5): sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', False, sr_ref, False) vdi_rec = fake.get_record('VDI', vdi_ref) return '<string>%s</string>' % vdi_rec['uuid']
def fake_get_vdi(cls, session, vm_ref): vdi_ref = fake.create_vdi('derp', 'herp') vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref) return vdi_ref, {'uuid': vdi_rec['uuid'], }
def _make_fake_vdi(): sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', sr_ref) vdi_rec = fake.get_record('VDI', vdi_ref) return vdi_rec['uuid']
def VDI_snapshot(self, session_ref, vm_ref, _1): sr_ref = "fakesr" return fake.create_vdi('fakelabel', sr_ref, read_only=True)
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.call_xenapi("VDI.get_record", vdi_ref) return vdi_ref, {'uuid': vdi_rec['uuid'], }
def fake_get_vdi(session, vm_ref): vdi_ref = fake.create_vdi('derp', 'herp') vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref) return vdi_ref, {'uuid': vdi_rec['uuid'], }
def fake_move_disks(self, instance, disk_info): vdi_ref = fake.create_vdi('new', 'fake') return fake.get_record('VDI', vdi_ref)['uuid']
def host_call_plugin(self, _1, _2, _3, _4, _5): sr_ref = fake.get_all("SR")[0] vdi_ref = fake.create_vdi("", False, sr_ref, False) vdi_rec = fake.get_record("VDI", vdi_ref) return "<string>%s</string>" % vdi_rec["uuid"]
def fake_move_disks(self, instance, disk_info): vdi_ref = fake.create_vdi(instance['name'], 'fake') vdi_rec = fake.get_record('VDI', vdi_ref) vdi_rec['other_config']['nova_disk_type'] = 'root' return {'uuid': vdi_rec['uuid'], 'ref': vdi_ref}
def fake_move_disks(self, instance, disk_info): vdi_ref = fake.create_vdi(instance["name"], "fake") vdi_rec = fake.get_record("VDI", vdi_ref) vdi_rec["other_config"]["nova_disk_type"] = "root" return {"uuid": vdi_rec["uuid"], "ref": vdi_ref}
def _make_fake_vdi(): sr_ref = fake.get_all('SR')[0] vdi_ref = fake.create_vdi('', False, sr_ref, False) vdi_rec = fake.get_record('VDI', vdi_ref) return vdi_rec['uuid']
def _make_fake_vdi(): sr_ref = fake.get_all("SR")[0] vdi_ref = fake.create_vdi("", sr_ref) vdi_rec = fake.get_record("VDI", vdi_ref) return vdi_rec["uuid"]
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_get_vdi(session, vm_ref): vdi_ref = fake.create_vdi("derp", "herp") vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref) return vdi_ref, {"uuid": vdi_rec["uuid"]}