def _refresh_from_db(self, context):
        """Make our compute_node inventory map match the db."""

        # Add/update existing compute_nodes ...

        computes = db.compute_node_get_all(context)
        existing = InventoryCacheManager.get_all_compute_inventory().keys()
        db_keys = []
        for compute in computes:
            compute_id = str(compute['id'])
            service = compute['service']
            if service is not None:
                compute_alive = hnm_utils.is_service_alive(
                    service['updated_at'], service['created_at'])
                db_keys.append(compute_id)
                if not compute_alive:
                    LOG.warn(_('Service %s for host %s is not active') % (
                        service['binary'], service['host']))
#                    continue
                if compute_id not in existing:
                    self._add_compute_to_inventory(compute[
                                                   'hypervisor_type'],
                                                   compute_id, service['host'])
                    LOG.audit(_(
                        'New Host with compute_id  %s is \
                        obtained') % (compute_id))
                InventoryCacheManager.get_all_compute_inventory()[
                    compute_id].update_compute_Id(compute_id)
            else:
                LOG.warn(_(
                    ' No services entry found for compute id  \
                    %s') % compute_id)

        # Cleanup compute_nodes removed from db ...
        self._clean_deleted_computes(db_keys)
Exemple #2
0
    def test_poll_perfmon(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.poll_perfmon(None)
        self.assertTrue(im.perf_green_pool is not None)
        self.assertTrue(
            InventoryCacheManager.get_all_compute_inventory() is not None)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    def test_poll_perfmon(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'],
                                       rmIpAddress=service['host'],
                                       rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()[
            'vmhost1'].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.poll_perfmon(None)
        self.assertTrue(im.perf_green_pool is not None)
        self.assertTrue(
            InventoryCacheManager.get_all_compute_inventory() is not None)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    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)
Exemple #6
0
    def create_compute_inventory(self):
        compute_inventory = ComputeInventory(self.connection.compute_rmcontext)
        InventoryCacheManager.get_all_compute_inventory()[
            self.vmhost_id] = compute_inventory
        InventoryCacheManager.get_all_compute_inventory()[
            self.vm_id] = compute_inventory

        self.mox.StubOutWithMock(ComputeInventory, 'get_compute_conn_driver')
        compute_inventory.get_compute_conn_driver().AndReturn(self.connection)
        self.mox.ReplayAll()
    def create_compute_inventory(self):
        compute_inventory = ComputeInventory(self.connection.compute_rmcontext)
        InventoryCacheManager.get_all_compute_inventory(
        )[self.vmhost_id] = compute_inventory
        InventoryCacheManager.get_all_compute_inventory(
        )[self.vm_id] = compute_inventory

        self.mox.StubOutWithMock(ComputeInventory, 'get_compute_conn_driver')
        compute_inventory.get_compute_conn_driver().AndReturn(self.connection)
        self.mox.ReplayAll()
    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)
Exemple #10
0
    def test_update_inventory(self):
        self.mox.StubOutWithMock(libvirt, 'openReadOnly')
        libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
        self.mox.StubOutWithMock(api, 'vm_save')
        self.mox.StubOutWithMock(api, 'vm_host_save')
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.ReplayAll()
        conn = connection.get_connection(True)
        compute_rmcontext = ComputeRMContext(rmType='QEMU',
                                             rmIpAddress='10.10.155.165',
                                             rmUserName='******',
                                             rmPassword='******')

        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(compute_rmcontext)

        conn.init_rmcontext(compute_rmcontext)
        conn._wrapped_conn = self.fakeConn

        conn.update_inventory('1')
Exemple #11
0
    def setUp(self):
        self.mock = mox.Mox()
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_virtualMachineIds([])
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.connection._wrapped_conn = None
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(self.connection.compute_rmcontext)
        self.mock.StubOutWithMock(LibvirtConnection, '_connect')

        self.connection._connect(
            mox.IgnoreArg(),
            mox.IgnoreArg()).AndRaise(libvirt.libvirtError)
        self.mock.ReplayAll()
        self.inventoryMonitor = LibvirtInventoryMonitor()
        libvirtEvents = LibvirtEvents()
        self.libvirtVmHost = LibvirtVmHost(
            self.connection._wrapped_conn, '1', libvirtEvents)
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
    def test_update_inventory(self):
