Пример #1
0
    def testProcessUpdates_compute_stopped_exception(self):
        vmHost = VmHost()
        vmHost.set_id('1')
        vmHost.set_connectionState(Constants.VMHOST_CONNECTED)
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.mock.StubOutWithMock(api, 'vm_host_save')
        api.vm_host_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')
        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())

        fake_computes = [{'id': '1', 'service': {'created_at':
                                                 'created',
                                                 'updated_at':'updated'}}]
        self.mock.StubOutWithMock(novadb, 'compute_node_get_all')
        novadb.compute_node_get_all(mox.IgnoreArg()).AndReturn(fake_computes)

        self.mock.StubOutWithMock(hnm_utils, 'is_service_alive')
        hnm_utils.is_service_alive(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)

        self.mock.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(
            mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception())
        self.mock.ReplayAll()

        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.mock.stubs.UnsetAll()
Пример #2
0
    def skiptestProcessUpdates_network_stopped(self):
        vmHost = VmHost()
        vmHost.set_id('1')
        vmHost.set_connectionState(Constants.VMHOST_CONNECTED)
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.mock.StubOutWithMock(
            self.libvirtVmHost, '_get_compute_running_status')
        self.libvirtVmHost._get_compute_running_status().AndReturn(
            (True, 'host'))

        self.mock.StubOutWithMock(api, 'vm_host_save')
        api.vm_host_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        fake_networks = {
            'id': '1', 'created_at': 'created', 'updated_at': 'updated'}
        self.mock.StubOutWithMock(novadb, 'service_get_by_host_and_topic')
        novadb.service_get_by_host_and_topic(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(fake_networks)

        self.mock.StubOutWithMock(hnm_utils, 'is_service_alive')
        hnm_utils.is_service_alive(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)

        self.mock.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None)
        self.mock.ReplayAll()

        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.assertEquals(
            self.libvirtVmHost.cachedvmHost.get_connectionState(),
            'Disconnected')
        self.mock.stubs.UnsetAll()
Пример #3
0
    def testProcessUpdates_compute_stopped_exception(self):
        vmHost = VmHost()
        vmHost.set_id('1')
        vmHost.set_connectionState(Constants.VMHOST_CONNECTED)
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.mock.StubOutWithMock(api, 'vm_host_save')
        api.vm_host_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')
        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())

        fake_computes = [{'id': '1', 'service': {'created_at':
                                                 'created', 'updated_at':'updated'}}]
        self.mock.StubOutWithMock(novadb, 'compute_node_get_all')
        novadb.compute_node_get_all(mox.IgnoreArg()).AndReturn(fake_computes)

        self.mock.StubOutWithMock(hnm_utils, 'is_service_alive')
        hnm_utils.is_service_alive(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)

        self.mock.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(
            mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception())
        self.mock.ReplayAll()

        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.mock.stubs.UnsetAll()
Пример #4
0
    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)
Пример #5
0
    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())
                )
Пример #6
0
    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()))