def test_external_vm_recovery_errors(self): with MonkeyPatchScope([ (clientIF, 'Vm', FakeVm) ]): recovery.lookup_external_vms(self.cif) self.assertEqual(sorted(self.cif.pop_unknown_vm_ids()), []) self.assertEqual(sorted(self.cif.vmContainer.keys()), ['2'])
def test_lookup_external_vms(self): vm_ext = [True] * len(self.vm_uuids) self.conn.domains = _make_domains_collection( list(zip(self.vm_uuids, vm_ext))) self.cif.unknown_vm_ids = list(self.vm_uuids) recovery.lookup_external_vms(self.cif) assert set(self.cif.vmRequests.keys()) == \ set(self.vm_uuids) assert vm_ext == \ [conf['external'] for conf, _ in self.cif.vmRequests.values()]
def test_lookup_external_vms_fails(self): """ Failure to get the XML of an external VM while trying lookup """ vm_ext = [True] * len(self.vm_uuids) self.conn.domains = _make_domains_collection( list(zip(self.vm_uuids, vm_ext))) self.conn.domains['a'].XMLDesc = _raise self.cif.unknown_vm_ids = list(self.vm_uuids) recovery.lookup_external_vms(self.cif) self.assertEqual(set(self.cif.vmRequests.keys()), set(('b', )))
def test_lookup_external_vms_fails(self): """ Failure to get the XML of an external VM while trying lookup """ vm_ext = [True] * len(self.vm_uuids) self.conn.domains = _make_domains_collection( list(zip(self.vm_uuids, vm_ext))) self.conn.domains['a'].XMLDesc = _raise self.cif.unknown_vm_ids = list(self.vm_uuids) recovery.lookup_external_vms(self.cif) self.assertEqual( set(self.cif.vmRequests.keys()), set(('b',)) )
def test_lookup_external_vms(self): vm_ext = [True] * len(self.vm_uuids) self.conn.domains = _make_domains_collection( list(zip(self.vm_uuids, vm_ext))) self.cif.unknown_vm_ids = list(self.vm_uuids) recovery.lookup_external_vms(self.cif) self.assertEqual( set(self.cif.vmRequests.keys()), set(self.vm_uuids) ) self.assertEqual( vm_ext, [conf['external'] for conf, _ in self.cif.vmRequests.values()] )
def test_lookup_external_vms(self): vm_uuids = ('a', 'b',) vm_ext = [True] * len(vm_uuids) self.conn.domains = _make_domains_collection( zip(vm_uuids, vm_ext)) self.cif.unknown_vm_ids = list(vm_uuids) recovery.lookup_external_vms(self.cif) self.assertEqual( set(self.cif.vmRequests.keys()), set(vm_uuids) ) self.assertEqual( vm_ext, [conf['external'] for conf, _ in self.cif.vmRequests.values()] )
def start(cif, scheduler): global _operations global _executor _executor = executor.Executor(name="periodic", workers_count=_WORKERS, max_tasks=_TASKS, scheduler=scheduler, max_workers=_MAX_WORKERS) _executor.start() def per_vm_operation(func, period): disp = VmDispatcher(cif.getVMs, _executor, func, _timeout_from(period)) return Operation(disp, period, scheduler) _operations = [ # Needs dispatching because updating the volume stats needs # access to the storage, thus can block. per_vm_operation(UpdateVolumes, config.getint('irs', 'vol_size_sample_interval')), # Job monitoring need QEMU monitor access. per_vm_operation(BlockjobMonitor, config.getint('vars', 'vm_sample_jobs_interval')), # We do this only until we get high water mark notifications # from QEMU. It accesses storage and/or QEMU monitor, so can block, # thus we need dispatching. per_vm_operation(DriveWatermarkMonitor, config.getint('vars', 'vm_watermark_interval')), Operation(lambda: recovery.lookup_external_vms(cif), config.getint('sampling', 'external_vm_lookup_interval'), scheduler, exclusive=True, discard=False), Operation(containersconnection.monitor, config.getint('vars', 'vm_sample_interval'), scheduler), ] if config.getboolean('sampling', 'enable'): _operations.extend([ # libvirt sampling using bulk stats can block, but unresponsive # domains are handled inside VMBulkstatsMonitor for performance # reasons; thus, does not need dispatching. Operation( sampling.VMBulkstatsMonitor(libvirtconnection.get(cif), cif.getVMs, sampling.stats_cache), config.getint('vars', 'vm_sample_interval'), scheduler), Operation(sampling.HostMonitor(cif=cif), config.getint('vars', 'host_sample_stats_interval'), scheduler, timeout=config.getint('vars', 'host_sample_stats_interval'), exclusive=True, discard=False), ]) host.stats.start() for op in _operations: op.start()
def _create(cif, scheduler): def per_vm_operation(func, period): disp = VmDispatcher(cif.getVMs, _executor, func, _timeout_from(period)) return Operation(disp, period, scheduler) ops = [ # Needs dispatching because updating the volume stats needs # access to the storage, thus can block. per_vm_operation(UpdateVolumes, config.getint('irs', 'vol_size_sample_interval')), # Job monitoring need QEMU monitor access. per_vm_operation(BlockjobMonitor, config.getint('vars', 'vm_sample_jobs_interval')), # We do this only until we get high water mark notifications # from QEMU. It accesses storage and/or QEMU monitor, so can block, # thus we need dispatching. per_vm_operation(DriveWatermarkMonitor, config.getint('vars', 'vm_watermark_interval')), per_vm_operation( NvramDataMonitor, config.getint('sampling', 'nvram_data_update_interval')), per_vm_operation(TpmDataMonitor, config.getint('sampling', 'tpm_data_update_interval')), Operation(lambda: recovery.lookup_external_vms(cif), config.getint('sampling', 'external_vm_lookup_interval'), scheduler, exclusive=True, discard=False), Operation(lambda: _kill_long_paused_vms(cif), config.getint('vars', 'vm_kill_paused_time') // 2, scheduler, exclusive=True, discard=False), ] if config.getboolean('sampling', 'enable'): ops.extend([ # libvirt sampling using bulk stats can block, but unresponsive # domains are handled inside VMBulkstatsMonitor for performance # reasons; thus, does not need dispatching. Operation( sampling.VMBulkstatsMonitor(libvirtconnection.get(cif), cif.getVMs, sampling.stats_cache), config.getint('vars', 'vm_sample_interval'), scheduler), Operation(sampling.HostMonitor(cif=cif), config.getint('vars', 'host_sample_stats_interval'), scheduler, timeout=config.getint('vars', 'host_sample_stats_interval'), exclusive=True, discard=False), ]) return ops
def _create(cif, scheduler): def per_vm_operation(func, period): disp = VmDispatcher( cif.getVMs, _executor, func, _timeout_from(period)) return Operation(disp, period, scheduler) ops = [ # Needs dispatching because updating the volume stats needs # access to the storage, thus can block. per_vm_operation( UpdateVolumes, config.getint('irs', 'vol_size_sample_interval')), # Job monitoring need QEMU monitor access. per_vm_operation( BlockjobMonitor, config.getint('vars', 'vm_sample_jobs_interval')), # We do this only until we get high water mark notifications # from QEMU. It accesses storage and/or QEMU monitor, so can block, # thus we need dispatching. per_vm_operation( DriveWatermarkMonitor, config.getint('vars', 'vm_watermark_interval')), Operation( lambda: recovery.lookup_external_vms(cif), config.getint('sampling', 'external_vm_lookup_interval'), scheduler, exclusive=True, discard=False), Operation( lambda: _kill_long_paused_vms(cif), config.getint('vars', 'vm_kill_paused_time') // 2, scheduler, exclusive=True, discard=False), ] if config.getboolean('sampling', 'enable'): ops.extend([ # libvirt sampling using bulk stats can block, but unresponsive # domains are handled inside VMBulkstatsMonitor for performance # reasons; thus, does not need dispatching. Operation( sampling.VMBulkstatsMonitor( libvirtconnection.get(cif), cif.getVMs, sampling.stats_cache), config.getint('vars', 'vm_sample_interval'), scheduler), Operation( sampling.HostMonitor(cif=cif), config.getint('vars', 'host_sample_stats_interval'), scheduler, timeout=config.getint('vars', 'host_sample_stats_interval'), exclusive=True, discard=False), ]) return ops