示例#1
0
    def test_ProcessUpdatesException(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        mock_libvirtVm = LibvirtVM(self.connection, '1')
        self.mock.StubOutWithMock(mock_libvirtVm, 'processVmDeletes')
        mock_libvirtVm.processVmDeletes([], []).AndRaise(Exception)
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVM.processUpdates(), None)
        self.assertRaises(Exception, LibvirtVM)
        self.mock.stubs.UnsetAll()
示例#2
0
    def test_processVmForIPAddress(self):
        self.mock.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()),
                          None)
        self.libvirtVM.processUpdates()
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        ipProfileList = vm.get_ipAddresses()
        self.assertTrue(ipProfileList is not None)
        self.assertTrue(ipProfileList[0].get_ipAddress() == '10.1.1.19')
        self.assertTrue(ipProfileList[1].get_ipAddress() == '10.2.1.20')
示例#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()
    def test_process_incomplete_vms(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mock.ReplayAll()
        libvirt_inventorymonitor.incomplete_vms = \
            {self.libvirtVM.compute_id:
            {'25f04dd3-e924-02b2-9eac-876e3c943262': 1}}
        self.libvirtVM.process_incomplete_vms()
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        self.assert_(vm.get_vmDisks(), "VM disks inventory not collected")
        self.assert_(
            '25f04dd3-e924-02b2-9eac-876e3c943262' not in
            libvirt_inventorymonitor.incomplete_vms[
                self.libvirtVM.compute_id],
            "VM id not removed from incomplete list")
        self.mock.stubs.UnsetAll()
示例#5
0
    def test_process_updates_for_updated_VM(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mock.ReplayAll()
        domainObj = libvirt.virDomain()
        self.assertEquals(
            self.libvirtVM.process_updates_for_updated_VM(domainObj), None)
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
#        self.assertEquals("TestVirtMgrVM7", vm.get_name())
        self.assertEquals("1048576", str(vm.get_memorySize()))
        self.assertEquals("hd", str(vm.get_bootOrder()).strip())
        self.mock.stubs.UnsetAll()
示例#6
0
    def test_process_updates_for_updated_VM(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mock.ReplayAll()
        domainObj = libvirt.virDomain()
        self.assertEquals(
            self.libvirtVM.process_updates_for_updated_VM(domainObj), None)
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
#        self.assertEquals("TestVirtMgrVM7", vm.get_name())
        self.assertEquals("1048576", str(vm.get_memorySize()))
        self.assertEquals("hd", str(vm.get_bootOrder()).strip())
        self.mock.stubs.UnsetAll()
示例#7
0
    def test_host_added_event(self):
        self.__mock_service_get_all_by_topic()
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(None)

        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

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

        self.mox.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.ReplayAll()
        self.libvirtVmHost.processUpdates()
        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_ADDED)
        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'],
                          self.libvirtVmHost.compute_id)
示例#8
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()
示例#9
0
    def test_processVmForIPAddress(self):
        self.mock.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()),
                          None)
        self.libvirtVM.processUpdates()
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        ipProfileList = vm.get_ipAddresses()
        self.assertTrue(ipProfileList is not None)
        self.assertTrue(ipProfileList[0].get_ipAddress() == '10.1.1.19')
        self.assertTrue(ipProfileList[1].get_ipAddress() == '10.2.1.20')
示例#10
0
    def test_ProcessUpdatesException(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        mock_libvirtVm = LibvirtVM(self.connection, '1')
        self.mock.StubOutWithMock(mock_libvirtVm, 'processVmDeletes')
        mock_libvirtVm.processVmDeletes([], []).AndRaise(Exception)
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVM.processUpdates(), None)
        self.assertRaises(Exception, LibvirtVM)
        self.mock.stubs.UnsetAll()
示例#11
0
    def test_host_disconnected_event(self):
        self.__mock_service_get_all_by_topic()
        backedUp_libvirt = connection.libvirt
        connection.libvirt = libvirt
        try:
            compute_id = '1'
            virtConnection = LibvirtConnection(False)
            vmHost = VmHost()
            vmHost.id = compute_id
            vmHost.set_virtualMachineIds([])
            InventoryCacheManager.update_object_in_cache(compute_id, vmHost)
