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 check(): # check that the VM has a VBD attached to it # Get XenAPI record for VBD vbds = xenapi_fake.get_all('VBD') vbd = xenapi_fake.get_record('VBD', vbds[0]) vm_ref = vbd['VM'] self.assertEqual(vm_ref, vm)
def test_get_dom_id_works_with_vmref(self): instance = {"name": "dummy"} vm_ref = self._create_vm("dummy", "Running") vm_rec = xenapi_fake.get_record("VM", vm_ref) self.assertEqual(vm_rec["domid"], self.vmops._get_dom_id(vm_ref=vm_ref))
def test_get_dom_id_raises_not_found(self): instance = {"name": "dummy"} vm_ref = self._create_vm("notdummy", "Running") vm_rec = xenapi_fake.get_record("VM", vm_ref) self.assertRaises(exception.NotFound, self.vmops._get_dom_id, instance)
def ensure_vbd_was_torn_down(): vbd_labels = [] for vbd_ref in xenapi_fake.get_all('VBD'): vbd_rec = xenapi_fake.get_record('VBD', vbd_ref) vbd_labels.append(vbd_rec["vm_name_label"]) self.assertEquals(vbd_labels, ['1'])
def test_spawn_with_network_qos(self): self._create_instance() for vif_ref in xenapi_fake.get_all('VIF'): vif_rec = xenapi_fake.get_record('VIF', vif_ref) self.assertEquals(vif_rec['qos_algorithm_type'], 'ratelimit') self.assertEquals(vif_rec['qos_algorithm_params']['kbps'], str(3 * 1024))
def VM_start(self, _1, ref, _2, _3): vm = fake.get_record("VM", ref) if vm["power_state"] != "Halted": raise fake.Failure(["VM_BAD_POWER_STATE", ref, "Halted", vm["power_state"]]) vm["power_state"] = "Running" vm["is_a_template"] = False vm["is_control_domain"] = False
def VM_start(self, _1, ref, _2, _3): vm = fake.get_record('VM', ref) if vm['power_state'] != 'Halted': raise fake.Failure(['VM_BAD_POWER_STATE', ref, 'Halted', vm['power_state']]) vm['power_state'] = 'Running' vm['is_a_template'] = False vm['is_control_domain'] = False
def VM_start(self, _1, ref, _2, _3): vm = fake.get_record('VM', ref) if vm['power_state'] != 'Halted': raise fake.Failure( ['VM_BAD_POWER_STATE', ref, 'Halted', vm['power_state']]) vm['power_state'] = 'Running' vm['is_a_template'] = False vm['is_control_domain'] = False
def ensure_vm_was_torn_down(): vm_labels = [] for vm_ref in xenapi_fake.get_all('VM'): vm_rec = xenapi_fake.get_record('VM', vm_ref) if not vm_rec["is_control_domain"]: vm_labels.append(vm_rec["name_label"]) self.assertEquals(vm_labels, ['1'])
def VDI_introduce(self, _1, uuid, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11): valid_vdi = False refs = fake.get_all("VDI") for ref in refs: rec = fake.get_record("VDI", ref) if rec["uuid"] == uuid: valid_vdi = True if not valid_vdi: raise fake.Failure([["INVALID_VDI", "session", self._session]])
def VM_start(self, _1, ref, _2, _3): vm = fake.get_record('VM', ref) if vm['power_state'] != 'Halted': raise XenAPI.Failure( ['VM_BAD_POWER_STATE', ref, 'Halted', vm['power_state']]) vm['power_state'] = 'Running' vm['is_a_template'] = False vm['is_control_domain'] = False vm['domid'] = random.randrange(1, 1 << 16) return vm
def VM_start(self, _1, ref, _2, _3): vm = fake.get_record('VM', ref) if vm['power_state'] != 'Halted': raise XenAPI.Failure(['VM_BAD_POWER_STATE', ref, 'Halted', vm['power_state']]) vm['power_state'] = 'Running' vm['is_a_template'] = False vm['is_control_domain'] = False vm['domid'] = random.randrange(1, 1 << 16) return vm
def VDI_introduce(self, _1, uuid, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11): valid_vdi = False refs = fake.get_all('VDI') for ref in refs: rec = fake.get_record('VDI', ref) if rec['uuid'] == uuid: valid_vdi = True if not valid_vdi: raise fake.Failure([['INVALID_VDI', 'session', self._session]])
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 ensure_vdi_was_torn_down(): for vdi_ref in xenapi_fake.get_all('VDI'): vdi_rec = xenapi_fake.get_record('VDI', vdi_ref) name_label = vdi_rec["name_label"] self.assert_(not name_label.endswith('snapshot'))
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('', sr_ref) vdi_rec = fake.get_record('VDI', vdi_ref) return vdi_rec['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 PBD_unplug(self, _1, ref): rec = fake.get_record("PBD", ref) rec["currently-attached"] = False
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 test_spawn_with_network_qos(self): self._create_instance() for vif_ref in xenapi_fake.get_all("VIF"): vif_rec = xenapi_fake.get_record("VIF", vif_ref) self.assertEquals(vif_rec["qos_algorithm_type"], "ratelimit") self.assertEquals(vif_rec["qos_algorithm_params"]["kbps"], str(3 * 1024))
def create_vm(self, name, state="Running"): vm_ref = xenapi_fake.create_vm(name, state) self.vms.append(vm_ref) vm = xenapi_fake.get_record("VM", vm_ref) return vm, vm_ref
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 _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 PBD_unplug(self, _1, ref): rec = fake.get_record('PBD', ref) rec['currently-attached'] = False
def fake_move_disks(self, instance, disk_info): vdi_ref = fake.create_vdi('new', 'fake') return fake.get_record('VDI', vdi_ref)['uuid']
def create_vm(self, name, state="running"): vm_ref = xenapi_fake.create_vm(name, state) self.vms.append(vm_ref) vm = xenapi_fake.get_record("VM", vm_ref) return vm, vm_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}