def _createCache(self): self.mox.StubOutWithMock(api, "vm_host_get_all") vmhost = VmHost() vmhost.set_id("vmhost1") vmhost1 = VmHost() vmhost1.set_id("vmhost2") vm = Vm() vm.set_id("vm1") vm.set_powerState(Constants.VM_POWER_STATES[1]) vm.set_vmHostId("vmhost1") vm1 = Vm() vm1.set_id("vm2") vm1.set_powerState(Constants.VM_POWER_STATES[1]) vm1.set_vmHostId("vmhost2") vmhost.set_virtualMachineIds(["vm1", "vm2"]) stPool = StorageVolume() stPool.set_id("stpool1") subNet = Subnet() subNet.set_id("net1") api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1]) self.mox.StubOutWithMock(api, "vm_get_all") api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1]) self.mox.StubOutWithMock(api, "storage_volume_get_all") api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool]) self.mox.StubOutWithMock(api, "subnet_get_all") api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
def _createCache(self): self.mox.StubOutWithMock(api, 'vm_host_get_all') vmhost = VmHost() vmhost.set_id('vmhost1') vmhost1 = VmHost() vmhost1.set_id('vmhost2') vm = Vm() vm.set_id('vm1') vm.set_powerState(Constants.VM_POWER_STATES[1]) vm.set_vmHostId('vmhost1') vm1 = Vm() vm1.set_id('vm2') vm1.set_powerState(Constants.VM_POWER_STATES[1]) vm1.set_vmHostId('vmhost2') vmhost.set_virtualMachineIds(['vm1', 'vm2']) stPool = StorageVolume() stPool.set_id('stpool1') subNet = Subnet() subNet.set_id('net1') api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1]) self.mox.StubOutWithMock(api, 'vm_get_all') api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1]) self.mox.StubOutWithMock(api, 'storage_volume_get_all') api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool]) self.mox.StubOutWithMock(api, 'subnet_get_all') api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
def test_host_removed_event(self): self.__mock_service_get_all_by_topic() 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) 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) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_HOST_REMOVED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'VmHost') self.assertEquals(payload['entity_id'], deleted_host.id)
def test_host_removed_event(self): self.__mock_service_get_all_by_topic() 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) 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) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_HOST_REMOVED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'VmHost') self.assertEquals(payload['entity_id'], deleted_host.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 _initCache(self): # Read from DB all the vmHost objects and populate # the cache for each IP if cache is empty LOG.info(_('Entering into initCache')) computes = db.compute_node_get_all(get_admin_context()) for compute in computes: compute_id = str(compute['id']) service = compute['service'] self._add_compute_to_inventory(compute[ 'hypervisor_type'], compute_id, service['host']) vmhosts = api.vm_host_get_all(get_admin_context()) vms = api.vm_get_all(get_admin_context()) storageVolumes = api.storage_volume_get_all(get_admin_context()) subNets = api.subnet_get_all(get_admin_context()) self._updateInventory(vmhosts) self._updateInventory(vms) self._updateInventory(storageVolumes) self._updateInventory(subNets) LOG.info(_('Hosts obtained from db: %s') % str(len(vmhosts))) LOG.info(_('Vms obtained from db: %s') % str(len(vms))) LOG.info(_('Storage volumes obtained from db: %s') % str(len(storageVolumes))) LOG.info(_('Subnets obtained from db: %s') % str(len(subNets))) LOG.info(_('Completed the initCache method'))
def _createCache(self): self.mox.StubOutWithMock(api, 'vm_host_get_all') vmhost = VmHost() vmhost.set_id('vmhost1') vm = Vm() vm.set_id('vm1') stPool = StorageVolume() stPool.set_id('stpool1') subnet = Subnet() subnet.set_id('bridge0') api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost]) self.mox.StubOutWithMock(api, 'vm_get_all') api.vm_get_all(mox.IgnoreArg()).AndReturn([vm]) self.mox.StubOutWithMock(api, 'storage_volume_get_all') api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool]) self.mox.StubOutWithMock(api, 'subnet_get_all') api.subnet_get_all(mox.IgnoreArg()).AndReturn([subnet])
def test_load_compute_inventory(self): compute_service = dict(host='host2') compute = dict(id='compute2', hypervisor_type='fake', service=compute_service) self.mox.StubOutWithMock(nova_db, 'compute_node_get_all') nova_db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute]) self.mox.StubOutWithMock(api, 'vm_host_get_all') api.vm_host_get_all(mox.IgnoreArg()).AndReturn([]) 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.ReplayAll() InventoryManager() compute_key_lst = InventoryCacheManager.get_all_compute_inventory( ).keys() self.assertTrue(len(compute_key_lst), 2)
def test_storagevolume_get_all(self): storagevolume = StorageVolume() storagevolume.id = 'SV1' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolume = StorageVolume() storagevolume.id = 'SV2' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_all(self.admin_context) self.assertFalse(storagevolumes is None, 'storage volume all returned a none list') self.assertTrue(len(storagevolumes) == 2, 'storage volume all returned invalid number of list' ) self.assertTrue( storagevolumes[0].id == 'SV1', 'Storage volume id mismatch') self.assertTrue( storagevolumes[1].id == 'SV2', 'Storage volume id mismatch')
def test_storagevolume_get_all(self): storagevolume = StorageVolume() storagevolume.id = 'SV1' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolume = StorageVolume() storagevolume.id = 'SV2' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_all(self.admin_context) self.assertFalse(storagevolumes is None, 'storage volume all returned a none list') self.assertTrue( len(storagevolumes) == 2, 'storage volume all returned invalid number of list') self.assertTrue(storagevolumes[0].id == 'SV1', 'Storage volume id mismatch') self.assertTrue(storagevolumes[1].id == 'SV2', 'Storage volume id mismatch')
def _initCache(self): # Read from DB all the vmHost objects and populate # the cache for each IP if cache is empty LOG.info(_(" Entering into initCache")) vmhosts = api.vm_host_get_all(get_admin_context()) vms = api.vm_get_all(get_admin_context()) storageVolumes = api.storage_volume_get_all(get_admin_context()) subNets = api.subnet_get_all(get_admin_context()) self._updateInventory(vmhosts) self._updateInventory(vms) self._updateInventory(storageVolumes) self._updateInventory(subNets) LOG.info(_("Hosts obtained from db ") % vmhosts) LOG.info(_("Vms obtained from db ") % vms) LOG.info(_("Storage volumes obtained from db ") % storageVolumes) LOG.info(_("Completed the initCache method"))
def _initCache(self): # Read from DB all the vmHost objects and populate # the cache for each IP if cache is empty LOG.info(_(' Entering into initCache')) vmhosts = api.vm_host_get_all(get_admin_context()) vms = api.vm_get_all(get_admin_context()) storageVolumes = api.storage_volume_get_all(get_admin_context()) subNets = api.subnet_get_all(get_admin_context()) self._updateInventory(vmhosts) self._updateInventory(vms) self._updateInventory(storageVolumes) self._updateInventory(subNets) LOG.info(_('Hosts obtained from db ') % vmhosts) LOG.info(_('Vms obtained from db ') % vms) LOG.info(_('Storage volumes obtained from db ') % storageVolumes) LOG.info(_('Completed the initCache method'))