#            virtConnection.setUuid('34353438-3934-434e-3738-313630323543'
#                                   )
            virtConnection._wrapped_conn = None
            virtConnection.compute_rmcontext = \
                ComputeRMContext(rmType='KVM',
                                 rmIpAddress='10.10.155.165',
                                 rmUserName='******',
                                 rmPassword='******')
            cachedHost = VmHost()
            cachedHost.id = compute_id
            cachedHost.connectionState = Constants.VMHOST_CONNECTED
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_object_from_cache')
            self.mox.StubOutWithMock(
                InventoryCacheManager, 'get_compute_conn_driver')

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

            InventoryCacheManager.get_object_from_cache(
                compute_id,
                Constants.VmHost).AndReturn(cachedHost)
            self.mox.StubOutWithMock(api, 'vm_host_save')

            api.vm_host_save(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
            self.mox.ReplayAll()
            libvirtEvents = LibvirtEvents()
            libvirtVmHost = LibvirtVmHost(
                virtConnection._wrapped_conn, compute_id, libvirtEvents)
            libvirtVmHost.processUpdates()
            self.assertEquals(libvirtVmHost.vmHost.get_connectionState(),
                              Constants.VMHOST_DISCONNECTED)
            self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
            msg = test_notifier.NOTIFICATIONS[0]
            self.assertEquals(msg['priority'], notifier_api.CRITICAL)
            event_type = \
                event_metadata.get_EventMetaData(
                    event_metadata.EVENT_TYPE_HOST_DISCONNECTED)
            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'],
                              libvirtVmHost.compute_id)
        finally:
            connection.libvirt = backedUp_libvirt
示例#12
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)
示例#13
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)
示例#14
0
    def test_host_disconnected_event(self):
        self.__mock_service_get_all_by_topic()
        backedUp_libvirt = connection.libvirt
        connection.libvirt = libvirt
        try:
            compute_id = '1'
            virtConnection = LibvirtConnection(False)
            vmHost = VmHost()
            vmHost.id = compute_id
            vmHost.set_virtualMachineIds([])
            InventoryCacheManager.update_object_in_cache(compute_id, vmHost)
            #            virtConnection.setUuid('34353438-3934-434e-3738-313630323543'
            #                                   )
            virtConnection._wrapped_conn = None
            virtConnection.compute_rmcontext = \
                ComputeRMContext(rmType='KVM',
                                 rmIpAddress='10.10.155.165',
                                 rmUserName='******',
                                 rmPassword='******')
            cachedHost = VmHost()
            cachedHost.id = compute_id
            cachedHost.connectionState = Constants.VMHOST_CONNECTED
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_object_from_cache')
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_compute_conn_driver')

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

            InventoryCacheManager.get_object_from_cache(
                compute_id, Constants.VmHost).AndReturn(cachedHost)
            self.mox.StubOutWithMock(api, 'vm_host_save')

            api.vm_host_save(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
            self.mox.ReplayAll()
            libvirtEvents = LibvirtEvents()
            libvirtVmHost = LibvirtVmHost(virtConnection._wrapped_conn,
                                          compute_id, libvirtEvents)
            libvirtVmHost.processUpdates()
            self.assertEquals(libvirtVmHost.vmHost.get_connectionState(),
                              Constants.VMHOST_DISCONNECTED)
            self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
            msg = test_notifier.NOTIFICATIONS[0]
            self.assertEquals(msg['priority'], notifier_api.CRITICAL)
            event_type = \
                event_metadata.get_EventMetaData(
                    event_metadata.EVENT_TYPE_HOST_DISCONNECTED)
            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'], libvirtVmHost.compute_id)
        finally:
            connection.libvirt = backedUp_libvirt
示例#15
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)
示例#16
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)
示例#17
0
    def testProcessUpdates(self):
        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())
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(),
                          'Disconnected')
        self.mock.stubs.UnsetAll()
示例#18
0
    def testProcessUpdates(self):
        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())
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(),
                          'Disconnected')
        self.mock.stubs.UnsetAll()
示例#19
0
    def test_process_incomplete_vms_with_retry(self):
        self.mock.StubOutWithMock(api, 'vm_save')

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

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).\
            MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVM.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())

        self.mock.StubOutWithMock(
            self.libvirtVM.libvirtconn, 'storageVolLookupByPath')
        self.libvirtVM.libvirtconn.storageVolLookupByPath(
            mox.IgnoreArg()).AndRaise(Exception)
        self.mock.ReplayAll()

        libvirt_inventorymonitor.incomplete_vms = \
            {self.libvirtVM.compute_id: {
             '25f04dd3-e924-02b2-9eac-876e3c943262': 1}}
        self.libvirtVM.process_incomplete_vms()
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        self.assert_(not(vm.get_vmDisks()), "VM disks should not be collected")
        self.assert_(
            libvirt_inventorymonitor.incomplete_vms[self.libvirtVM.compute_id][
                '25f04dd3-e924-02b2-9eac-876e3c943262'] == 2,
            "incomplete_vms retry count not incremented")
        self.mock.stubs.UnsetAll()
