def setUp(self): super(TestBittorrentStore, self).setUp() self.store = bittorrent.BittorrentStore() self.mox = mox.Mox() self.flags(torrent_base_url='http://foo', connection_url='test_url', connection_password='******', group='xenserver') self.context = context.RequestContext('user', 'project', auth_token='foobar') fake.reset() stubs.stubout_session(self.stubs, fake.SessionBase) def mock_iter_eps(namespace): return [] self.stubs.Set(pkg_resources, 'iter_entry_points', mock_iter_eps) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.stubs.Set(vm_utils, 'get_sr_path', lambda *a, **kw: '/fake/sr/path')
def setUp(self): super(TestGlanceStore, self).setUp() self.store = glance.GlanceStore() self.flags(host='1.1.1.1', port=123, api_insecure=False, group='glance') self.flags(connection_url='test_url', connection_password='******', group='xenserver') self.context = context.RequestContext('user', 'project', auth_token='foobar') fake.reset() stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.stubs.Set(vm_utils, 'get_sr_path', lambda *a, **kw: '/fake/sr/path') self.instance = { 'uuid': 'blah', 'system_metadata': [], 'auto_disk_config': True, 'os_type': 'default', 'xenapi_use_agent': 'true' }
def setUp(self): super(TestBittorrentStore, self).setUp() self.store = bittorrent.BittorrentStore() self.mox = mox.Mox() self.flags(xenapi_torrent_base_url='http://foo', xenapi_connection_url='test_url', xenapi_connection_password='******') self.context = context.RequestContext( 'user', 'project', auth_token='foobar') fake.reset() stubs.stubout_session(self.stubs, fake.SessionBase) def mock_iter_eps(namespace): return [] self.stubs.Set(pkg_resources, 'iter_entry_points', mock_iter_eps) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.stubs.Set( vm_utils, 'get_sr_path', lambda *a, **kw: '/fake/sr/path') self.instance = {'uuid': 'blah', 'system_metadata': {'image_xenapi_use_agent': 'true'}, 'auto_disk_config': True, 'os_type': 'default', 'xenapi_use_agent': 'true'}
def setUp(self): super(TestGlanceStore, self).setUp() self.store = glance.GlanceStore() self.flags(api_servers=['http://localhost:9292'], group='glance') self.flags(connection_url='http://localhost', connection_password='******', group='xenserver') self.context = context.RequestContext('user', 'project', auth_token='foobar') fake.reset() stubs.stubout_session(self, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.stub_out('nova.virt.xenapi.vm_utils.get_sr_path', lambda *a, **kw: '/fake/sr/path') self.instance = { 'uuid': 'blah', 'system_metadata': [], 'auto_disk_config': True, 'os_type': 'default', 'xenapi_use_agent': 'true' }
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_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_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_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_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 setUp(self): super(GenerateDiskTestCase, self).setUp() self.flags(disable_process_locking=True, instance_name_template='%d', firewall_driver='nova.virt.xenapi.firewall.' 'Dom0IptablesFirewallDriver', xenapi_connection_url='test_url', xenapi_connection_password='******',) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.session.is_local_connection = False self.vm_ref = fake.create_vm("foo", "Running")
def setUp(self): super(VMUtilsSRPath, self).setUp() self.flags( disable_process_locking=True, instance_name_template='%d', firewall_driver='nova.virt.xenapi.firewall.' 'Dom0IptablesFirewallDriver', xenapi_connection_url='test_url', xenapi_connection_password='******', ) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.session.is_local_connection = False
def main(): config.parse_args(sys.argv) utils.monkey_patch() xenapi = xenapi_driver.XenAPIDriver() session = xenapi._session sr_ref = vm_utils.safe_find_sr(session) destroyed = vm_utils.destroy_cached_images( session, sr_ref, all_cached=CONF.all_cached, dry_run=CONF.dry_run) if '--verbose' in sys.argv: print '\n'.join(destroyed) print "Destroyed %d cached VDIs" % len(destroyed)
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_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 main(): config.parse_args(sys.argv) xenapi = xenapi_driver.XenAPIDriver(virtapi.VirtAPI()) session = xenapi._session vdi_refs = session.call_xenapi('VDI.get_all') for vdi_ref in vdi_refs: vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref) other_config = vdi_rec['other_config'] # Already set... if 'nova_instance_uuid' in other_config: continue name_label = vdi_rec['name_label'] # We only want name-labels of form instance-<UUID>-[optional-suffix] if not name_label.startswith('instance-'): continue # Parse out UUID instance_uuid = name_label.replace('instance-', '')[:36] if not uuidutils.is_uuid_like(instance_uuid): print "error: name label '%s' wasn't UUID-like" % name_label continue vdi_type = vdi_rec['name_description'] # We don't need a full instance record, just the UUID instance = {'uuid': instance_uuid} if not CONF.dry_run: vm_utils._set_vdi_info(session, vdi_ref, vdi_type, name_label, vdi_type, instance) if CONF.verbose: print "Setting other_config for instance_uuid=%s vdi_uuid=%s" % ( instance_uuid, vdi_rec['uuid']) if CONF.dry_run: print "Dry run completed"
def main(): """Main loop.""" config.parse_args(sys.argv) args = CONF(args=sys.argv[1:], usage='%(prog)s [options] --command={' + '|'.join(ALLOWED_COMMANDS) + '}') command = CONF.command if not command or command not in ALLOWED_COMMANDS: CONF.print_usage() sys.exit(1) if CONF.zombie_instance_updated_at_window < CONF.resize_confirm_window: raise Exception("`zombie_instance_updated_at_window` has to be longer" " than `resize_confirm_window`.") # NOTE(blamar) This tool does not require DB access, so passing in the # 'abstract' VirtAPI class is acceptable xenapi = xenapi_driver.XenAPIDriver(virtapi.VirtAPI()) if command == "list-vdis": if CONF.verbose: print "Connected VDIs:\n" orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) if CONF.verbose: print "\nOrphaned VDIs:\n" list_orphaned_vdis(orphaned_vdi_uuids) elif command == "clean-vdis": orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) clean_orphaned_vdis(xenapi, orphaned_vdi_uuids) elif command == "list-instances": orphaned_instances = find_orphaned_instances(xenapi) list_orphaned_instances(orphaned_instances) elif command == "clean-instances": orphaned_instances = find_orphaned_instances(xenapi) clean_orphaned_instances(xenapi, orphaned_instances) elif command == "test": doctest.testmod() else: print "Unknown command '%s'" % command sys.exit(1)
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(TestBittorrentStore, self).setUp() self.store = bittorrent.BittorrentStore() self.flags(torrent_base_url='http://foo', connection_url='test_url', connection_password='******', group='xenserver') self.context = context.RequestContext('user', 'project', auth_token='foobar') fake.reset() stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) self.session = driver._session self.stub_out('nova.virt.xenapi.vm_utils.get_sr_path', lambda *a, **kw: '/fake/sr/path')
def main(): """Main loop.""" args = CONF(args=sys.argv, usage='%prog [options] [' + '|'.join(ALLOWED_COMMANDS) + ']') if len(args) < 2: CONF.print_usage() sys.exit(1) command = args[1] if CONF.zombie_instance_updated_at_window < CONF.resize_confirm_window: raise Exception("`zombie_instance_updated_at_window` has to be longer" " than `resize_confirm_window`.") xenapi = xenapi_driver.XenAPIDriver() if command == "list-vdis": if CONF.verbose: print "Connected VDIs:\n" orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) if CONF.verbose: print "\nOrphaned VDIs:\n" list_orphaned_vdis(orphaned_vdi_uuids) elif command == "clean-vdis": orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) clean_orphaned_vdis(xenapi, orphaned_vdi_uuids) elif command == "list-instances": orphaned_instances = find_orphaned_instances(xenapi) list_orphaned_instances(orphaned_instances) elif command == "clean-instances": orphaned_instances = find_orphaned_instances(xenapi) clean_orphaned_instances(xenapi, orphaned_instances) elif command == "test": doctest.testmod() else: print "Unknown command '%s'" % command sys.exit(1)