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])
예제 #2
0
 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])
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    def test_vm_delete_none(self):
        # Initially insert a vm into db and check the length
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)

        # Now delete the None from db
        healthnmon_db_api.vm_delete_by_ids(get_admin_context(), None)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
예제 #8
0
    def test_vm_save_none(self):
        # Initially insert a vm into db and check the length
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)

        # Now try to save the none and check the length is same as previous
        healthnmon_db_api.vm_save(get_admin_context(), None)
        vmsaved = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vmsaved is not None)
        self.assertTrue(len(vmsaved) == 1)
예제 #9
0
    def test_vm_delete_none(self):
        #Initially insert a vm into db and check the length
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)

        #Now delete the None from db
        healthnmon_db_api.vm_delete_by_ids(get_admin_context(), None)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
예제 #10
0
    def test_vm_save_none(self):
        #Initially insert a vm into db and check the length
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)

        #Now try to save the none and check the length is same as previous
        healthnmon_db_api.vm_save(get_admin_context(), None)
        vmsaved = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertTrue(vmsaved is not None)
        self.assertTrue(len(vmsaved) == 1)
예제 #11
0
    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'))
예제 #12
0
 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])
예제 #13
0
 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])
예제 #14
0
    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)
예제 #15
0
    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"))
예제 #16
0
    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'))
예제 #17
0
    def test_vm_get_all(self):
        '''
        Inserts more than one vm object and
        try to get them all and validates the values
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        vm.name = 'VM1-Name'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vm = Vm()
        vm.id = 'VM2-id'
        vm.name = 'VM2-Name'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertFalse(vms is None, 'vm_get_all returned None')
        self.assertTrue(len(vms) == 2,
                        'vm_get_all does not returned expected number of vms')
        self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vms[1].get_id(), 'VM2-id', "VM id is not same")
        self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM Name is not same")
        self.assertEqual(vms[1].get_name(), 'VM2-Name', "VM Name is not same")
예제 #18
0
    def test_vm_get_all(self):
        '''
        Inserts more than one vm object and
        try to get them all and validates the values
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        vm.name = 'VM1-Name'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vm = Vm()
        vm.id = 'VM2-id'
        vm.name = 'VM2-Name'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vms = healthnmon_db_api.vm_get_all(get_admin_context())
        self.assertFalse(vms is None, 'vm_get_all returned None')
        self.assertTrue(
            len(vms) == 2,
            'vm_get_all does not returned expected number of vms')
        self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vms[1].get_id(), 'VM2-id', "VM id is not same")
        self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM Name is not same")
        self.assertEqual(vms[1].get_name(), 'VM2-Name', "VM Name is not same")