def test_get_vdis_for_boot_from_iscsi_vol_missing_sr_uuid(self): dev_params = get_fake_dev_params(ISCSI_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertNotEquals(result["root"]["uuid"], None)
def test_get_vdis_for_boot_from_vol_with_sr_uuid(self): dev_params = get_fake_dev_params(XENSM_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertEquals(result["root"]["uuid"], "falseVDI")
def setUp(self): super(XenAPIVMTestCase, self).setUp() self.network = utils.import_object(FLAGS.network_manager) self.stubs = stubout.StubOutForTesting() self.flags(xenapi_connection_url='test_url', xenapi_connection_password='******', instance_name_template='%d') xenapi_fake.reset() xenapi_fake.create_local_srs() xenapi_fake.create_local_pifs() db_fakes.stub_out_db_instance_api(self.stubs) xenapi_fake.create_network('fake', FLAGS.flat_network_bridge) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) stubs.stubout_get_this_vm_uuid(self.stubs) stubs.stubout_stream_disk(self.stubs) stubs.stubout_is_vdi_pv(self.stubs) self.stubs.Set(vmops.VMOps, 'reset_network', reset_network) self.stubs.Set(vmops.VMOps, '_find_rescue_vbd_ref', _find_rescue_vbd_ref) stubs.stub_out_vm_methods(self.stubs) glance_stubs.stubout_glance_client(self.stubs) fake_utils.stub_out_utils_execute(self.stubs) self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.conn = xenapi_conn.get_connection(False)
def test_finish_migrate_no_resize_vdi(self): instance = db.instance_create(self.context, self.values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway6': 'dead:beef::1', 'ip6s': [{'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64'}], 'ips': [{'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0'}], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] # Resize instance would be determined by the compute call conn.finish_migration(instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=False)
def test_finish_migrate_no_local_storage(self): tiny_type_id = \ instance_types.get_instance_type_by_name('m1.tiny')['id'] self.instance_values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway6': 'dead:beef::1', 'ip6s': [{'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64'}], 'ips': [{'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0'}], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True)
def setUp(self): super(XenAPIVMTestCase, self).setUp() self.manager = manager.AuthManager() self.user = self.manager.create_user("fake", "fake", "fake", admin=True) self.project = self.manager.create_project("fake", "fake", "fake") self.network = utils.import_object(FLAGS.network_manager) self.stubs = stubout.StubOutForTesting() self.flags( xenapi_connection_url="test_url", xenapi_connection_password="******", instance_name_template="%d" ) xenapi_fake.reset() xenapi_fake.create_local_srs() xenapi_fake.create_local_pifs() db_fakes.stub_out_db_instance_api(self.stubs) xenapi_fake.create_network("fake", FLAGS.flat_network_bridge) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) stubs.stubout_get_this_vm_uuid(self.stubs) stubs.stubout_stream_disk(self.stubs) stubs.stubout_is_vdi_pv(self.stubs) self.stubs.Set(VMOps, "reset_network", reset_network) stubs.stub_out_vm_methods(self.stubs) glance_stubs.stubout_glance_client(self.stubs, glance_stubs.FakeGlance) fake_utils.stub_out_utils_execute(self.stubs) self.context = context.RequestContext("fake", "fake", False) self.conn = xenapi_conn.get_connection(False)
def test_finish_migrate_no_resize_vdi(self): instance = db.instance_create(self.context, self.values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [ ( {"bridge": "fa0", "id": 0, "injected": False}, { "broadcast": "192.168.0.255", "dns": ["192.168.0.1"], "gateway": "192.168.0.1", "gateway6": "dead:beef::1", "ip6s": [{"enabled": "1", "ip": "dead:beef::dcad:beff:feef:0", "netmask": "64"}], "ips": [{"enabled": "1", "ip": "192.168.0.100", "netmask": "255.255.255.0"}], "label": "fake", "mac": "DE:AD:BE:EF:00:00", "rxtx_cap": 3, }, ) ] # Resize instance would be determined by the compute call conn.finish_migration( self.context, instance, dict(base_copy="hurr", cow="durr"), network_info, resize_instance=False )
def setUp(self): super(XenAPIManagedDiskTestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.flags(target_host='127.0.0.1', xenapi_connection_url='test_url', xenapi_connection_password='******') stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) xenapi_fake.reset() self.conn = xenapi_conn.get_connection(False) self.user_id = 'fake' self.project_id = 'fake' self.instance_values = {'id': 1, 'project_id': self.project_id, 'user_id': self.user_id, 'image_ref': 1, 'kernel_id': 2, 'ramdisk_id': 3, 'local_gb': 20, 'instance_type_id': '3', # m1.large 'os_type': 'linux', 'architecture': 'x86-64'} self.context = context.RequestContext(self.user_id, self.project_id) @classmethod def fake_create_vbd(cls, session, vm_ref, vdi_ref, userdevice, bootable=True): pass self.stubs.Set(vm_utils.VMHelper, "create_vbd", fake_create_vbd)
def test_migrate_disk_and_power_off(self): instance = db.instance_create(self.context, self.instance_values) instance_type = db.instance_type_get_by_name(self.context, 'm1.large') stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn.migrate_disk_and_power_off(self.context, instance, '127.0.0.1', instance_type)
def test_finish_migrate_no_local_storage(self): tiny_type_id = \ instance_types.get_instance_type_by_name('m1.tiny')['id'] self.instance_values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway6': 'dead:beef::1', 'ip6s': [{'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64'}], 'ips': [{'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0'}], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'} conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, image_meta, resize_instance=True)
def setUp(self): super(XenAPIAutoDiskConfigTestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.flags(target_host='127.0.0.1', xenapi_connection_url='test_url', xenapi_connection_password='******') stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) xenapi_fake.reset() self.conn = xenapi_conn.get_connection(False) self.user_id = 'fake' self.project_id = 'fake' self.instance_values = {'id': 1, 'project_id': self.project_id, 'user_id': self.user_id, 'image_ref': 1, 'kernel_id': 2, 'ramdisk_id': 3, 'local_gb': 20, 'instance_type_id': '3', # m1.large 'os_type': 'linux', 'architecture': 'x86-64'} self.context = context.RequestContext(self.user_id, self.project_id) @classmethod def fake_create_vbd(cls, session, vm_ref, vdi_ref, userdevice, bootable=True): pass self.stubs.Set(volume_utils.VolumeHelper, "create_vbd", fake_create_vbd)
def test_get_vdi_uuid_for_volume_from_iscsi_vol_missing_sr_uuid(self): connection_data = get_fake_connection_data(ISCSI_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) vdi_uuid = vm_utils.get_vdi_uuid_for_volume(driver._session, connection_data) self.assertNotEquals(vdi_uuid, None)
def _test_spawn(self, image_id, kernel_id, ramdisk_id, instance_type="m1.large", os_type="linux"): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = { 'name': 1, 'id': 1, 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': image_id, 'kernel_id': kernel_id, 'ramdisk_id': ramdisk_id, 'instance_type': instance_type, 'mac_address': 'aa:bb:cc:dd:ee:ff', 'os_type': os_type } conn = xenapi_conn.get_connection(False) instance = db.instance_create(values) conn.spawn(instance) self.create_vm_record(conn, os_type) self.check_vm_record(conn)
def test_get_vdi_uuid_for_volume_with_sr_uuid(self): connection_data = get_fake_connection_data(XENSM_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) vdi_uuid = vm_utils.get_vdi_uuid_for_volume(driver._session, connection_data) self.assertEquals(vdi_uuid, "falseVDI")
def test_get_vdi_uuid_for_volume_with_sr_uuid(self): connection_data = get_fake_connection_data(XENSM_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) vdi_uuid = vm_utils.get_vdi_uuid_for_volume(driver._session, connection_data) self.assertEquals(vdi_uuid, 'falseVDI')
def test_get_vdis_for_boot_from_iscsi_vol_missing_sr_uuid(self): dev_params = get_fake_dev_params(ISCSI_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertNotEquals(result['root']['uuid'], None)
def test_attach_volume_raise_exception(self): """This shows how to test when exceptions are raised.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeFailedTests) conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.context, self.values) xenapi_fake.create_vm(instance.name, "Running") self.assertRaises(Exception, conn.attach_volume, instance.name, volume["id"], "/dev/sdc")
def test_get_vdis_for_boot_from_vol_with_sr_uuid(self): dev_params = get_fake_dev_params(XENSM_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertEquals(result['root']['uuid'], 'falseVDI')
def test_get_vdi_uuid_for_volume_failure(self): stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) def bad_introduce_sr(session, sr_uuid, label, sr_params): return None self.stubs.Set(volume_utils, "introduce_sr", bad_introduce_sr) connection_data = get_fake_connection_data(XENSM_TYPE) self.assertRaises(exception.NovaException, vm_utils.get_vdi_uuid_for_volume, driver._session, connection_data)
def test_get_instance_vdis_for_sr_no_vbd(self): vm_ref = fake.create_vm("foo", "Running") sr_ref = fake.create_sr() 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([], result)
def test_attach_volume_raise_exception(self): """This shows how to test when exceptions are raised.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeFailedTests) conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.context, self.values) xenapi_fake.create_vm(instance.name, 'Running') self.assertRaises(Exception, conn.attach_volume, instance.name, volume['id'], '/dev/sdc')
def test_parse_volume_info_raise_exception(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() # oops, wrong mount point! self.assertRaises(volume_utils.StorageError, helper.parse_volume_info, vol["id"], "/dev/sd") db.volume_destroy(context.get_admin_context(), vol["id"])
def test_parse_volume_info_raise_exception(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() # oops, wrong mount point! self.assertRaises(volume_utils.StorageError, helper.parse_volume_info, vol['id'], '/dev/sd') db.volume_destroy(context.get_admin_context(), vol['id'])
def setUp(self): super(XenAPIBWUsageTestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.stubs.Set(vm_utils.VMHelper, "compile_metrics", XenAPIBWUsageTestCase._fake_compile_metrics) self.flags(target_host='127.0.0.1', xenapi_connection_url='test_url', xenapi_connection_password='******') stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) xenapi_fake.reset() self.conn = xenapi_conn.get_connection(False)
def test_finish_migrate(self): instance = db.instance_create(self.context, self.values) self.called = False self.fake_vm_start_called = False def fake_vm_start(*args, **kwargs): self.fake_vm_start_called = True def fake_vdi_resize(*args, **kwargs): self.called = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({ 'bridge': 'fa0', 'id': 0, 'injected': False }, { 'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway6': 'dead:beef::1', 'ip6s': [{ 'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64' }], 'ips': [{ 'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0' }], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3 })] conn.finish_migration(self.context, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True) self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, True)
def test_get_instance_vdis_for_sr_no_vbd(self): vm_ref = fake.create_vm("foo", "Running") sr_ref = fake.create_sr() 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([], result)
def test_get_vdi_uuid_for_volume_failure(self): stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) def bad_introduce_sr(session, sr_uuid, label, sr_params): return None self.stubs.Set(volume_utils, 'introduce_sr', bad_introduce_sr) connection_data = get_fake_connection_data(XENSM_TYPE) self.assertRaises(exception.NovaException, vm_utils.get_vdi_uuid_for_volume, driver._session, connection_data)
def test_migrate_disk_and_power_off_passes_exceptions(self): instance = db.instance_create(self.context, self.instance_values) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) def fake_raise(*args, **kwargs): raise exception.MigrationError(reason='test failure') self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise) conn = xenapi_conn.get_connection(False) self.assertRaises(exception.MigrationError, conn.migrate_disk_and_power_off, self.context, instance, '127.0.0.1')
def test_migrate_disk_and_power_off_passes_exceptions(self): instance = db.instance_create(self.context, self.instance_values) instance_type = db.instance_type_get_by_name(self.context, 'm1.large') stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) def fake_raise(*args, **kwargs): raise exception.MigrationError(reason='test failure') self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise) conn = xenapi_conn.get_connection(False) self.assertRaises(exception.MigrationError, conn.migrate_disk_and_power_off, self.context, instance, '127.0.0.1', instance_type)
def setUp(self): super(XenSMTestCase, self).setUp() self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.flags(connection_type='xenapi', xenapi_connection_url='http://test_url', xenapi_connection_username='******', xenapi_connection_password='******') stubs.stubout_session(self.stubs, xenapi_fake.SessionBase) xenapi_fake.reset() self.driver = xensm.XenSMDriver() self.driver.db = db
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_get_vdis_for_boot_from_vol(self): dev_params = {'sr_uuid': 'falseSR', 'name_label': 'fake_storage', 'name_description': 'test purposes', 'server': 'myserver', 'serverpath': '/local/scratch/myname', 'sr_type': 'nfs', 'introduce_sr_keys': ['server', 'serverpath', 'sr_type'], 'vdi_uuid': 'falseVDI'} stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertEquals(result['root']['uuid'], 'falseVDI')
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 test_revert_migration(self): instance = self._create_instance() class VMOpsMock: def __init__(self): self.revert_migration_called = False def revert_migration(self, instance): self.revert_migration_called = True stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn._vmops = VMOpsMock() conn.revert_migration(instance) self.assertTrue(conn._vmops.revert_migration_called)
def test_revert_migration(self): instance = self._create_instance() class VMOpsMock(): def __init__(self): self.revert_migration_called = False def revert_migration(self, instance): self.revert_migration_called = True stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn._vmops = VMOpsMock() conn.revert_migration(instance) self.assertTrue(conn._vmops.revert_migration_called)
def test_resize_xenserver_6(self): instance = db.instance_create(self.context, self.values) called = {'resize': False} def fake_vdi_resize(*args, **kwargs): called['resize'] = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests, product_version=(6, 0, 0)) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) conn._vmops.resize_instance(instance, '') self.assertEqual(called['resize'], True)
def test_resize_xenserver_6(self): instance = db.instance_create(self.context, self.instance_values) called = {'resize': False} def fake_vdi_resize(*args, **kwargs): called['resize'] = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests, product_version=(6, 0, 0)) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) conn._vmops._resize_instance(instance, '') self.assertEqual(called['resize'], True)
def test_get_vdis_for_boot_from_vol(self): dev_params = { "sr_uuid": "falseSR", "name_label": "fake_storage", "name_description": "test purposes", "server": "myserver", "serverpath": "/local/scratch/myname", "sr_type": "nfs", "introduce_sr_keys": ["server", "serverpath", "sr_type"], "vdi_uuid": "falseVDI", } stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertEquals(result["root"]["uuid"], "falseVDI")
def test_revert_migrate(self): instance = db.instance_create(self.context, self.instance_values) self.called = False self.fake_vm_start_called = False self.fake_finish_revert_migration_called = False def fake_vm_start(*args, **kwargs): self.fake_vm_start_called = True def fake_vdi_resize(*args, **kwargs): self.called = True def fake_finish_revert_migration(*args, **kwargs): self.fake_finish_revert_migration_called = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) self.stubs.Set(vmops.VMOps, 'finish_revert_migration', fake_finish_revert_migration) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway_v6': 'dead:beef::1', 'ip6s': [{'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64'}], 'ips': [{'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0'}], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'} conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, image_meta, resize_instance=True) self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, True) conn.finish_revert_migration(instance) self.assertEqual(self.fake_finish_revert_migration_called, True)
def test_revert_migrate(self): instance = db.instance_create(self.context, self.values) self.called = False self.fake_vm_start_called = False self.fake_revert_migration_called = False def fake_vm_start(*args, **kwargs): self.fake_vm_start_called = True def fake_vdi_resize(*args, **kwargs): self.called = True def fake_revert_migration(*args, **kwargs): self.fake_revert_migration_called = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, "_start", fake_vm_start) self.stubs.Set(vmops.VMOps, "revert_migration", fake_revert_migration) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [ ( {"bridge": "fa0", "id": 0, "injected": False}, { "broadcast": "192.168.0.255", "dns": ["192.168.0.1"], "gateway": "192.168.0.1", "gateway6": "dead:beef::1", "ip6s": [{"enabled": "1", "ip": "dead:beef::dcad:beff:feef:0", "netmask": "64"}], "ips": [{"enabled": "1", "ip": "192.168.0.100", "netmask": "255.255.255.0"}], "label": "fake", "mac": "DE:AD:BE:EF:00:00", "rxtx_cap": 3, }, ) ] conn.finish_migration( self.context, instance, dict(base_copy="hurr", cow="durr"), network_info, resize_instance=True ) self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, True) conn.revert_migration(instance) self.assertEqual(self.fake_revert_migration_called, True)
def test_get_vdis_for_boot_from_vol(self): dev_params = { 'sr_uuid': 'falseSR', 'name_label': 'fake_storage', 'name_description': 'test purposes', 'server': 'myserver', 'serverpath': '/local/scratch/myname', 'sr_type': 'nfs', 'introduce_sr_keys': ['server', 'serverpath', 'sr_type'], 'vdi_uuid': 'falseVDI' } stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) result = vm_utils.get_vdis_for_boot_from_vol(driver._session, dev_params) self.assertEquals(result['root']['uuid'], 'falseVDI')
def _test_spawn(self, image_id, kernel_id, ramdisk_id, instance_type="m1.large"): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = {'name': 1, 'id': 1, 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': image_id, 'kernel_id': kernel_id, 'ramdisk_id': ramdisk_id, 'instance_type': instance_type, 'mac_address': 'aa:bb:cc:dd:ee:ff', } conn = xenapi_conn.get_connection(False) instance = db.instance_create(values) conn.spawn(instance) self.check_vm_record(conn)
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 test_attach_volume(self): """This shows how to test Ops classes' methods.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.context, self.values) vm = xenapi_fake.create_vm(instance.name, 'Running') result = conn.attach_volume(instance.name, volume['id'], '/dev/sdc') 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) check()
def test_get_vdis_for_boot_from_vol_failure(self): stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) def bad_introduce_sr(session, sr_uuid, label, sr_params): return None self.stubs.Set(volume_utils, "introduce_sr", bad_introduce_sr) dev_params = { "sr_uuid": "falseSR", "name_label": "fake_storage", "name_description": "test purposes", "server": "myserver", "serverpath": "/local/scratch/myname", "sr_type": "nfs", "introduce_sr_keys": ["server", "serverpath", "sr_type"], "vdi_uuid": "falseVDI", } self.assertRaises(exception.NovaException, vm_utils.get_vdis_for_boot_from_vol, driver._session, dev_params)
def test_get_vdis_for_boot_from_vol_failure(self): stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) def bad_introduce_sr(session, sr_uuid, label, sr_params): return None self.stubs.Set(volume_utils, 'introduce_sr', bad_introduce_sr) dev_params = { 'sr_uuid': 'falseSR', 'name_label': 'fake_storage', 'name_description': 'test purposes', 'server': 'myserver', 'serverpath': '/local/scratch/myname', 'sr_type': 'nfs', 'introduce_sr_keys': ['server', 'serverpath', 'sr_type'], 'vdi_uuid': 'falseVDI' } self.assertRaises(exception.NovaException, vm_utils.get_vdis_for_boot_from_vol, driver._session, dev_params)
def setUp(self): super(XenAPIVMTestCase, self).setUp() self.manager = manager.AuthManager() self.user = self.manager.create_user('fake', 'fake', 'fake', admin=True) self.project = self.manager.create_project('fake', 'fake', 'fake') self.network = utils.import_object(FLAGS.network_manager) self.stubs = stubout.StubOutForTesting() FLAGS.xenapi_connection_url = 'test_url' FLAGS.xenapi_connection_password = '******' xenapi_fake.reset() xenapi_fake.create_local_srs() db_fakes.stub_out_db_instance_api(self.stubs) xenapi_fake.create_network('fake', FLAGS.flat_network_bridge) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) stubs.stubout_get_this_vm_uuid(self.stubs) stubs.stubout_stream_disk(self.stubs) stubs.stubout_is_vdi_pv(self.stubs) self.stubs.Set(VMOps, 'reset_network', reset_network) glance_stubs.stubout_glance_client(self.stubs, glance_stubs.FakeGlance) self.conn = xenapi_conn.get_connection(False)
def test_finish_resize(self): instance = db.instance_create(self.values) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn.finish_resize(instance, dict(base_copy='hurr', cow='durr'))
def test_migrate_disk_and_power_off(self): instance = db.instance_create(self.context, self.values) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn.migrate_disk_and_power_off(instance, '127.0.0.1')