Exemplo n.º 1
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
Exemplo n.º 2
0
    def test_ProcessUpdatesException(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        libvirtEvents = LibvirtEvents()
        mock_libvirtVmHost = LibvirtVmHost(self.connection, '1', libvirtEvents)
        self.mock.StubOutWithMock(mock_libvirtVmHost, '_mapHostProperties')
        mock_libvirtVmHost._mapHostProperties().AndRaise(Exception)
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        self.assertRaises(Exception, LibvirtVmHost)
        self.mock.stubs.UnsetAll()
Exemplo n.º 3
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'])
Exemplo n.º 4
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 = []
Exemplo n.º 5
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'])