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 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 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 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_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 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 test_create_iscsi_storage(self): """This shows how to test helper classes' methods.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass') helper = volume_utils.VolumeHelper helper.XenAPI = session.get_imported_xenapi() vol = self._create_volume() info = helper.parse_volume_info(vol['id'], '/dev/sdc') label = 'SR-%s' % vol['id'] description = 'Test-SR' sr_ref = helper.create_iscsi_storage(session, info, label, description) srs = xenapi_fake.get_all('SR') self.assertEqual(sr_ref, srs[0]) db.volume_destroy(context.get_admin_context(), vol['id'])
def test_create_iscsi_storage(self): """This shows how to test helper classes' methods.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) session = xenapi_conn.XenAPISession("test_url", "root", "test_pass") helper = volume_utils.VolumeHelper helper.XenAPI = session.get_imported_xenapi() vol = self._create_volume() info = helper.parse_volume_info(vol["id"], "/dev/sdc") label = "SR-%s" % vol["id"] description = "Test-SR" sr_ref = helper.create_iscsi_storage(session, info, label, description) srs = xenapi_fake.get_all("SR") self.assertEqual(sr_ref, srs[0]) db.volume_destroy(context.get_admin_context(), vol["id"])
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 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 _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 _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 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']