def poll_perfmon(self, context): """ Periodically polls to refresh the performance data of VmHost and Vm in inventory """ LOG.info(_("Polling performance data periodically for Vmhosts and Vms")) def _worker(uuid, conn_driver, perfmon_type): conn_driver.update_perfdata(uuid, perfmon_type) for host_id in InventoryCacheManager.get_inventory_cache()[Constants.VmHost].keys(): conn_driver = InventoryCacheManager.get_compute_conn_driver(host_id, Constants.VmHost) if conn_driver is not None: self.perf_green_pool.spawn_n(_worker, host_id, conn_driver, Constants.VmHost) else: LOG.error(_("Error in monitoring performance data for Host %s ") % host_id) host_obj = InventoryCacheManager.get_inventory_cache()[Constants.VmHost][host_id] for vm_id in host_obj.get_virtualMachineIds(): vm_obj = InventoryCacheManager.get_object_from_cache(vm_id, Constants.Vm) if vm_obj.get_powerState() == Constants.VM_POWER_STATES[1]: conn_driver = InventoryCacheManager.get_compute_conn_driver(vm_id, Constants.Vm) if conn_driver is not None: self.perf_green_pool.spawn_n(_worker, vm_id, conn_driver, Constants.Vm) else: LOG.error( _( "Error in monitoring performance \ data for VM %s " ) % vm_id )
def test_processVmDeletes(self): self.mock.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id InventoryCacheManager.get_object_from_cache( deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mock.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.assertEquals(self.libvirtVM.processVmDeletes(cachedList, updatedList), None) self.assertTrue(deleted_vm_id not in InventoryCacheManager.get_inventory_cache().keys()) self.mock.stubs.UnsetAll()
def test_processVmDeletes(self): self.mock.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache' ) deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id InventoryCacheManager.get_object_from_cache(deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mock.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.assertEquals(self.libvirtVM.processVmDeletes(cachedList, updatedList), None) self.assertTrue(deleted_vm_id not in InventoryCacheManager.get_inventory_cache().keys()) self.mock.stubs.UnsetAll()
def poll_perfmon(self, context): """ Periodically polls to refresh the performance data of VmHost and Vm in inventory """ LOG.info( _('Polling performance data periodically for Vmhosts and Vms')) def _worker(uuid, conn_driver, perfmon_type): conn_driver.update_perfdata(uuid, perfmon_type) for host_id in InventoryCacheManager.\ get_inventory_cache()[Constants.VmHost].keys(): conn_driver = InventoryCacheManager.get_compute_conn_driver( host_id, Constants.VmHost) if conn_driver is not None: self.perf_green_pool.spawn_n(_worker, host_id, conn_driver, Constants.VmHost) else: LOG.error(_('Error in monitoring performance data for Host %s ' ) % host_id) host_obj = InventoryCacheManager.get_inventory_cache( )[Constants.VmHost][host_id] for vm_id in host_obj.get_virtualMachineIds(): vm_obj = InventoryCacheManager.get_object_from_cache( vm_id, Constants.Vm) if vm_obj.get_powerState() \ == Constants.VM_POWER_STATES[1]: conn_driver = InventoryCacheManager.\ get_compute_conn_driver(vm_id, Constants.Vm) if conn_driver is not None: self.perf_green_pool.spawn_n(_worker, vm_id, conn_driver, Constants.Vm) else: LOG.error(_('Error in monitoring performance \ data for VM %s ') % vm_id)
def test_host_removed_event_none_host(self): deleted_host = VmHost() deleted_host.set_id('compute1') deleted_host.set_name('compute1') self.mox.StubOutWithMock(api, 'vm_host_get_all') api.vm_host_get_all(mox.IgnoreArg()).AndReturn([deleted_host]) self.mox.StubOutWithMock(api, 'vm_get_all') api.vm_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'storage_volume_get_all') api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'subnet_get_all') api.subnet_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(nova_db, 'compute_node_get_all') nova_db.compute_node_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'vm_host_delete_by_ids') api.vm_host_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock( InventoryCacheManager, 'get_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( 'compute1', Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() compute_service = dict(host='host1') compute = dict(id='compute1', hypervisor_type='fake', service=compute_service) rm_context = \ rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'], rmIpAddress=compute_service['host'], rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory().clear() InventoryCacheManager.get_all_compute_inventory()['compute1'] = \ ComputeInventory(rm_context) InventoryCacheManager.get_compute_inventory( 'compute1').update_compute_info(rm_context, deleted_host) self.assertEquals( len(InventoryCacheManager.get_all_compute_inventory()), 1) InventoryCacheManager.get_inventory_cache( )[Constants.VmHost][deleted_host.get_id()] = None inv_manager = InventoryManager() inv_manager._refresh_from_db(None) self.assertEquals( len(InventoryCacheManager.get_all_compute_inventory()), 0) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
def test_host_removed_event_none_host(self): deleted_host = VmHost() deleted_host.set_id('compute1') deleted_host.set_name('compute1') self.mox.StubOutWithMock(api, 'vm_host_get_all') api.vm_host_get_all(mox.IgnoreArg()).AndReturn([deleted_host]) self.mox.StubOutWithMock(api, 'vm_get_all') api.vm_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'storage_volume_get_all') api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'subnet_get_all') api.subnet_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(nova_db, 'compute_node_get_all') nova_db.compute_node_get_all(mox.IgnoreArg()).AndReturn([]) self.mox.StubOutWithMock(api, 'vm_host_delete_by_ids') api.vm_host_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( 'compute1', Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() compute_service = dict(host='host1') compute = dict(id='compute1', hypervisor_type='fake', service=compute_service) rm_context = \ rmcontext.ComputeRMContext(rmType=compute['hypervisor_type' ], rmIpAddress=compute_service['host'], rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory().clear() InventoryCacheManager.get_all_compute_inventory( )['compute1'] = ComputeInventory(rm_context) InventoryCacheManager.get_compute_inventory( 'compute1').update_compute_info(rm_context, deleted_host) self.assertEquals( len(InventoryCacheManager.get_all_compute_inventory()), 1) InventoryCacheManager.get_inventory_cache()[Constants.VmHost][ deleted_host.get_id()] = None inv_manager = InventoryManager() inv_manager._refresh_from_db(None) self.assertEquals( len(InventoryCacheManager.get_all_compute_inventory()), 0) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
def test_get_inventory_cache(self): self._createInvCache() self.assertEquals(len(InventoryCacheManager.get_inventory_cache()), 4) self.mox.UnsetStubs()