Пример #1
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()
Пример #2
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)
Пример #3
0
 def test_init_rmcontext(self):
     compute_rmcontext = rmcontext.ComputeRMContext(
         rmType='QEMU',
         rmIpAddress='10.10.155.165',
         rmUserName='******',
         rmPassword='******')
     conn = connection.get_connection(True)
     conn.init_rmcontext(compute_rmcontext)
     self.assertTrue(conn.compute_rmcontext is not None)
     self.assertEquals(conn.compute_rmcontext.rmIpAddress, "10.10.155.165")
     self.assertEquals(conn.compute_rmcontext.rmUserName, "openstack")
     self.assertEquals(conn.compute_rmcontext.rmPassword, "password")
Пример #4
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)
Пример #5
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()
Пример #6
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()
Пример #7
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()
Пример #8
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()))