#        self.mox.StubOutWithMock(libvirt, 'openReadOnly')
#        libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
#        self.mox.StubOutWithMock(api, 'vm_save')
#        self.mox.StubOutWithMock(api, 'vm_host_save')
#        self.mox.StubOutWithMock(api, 'storage_volume_save')
#
#        api.storage_volume_save(
#            mox.IgnoreArg(),
#            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
#
#        api.vm_host_save(mox.IgnoreArg(),
#                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
#
#        api.vm_save(mox.IgnoreArg(),
#                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
#        self.mox.ReplayAll()
        conn = connection.get_connection(True)
        compute_rmcontext = ComputeRMContext(
            rmType='QEMU',
            rmIpAddress='10.10.155.165', rmUserName='******',
            rmPassword='******')

        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(compute_rmcontext)

        conn.init_rmcontext(compute_rmcontext)
        conn._wrapped_conn = self.fakeConn

        conn.update_inventory('1')
Exemple #13
0
    def test_get_compute_list(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='compute1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory().clear()
        InventoryCacheManager.get_all_compute_inventory()['compute1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['compute1'].update_compute_info(rm_context, compute)
        compute_info = self.inv_manager.get_compute_list()
        self.assertEquals(compute_info[0]['hypervisor_type'], 'fake')
        self.mox.UnsetStubs()
    def test_refresh_from_db_for_service_disabled_created(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute1 = _create_Compute(compute_id="vmhost1")
        compute1["service"]["created_at"] = timeutils.utcnow() - timedelta(1)
        compute1["service"]["updated_at"] = None
        self.mox.StubOutWithMock(db, "compute_node_get_all")
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute1])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()
        self.assertEquals(len(InventoryCacheManager.get_all_compute_inventory()), 1)
        self.assertNotIn("compute1", InventoryCacheManager.get_all_compute_inventory())
    def test_get_compute_list(self):
        self._createInvCache()
        compute = _create_Compute(compute_id="compute1")
        service = compute["service"]
        rm_context = rmcontext.ComputeRMContext(
            rmType=compute["hypervisor_type"],
            rmIpAddress=service["host"],
            rmUserName="******",
            rmPassword="******",
        )
        InventoryCacheManager.get_all_compute_inventory().clear()
        InventoryCacheManager.get_all_compute_inventory()["compute1"] = ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()["compute1"].update_compute_info(rm_context, compute)
        compute_info = self.inv_manager.get_compute_list()
        self.assertEquals(compute_info[0]["hypervisor_type"], "fake")
        self.mox.UnsetStubs()
    def test_get_compute_list(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='compute1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory().clear()
        InventoryCacheManager.get_all_compute_inventory()['compute1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()['compute1'
                                                          ].update_compute_info(rm_context, compute)
        compute_info = self.inv_manager.get_compute_list()
        self.assertEquals(compute_info[0]['hypervisor_type'], 'fake')
        self.mox.UnsetStubs()
 def _add_compute_to_inventory(self, hypervisor_type, compute_id, host):
     LOG.info(_("Adding compute to inventory with id : %s") % compute_id)
     rm_context = rmcontext.ComputeRMContext(
         rmType=hypervisor_type,
         rmIpAddress=host,
         rmUserName='******',
         rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()[
         compute_id] = ComputeInventory(rm_context)
    def _poll_computes(self):
        """Try to connect to each compute node and get update."""

        def _worker(compute_inventory):
            compute_inventory.poll()

        for compute in InventoryCacheManager.get_all_compute_inventory().values():
            self.green_pool.spawn_n(_worker, compute)
            LOG.debug(_("Free threads available in green pool %d ") % self.green_pool.free())
    def test_refresh_from_db_new(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute = _create_Compute(compute_id="compute1")
        self.mox.StubOutWithMock(db, "compute_node_get_all")
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()

        self.assertEquals(len(InventoryCacheManager.get_all_compute_inventory()), 2)
        self.assertIn("compute1", InventoryCacheManager.get_all_compute_inventory())

        self.mox.UnsetStubs()
Exemple #20
0
 def test__poll_compute_nodes(self):
     self.mox.StubOutWithMock(self.driver.inventory_manager, 'update')
     self.driver.inventory_manager.update(mox.IgnoreArg())
     self.mox.ReplayAll()
     self.driver.poll_compute_nodes(self.context)
     self.assertTrue(self.driver.inventory_manager is not None)
     self.assertTrue(
         InventoryCacheManager.get_all_compute_inventory() is not None)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
    def _clean_deleted_computes(self, db_keys):
        keys = InventoryCacheManager.get_all_compute_inventory(
        ).keys()  # since we're deleting
        deletion_list = []
        for compute_id in keys:
            if compute_id not in db_keys:
                vmHostObj = InventoryCacheManager.get_all_compute_inventory()[
                    compute_id].get_compute_info()
                if vmHostObj is not None:
                    deletion_list.append(vmHostObj.get_id())

        host_deleted_list = []
        if len(deletion_list) != 0:
            # Delete object from cache
            for _id in deletion_list:
                host_deleted = InventoryCacheManager.get_object_from_cache(
                    _id, Constants.VmHost)
                if host_deleted is not None:
                    host_deleted_list.append(
                        InventoryCacheManager.
                        get_object_from_cache(_id, Constants.VmHost))
                else:
                    LOG.warn(_(
                        "VmHost object for id %s not found in cache") % _id)

            # Delete the VmHost from DB
            api.vm_host_delete_by_ids(get_admin_context(), deletion_list)
            # Generate the VmHost Removed Event
            for host_deleted in host_deleted_list:
                LOG.debug(_('Generating Host Removed event for the \
                host id : %s') % str(
                    host_deleted.get_id()))
                event_api.notify_host_update(
                    event_metadata.EVENT_TYPE_HOST_REMOVED, host_deleted)
                # VmHost is deleted from compute inventory and inventory cache
                # after notifying the event
                del InventoryCacheManager.get_all_compute_inventory()[
                    host_deleted.get_id()]
                InventoryCacheManager.delete_object_in_cache(
                    host_deleted.get_id(), Constants.VmHost)
                LOG.audit(_('Host with (UUID, host name) - (%s, %s) \
                got removed') % (
                    host_deleted.get_id(), host_deleted.get_name()))
Exemple #22
0
    def test_refresh_from_db_new(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute = _create_Compute(compute_id='compute1')
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()

        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 1)
        self.assertIn('compute1',
                      InventoryCacheManager.get_all_compute_inventory())

        self.mox.UnsetStubs()
 def test__poll_compute_nodes(self):
     self.mox.StubOutWithMock(self.driver.inventory_manager, 'update'
                              )
     self.driver.inventory_manager.update(mox.IgnoreArg())
     self.mox.ReplayAll()
     self.driver.poll_compute_nodes(self.context)
     self.assertTrue(self.driver.inventory_manager is not None)
     self.assertTrue(
         InventoryCacheManager.get_all_compute_inventory() is not None)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
 def setUp(self):
     super(NetworkEventsTest, self).setUp()
     self.connection = LibvirtConnection(False)
     self.connection._wrapped_conn = libvirt.open("qemu:///system")
     rm_context = ComputeRMContext(
         rmType="QEMU", rmIpAddress="10.10.155.165", rmUserName="******", rmPassword="******"
     )
     InventoryCacheManager.get_all_compute_inventory()["1"] = ComputeInventory(rm_context)
     self.libvirtNetwork = LibvirtNetwork(self.connection._wrapped_conn, "1")
     self.flags(healthnmon_notification_drivers=["nova.notifier.test_notifier"])
     test_notifier.NOTIFICATIONS = []
Exemple #25
0
    def test_refresh_from_db_for_service_disabled_created(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute1 = _create_Compute(compute_id='vmhost1')
        compute1['service']['created_at'] = timeutils.utcnow() - timedelta(1)
        compute1['service']['updated_at'] = None
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute1])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()

        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertNotIn('compute1',
                         InventoryCacheManager.get_all_compute_inventory())
Exemple #26
0
    def test_poll_compute_perfmon(self):
        self.mox.StubOutWithMock(self.driver.inventory_manager, 'poll_perfmon')
        self.driver.inventory_manager.poll_perfmon(mox.IgnoreArg())

        self.mox.ReplayAll()
        self.driver.poll_compute_perfmon(self.context)
        self.assertTrue(
            self.driver.inventory_manager.perf_green_pool is not None)
        self.assertTrue(
            InventoryCacheManager.get_all_compute_inventory() is not None)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Exemple #27
0
    def test_get_resource_utilization(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.get_resource_utilization(None, 'vmhost1', Constants.VmHost, 5)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
Exemple #28
0
 def test_register_libvirt_events(self):
     libvirtEvents = libvirt_event_monitor.LibvirtEvents()
     libvirtEvents.compute_id = '1'
     connection = LibvirtConnection(False)
     connection.compute_rmcontext = \
         ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['1'] = \
         ComputeInventory(connection.compute_rmcontext)
     libvirtEvents.register_libvirt_events()
     self.mock.VerifyAll()
    def test_get_resource_utilization(self):
        self._createInvCache()
        compute = _create_Compute(compute_id="vmhost1")
        service = compute["service"]
        rm_context = rmcontext.ComputeRMContext(
            rmType=compute["hypervisor_type"],
            rmIpAddress=service["host"],
            rmUserName="******",
            rmPassword="******",
        )
        InventoryCacheManager.get_all_compute_inventory()["vmhost1"] = ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()["vmhost1"].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.get_resource_utilization(None, "vmhost1", Constants.VmHost, 5)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    def test_refresh_from_db_for_service_disabled_updated(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute1 = _create_Compute(compute_id='vmhost1')
        srvc = compute1['service']
        compute1['service']['binary'] = 'healthnmon'
        srvc['updated_at'] = timeutils.utcnow() - timedelta(1)
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn([compute1])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()

        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertNotIn(
            'compute1', InventoryCacheManager.get_all_compute_inventory())
    def test_poll_compute_perfmon(self):
        self.mox.StubOutWithMock(self.driver.inventory_manager,
                                 'poll_perfmon')
        self.driver.inventory_manager.poll_perfmon(mox.IgnoreArg())

        self.mox.ReplayAll()
        self.driver.poll_compute_perfmon(self.context)
        self.assertTrue(
            self.driver.inventory_manager.perf_green_pool is not None)
        self.assertTrue(
            InventoryCacheManager.get_all_compute_inventory() is not None)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
    def test_get_resource_utilization(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()['vmhost1'
                                                          ].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.get_resource_utilization(None, 'vmhost1', Constants.VmHost,
                                    5)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    def test_update_throwException(self):
        self._createInvCache()
        im = self.inv_manager
        self.mox.StubOutWithMock(im, "_refresh_from_db")

        # self.mox.StubOutWithMock(im, '_poll_computes')

        im._refresh_from_db(mox.IgnoreArg())

        # im._poll_computes()

        self.mox.StubOutWithMock(ComputeInventory, "update_inventory")

        InventoryCacheManager.get_all_compute_inventory()["compute1"].update_inventory().AndRaise(Exception)

        self.mox.ReplayAll()
        im.update(None)
        self.assertRaises(Exception, self.inv_manager_cls)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    def test_refresh_from_db_for_service_none(self):
        self._createInvCache()
        self.inv_manager_cls._compute_inventory = {}
        compute1 = _create_Compute(compute_id='compute1')
        compute2 = _create_Compute(compute_id='compute2')
        compute2['service'] = None
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(
            mox.IgnoreArg()).AndReturn([compute1, compute2])

        im = self.inv_manager
        self.assertEquals(len(im._compute_inventory), 0)

        self.mox.ReplayAll()
        im._refresh_from_db(None)
        self.mox.VerifyAll()

        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 1)
        self.assertIn(
            'compute1', InventoryCacheManager.get_all_compute_inventory())
        self.assertNotIn(
            'compute2', InventoryCacheManager.get_all_compute_inventory())
Exemple #35
0
    def test_update_throwException(self):
        self._createInvCache()
        im = self.inv_manager
        self.mox.StubOutWithMock(im, '_refresh_from_db')

        # self.mox.StubOutWithMock(im, '_poll_computes')

        im._refresh_from_db(mox.IgnoreArg())

        # im._poll_computes()

        self.mox.StubOutWithMock(ComputeInventory, 'update_inventory')

        InventoryCacheManager.get_all_compute_inventory(
        )['compute1'].update_inventory().AndRaise(Exception)

        self.mox.ReplayAll()
        im.update(None)
        self.assertRaises(Exception, self.inv_manager_cls)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
    def test_refresh_from_db_delete_host(self):
        self._createInvCache()
        InventoryCacheManager.get_all_compute_inventory().clear()
        compute = []
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn(compute)

        im = self.inv_manager
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)

        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'],
                                       rmIpAddress=service['host'],
                                       rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        vmhost = VmHost()
        vmhost.set_id('vmhost1')
        vmhost.set_name('vmhost1')
        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].update_compute_info(rm_context, vmhost)

        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(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.mox.ReplayAll()

        im._refresh_from_db(None)
        self.mox.VerifyAll()
        self.mox.stubs.UnsetAll()
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertTrue(InventoryCacheManager.get_all_compute_inventory(
        ).get('compute1') is None)

        self.mox.UnsetStubs()
    def test_poll_perfmon(self):
        self._createInvCache()
        compute = _create_Compute(compute_id="vmhost1")
        service = compute["service"]
        rm_context = rmcontext.ComputeRMContext(
            rmType=compute["hypervisor_type"],
            rmIpAddress=service["host"],
            rmUserName="******",
            rmPassword="******",
        )
        InventoryCacheManager.get_all_compute_inventory()["vmhost1"] = ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory()["vmhost1"].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.poll_perfmon(None)
        self.assertTrue(im.perf_green_pool is not None)
        self.assertTrue(InventoryCacheManager.get_all_compute_inventory() is not None)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
 def setUp(self):
     super(NetworkEventsTest, self).setUp()
     self.connection = LibvirtConnection(False)
     self.connection._wrapped_conn = libvirt.open("qemu:///system")
     rm_context = ComputeRMContext(
         rmType='QEMU', rmIpAddress='10.10.155.165',
         rmUserName='******',
         rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['1'] = \
         ComputeInventory(rm_context)
     self.libvirtNetwork = LibvirtNetwork(
         self.connection._wrapped_conn, '1')
     self.flags(
         healthnmon_notification_drivers=['nova.notifier.test_notifier'])
     test_notifier.NOTIFICATIONS = []
 def setUp(self):
     super(NetworkEventsTest, self).setUp()
     self.connection = LibvirtConnection(False)
     self.connection._wrapped_conn = libvirt.open("qemu:///system")
     rm_context = ComputeRMContext(rmType='QEMU',
                                   rmIpAddress='10.10.155.165',
                                   rmUserName='******',
                                   rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['1'] = \
         ComputeInventory(rm_context)
     self.libvirtNetwork = LibvirtNetwork(self.connection._wrapped_conn,
                                          '1')
     self.flags(
         healthnmon_notification_drivers=['nova.notifier.test_notifier'])
     test_notifier.NOTIFICATIONS = []
Exemple #40
0
    def test_refresh_from_db_delete_host(self):
        self._createInvCache()
        InventoryCacheManager.get_all_compute_inventory().clear()
        compute = []
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn(compute)

        im = self.inv_manager
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)

        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        vmhost = VmHost()
        vmhost.set_id('vmhost1')
        vmhost.set_name('vmhost1')
        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].update_compute_info(rm_context, vmhost)

        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(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.mox.ReplayAll()

        im._refresh_from_db(None)
        self.mox.VerifyAll()
        self.mox.stubs.UnsetAll()
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertTrue(InventoryCacheManager.get_all_compute_inventory().get(
            'compute1') is None)

        self.mox.UnsetStubs()
Exemple #41
0
 def test_register_libvirt_events_conn_none(self):
     libvirtEvents = libvirt_event_monitor.LibvirtEvents()
     libvirtEvents.compute_id = '1'
     connection = LibvirtConnection(False)
     connection.compute_rmcontext = \
         ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['2'] = \
         ComputeInventory(connection.compute_rmcontext)
     from healthnmon.virt.fake import FakeConnection
     self.mock.StubOutWithMock(FakeConnection, 'get_new_connection')
     fc = FakeConnection()
     fc.get_new_connection(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None)
     self.mock.ReplayAll()
     libvirtEvents.register_libvirt_events()
     self.mock.VerifyAll()
    def test_refresh_from_db_delete_host(self):
        self._createInvCache()
        InventoryCacheManager.get_all_compute_inventory().clear()
        compute = []
        self.mox.StubOutWithMock(db, "compute_node_get_all")
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn(compute)

        im = self.inv_manager
        self.assertEquals(len(InventoryCacheManager.get_all_compute_inventory()), 0)

        compute = _create_Compute(compute_id="vmhost1")
        service = compute["service"]
        rm_context = rmcontext.ComputeRMContext(
            rmType=compute["hypervisor_type"],
            rmIpAddress=service["host"],
            rmUserName="******",
            rmPassword="******",
        )
        InventoryCacheManager.get_all_compute_inventory()["vmhost1"] = ComputeInventory(rm_context)

        vmhost = VmHost()
        vmhost.set_id("vmhost1")
        vmhost.set_name("vmhost1")
        InventoryCacheManager.get_all_compute_inventory()["vmhost1"].update_compute_info(rm_context, vmhost)

        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(event_api, "notify_host_update")
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.mox.ReplayAll()

        im._refresh_from_db(None)
        self.mox.VerifyAll()
        self.mox.stubs.UnsetAll()
        self.assertEquals(len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertTrue(InventoryCacheManager.get_all_compute_inventory().get("compute1") is None)

        self.mox.UnsetStubs()
    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)
Exemple #44
0
    def setUp(self):
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_virtualMachineIds([])

        rm_context = ComputeRMContext(
            rmType='QEMU', rmIpAddress='10.10.155.165',
            rmUserName='******',
            rmPassword='******')

        InventoryCacheManager.update_object_in_cache('1', vmHost)
        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(rm_context)

        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        libvirtEvents = LibvirtEvents()
        self.libvirtVmHost = LibvirtVmHost(
            self.connection._wrapped_conn, '1', libvirtEvents)
        self.connection.compute_rmcontext = rm_context
        self.mock = mox.Mox()
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
Exemple #45
0
    def setUp(self):
        self.mock = mox.Mox()
        self.connection = LibvirtConnection(False)
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        vmHost = VmHost()
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(self.connection.compute_rmcontext)
        self.mock.StubOutWithMock(LibvirtConnection, '_connect')

        self.connection._connect(mox.IgnoreArg(),
                                 mox.IgnoreArg()).AndRaise(libvirt.libvirtError)
        self.mock.ReplayAll()
        self.inventoryMonitor = LibvirtInventoryMonitor()
#        self.libvirtVmHost = LibvirtVmHost(self.connection, '1')
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
        self.libvirtInventoryMonitor = LibvirtInventoryMonitor()
Exemple #46
0
    def setUp(self):
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_virtualMachineIds([])

        rm_context = ComputeRMContext(
            rmType='QEMU', rmIpAddress='10.10.155.165',
            rmUserName='******',
            rmPassword='******')

        InventoryCacheManager.update_object_in_cache('1', vmHost)
        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(rm_context)

        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        libvirtEvents = LibvirtEvents()
        self.libvirtVmHost = LibvirtVmHost(
            self.connection._wrapped_conn, '1', libvirtEvents)
        self.connection.compute_rmcontext = rm_context
        self.mock = mox.Mox()
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
Exemple #47
0
    def setUp(self):
        super(VmHostEventsTest, self).setUp()
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_virtualMachineIds([])
        InventoryCacheManager.update_object_in_cache('1', vmHost)

        rm_context = ComputeRMContext(rmType='QEMU',
                                      rmIpAddress='10.10.155.165',
                                      rmUserName='******',
                                      rmPassword='******')

        InventoryCacheManager.update_object_in_cache('1', vmHost)
        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(rm_context)

        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        libvirtEvents = LibvirtEvents()
        self.libvirtVmHost = LibvirtVmHost(self.connection._wrapped_conn, '1',
                                           libvirtEvents)
        self.connection.compute_rmcontext = rm_context
        self.flags(
            healthnmon_notification_drivers=['nova.notifier.test_notifier'])
        test_notifier.NOTIFICATIONS = []
    def _refresh_from_db(self, context):
        """Make our compute_node inventory map match the db."""

        # Add/update existing compute_nodes ...

        computes = db.compute_node_get_all(context)
        existing = InventoryCacheManager.get_all_compute_inventory().keys()
        db_keys = []
        for compute in computes:
            compute_id = str(compute['id'])
            service = compute['service']
            compute_hypervisor_type = compute['hypervisor_type']
            LOG.debug(_(' Compute-id -> %s: Hypervisor Type -> %s') %
                      (compute_id, compute_hypervisor_type))

            if service is not None and compute_hypervisor_type == 'QEMU':
                compute_alive = hnm_utils.is_service_alive(
                    service['updated_at'], service['created_at'])
                db_keys.append(compute_id)
                if not compute_alive:
                    LOG.warn(_('Service %s for host %s is not active')
                             % (service['binary'], service['host']))
                    continue
                if compute_id not in existing:
                    rm_context = \
                        rmcontext.ComputeRMContext(
                            rmType=compute['hypervisor_type'],
                            rmIpAddress=service['host'],
                            rmUserName='******', rmPassword='******')
                    InventoryCacheManager.\
                        get_all_compute_inventory()[compute_id] =\
                        ComputeInventory(rm_context)
                    LOG.audit(_('New Host with compute_id  %s is obtained')
                              % (compute_id))
                InventoryCacheManager.get_all_compute_inventory(
                )[compute_id].update_compute_Id(compute_id)
            else:
                LOG.warn(_(' No services entry found for compute id  %s')
                         % compute_id)

        # Cleanup compute_nodes removed from db ...

        keys = InventoryCacheManager.get_all_compute_inventory(
        ).keys()  # since we're deleting
        deletion_list = []
        for compute_id in keys:
            if compute_id not in db_keys:
                vmHostObj = InventoryCacheManager.get_all_compute_inventory(
                )[compute_id].get_compute_info()
                if vmHostObj is not None:
                    deletion_list.append(vmHostObj.get_id())

        host_deleted_list = []
        if len(deletion_list) != 0:
            # Delete object from cache
            for _id in deletion_list:
                host_deleted = InventoryCacheManager.get_object_from_cache(
                    _id, Constants.VmHost)
                if host_deleted is not None:
                    host_deleted_list.append(
                        InventoryCacheManager.get_object_from_cache(
                            _id, Constants.VmHost))
                else:
                    LOG.warn(
                        _("VmHost object for id %s not found in cache") % _id)

            # Delete the VmHost from DB
            api.vm_host_delete_by_ids(get_admin_context(), deletion_list)
            # Generate the VmHost Removed Event
            for host_deleted in host_deleted_list:
                LOG.debug(_('Generating Host Removed event \
                for the host id : %s') % str(host_deleted.get_id()))
                event_api.notify_host_update(
                    event_metadata.EVENT_TYPE_HOST_REMOVED, host_deleted)
                # VmHost is deleted from compute inventory and inventory
                # cache after notifying the event
                del InventoryCacheManager.get_all_compute_inventory(
                )[host_deleted.get_id()]
                InventoryCacheManager.delete_object_in_cache(
                    host_deleted.get_id(), Constants.VmHost)
                LOG.audit(_('Host with (UUID, host name) \
                - (%s, %s) got removed') % (host_deleted.get_id(),
                                            host_deleted.get_name()))
    def get_compute_list(self):
        """Return the list of nova-compute_nodes we know about."""

        return [compute.get_compute_info() for compute in
                InventoryCacheManager.get_all_compute_inventory().values()]