Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
0
 def get_single_host(self):
     host_list = []
     host = VmHost()
     host.set_id('host-01')
     host.set_name('host-01')
     host.add_virtualMachineIds('vm-01')
     host.add_virtualMachineIds('vm-02')
     host.add_storageVolumeIds('storage-01')
     host.add_storageVolumeIds('storage-02')
     host_list.append(host)
     return host_list
Esempio n. 4
0
 def get_single_host(self):
     host_list = []
     host = VmHost()
     host.set_id('host-01')
     host.set_name('host-01')
     host.add_virtualMachineIds('vm-01')
     host.add_virtualMachineIds('vm-02')
     host.add_storageVolumeIds('storage-01')
     host.add_storageVolumeIds('storage-02')
     host_list.append(host)
     return host_list
Esempio n. 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)
Esempio n. 6
0
 def get_limited_list(self, num):
     host_list = []
     for i in range(1, num + 1):
         host = VmHost()
         host.set_id('host-' + str(i))
         host.set_name('host-' + str(i))
         host.add_virtualMachineIds('vm-' + str(i))
         host.add_virtualMachineIds('vm-' + str(i))
         host.add_storageVolumeIds('storage-' + str(i))
         host.add_storageVolumeIds('storage-' + str(i))
         host_list.append(host)
     return host_list
Esempio n. 7
0
 def get_limited_list(self, num):
     host_list = []
     for i in range(1, num + 1):
         host = VmHost()
         host.set_id('host-' + str(i))
         host.set_name('host-' + str(i))
         host.add_virtualMachineIds('vm-' + str(i))
         host.add_virtualMachineIds('vm-' + str(i))
         host.add_storageVolumeIds('storage-' + str(i))
         host.add_storageVolumeIds('storage-' + str(i))
         host_list.append(host)
     return host_list
Esempio n. 8
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)
    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()
Esempio n. 10
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()
    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()