示例#20
0
    def test_process_incomplete_vms_deletedvm(self):
        self.mock.StubOutWithMock(api, 'vm_save')
        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)

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

        self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg())\
            .MultipleTimes().AndReturn(None)

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

        self.mock.StubOutWithMock(
            self.libvirtVM.libvirtconn, 'listDefinedDomains')
        self.libvirtVM.libvirtconn.listDefinedDomains().AndReturn([])

        self.mock.StubOutWithMock(self.libvirtVM.libvirtconn, 'listDomainsID')
        self.libvirtVM.libvirtconn.listDomainsID().AndReturn([])
        self.mock.ReplayAll()

        libvirt_inventorymonitor.incomplete_vms = \
            {self.libvirtVM.compute_id: {
             '25f04dd3-e924-02b2-9eac-876e3c943262': 1}}
        self.libvirtVM.process_incomplete_vms()

        self.assert_(
            '25f04dd3-e924-02b2-9eac-876e3c943262' not in
            libvirt_inventorymonitor.incomplete_vms[
                self.libvirtVM.compute_id],
            "Deleted VM id not removed from incomplete list")
        self.mock.stubs.UnsetAll()
示例#21
0
def get_connection(hypervisor_type, read_only=False):
    """
    Returns an object representing the connection to a virtualization
    platform.

    This could be :mod:`nova.virt.fake.FakeConnection` in test mode,
    a connection to KVM, QEMU, or UML via :mod:`libvirt_conn`, or a connection
    to XenServer or Xen Cloud Platform via :mod:`xenapi`.

    Any object returned here must conform to the interface documented by
    :mod:`FakeConnection`.

    **Related flags**

    :connection_type:  A string literal that falls through a if/elif structure
                       to determine what virtualization mechanism to use.
                       Values may be

                            * fake
                            * libvirt
    """

    # TODO(termie): maybe lazy load after initial check for permissions
    # TODO(termie): check whether we can be disconnected

    if hypervisor_type == 'fake':
        conn = fake.get_connection(read_only)
    elif hypervisor_type == 'QEMU':
        conn = libvirt_conn.get_connection(read_only)
    else:
        raise Exception('Unknown connection type "%s"'
                        % hypervisor_type)

    if conn is None:
        LOG.error(_('Failed to open connection to the hypervisor'))
        sys.exit(1)
    return utils.check_isinstance(conn, driver.ComputeInventoryDriver)
示例#22
0
    def test_host_connected_event(self):
        self.__mock_service_get_all_by_topic()
        cachedHost = VmHost()
        cachedHost.id = self.libvirtVmHost.compute_id
        cachedHost.connectionState = 'Disconnected'
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(cachedHost)

        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_compute_conn_driver')

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

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.ReplayAll()
        self.libvirtVmHost.processUpdates()
        self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(),
                          Constants.VMHOST_CONNECTED)
        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_CONNECTED)
        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'], self.libvirtVmHost.compute_id)
示例#23
0
def get_connection(hypervisor_type, read_only=False):
    """
    Returns an object representing the connection to a virtualization
    platform.

    This could be :mod:`nova.virt.fake.FakeConnection` in test mode,
    a connection to KVM, QEMU, or UML via :mod:`libvirt_conn`, or a connection
    to XenServer or Xen Cloud Platform via :mod:`xenapi`.

    Any object returned here must conform to the interface documented by
    :mod:`FakeConnection`.

    **Related flags**

    :connection_type:  A string literal that falls through a if/elif structure
                       to determine what virtualization mechanism to use.
                       Values may be

                            * fake
                            * libvirt
    """

    # TODO(termie): maybe lazy load after initial check for permissions
    # TODO(termie): check whether we can be disconnected

    if hypervisor_type == 'fake':
        conn = fake.get_connection(read_only)
    elif hypervisor_type == 'QEMU':
        conn = libvirt_conn.get_connection(read_only)
    else:
        raise Exception('Unknown connection type "%s"' % hypervisor_type)

    if conn is None:
        LOG.error(_('Failed to open connection to the hypervisor'))
        sys.exit(1)
    return utils.check_isinstance(conn, driver.ComputeInventoryDriver)