Beispiel #1
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'])
    def setUp(self):
        super(StorageVolumeEventsTest, self).setUp()
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_storageVolumeIds([])
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        self.LibvirtStorageVolume = \
            LibvirtStorageVolume(self.connection._wrapped_conn, '1')
        self.LibvirtStorageVolume.vmHost = vmHost
        self.LibvirtStorageVolume.cur_total_storage_size = 0
        self.LibvirtStorageVolume.curr_storage_free = 0
        self.LibvirtStorageVolume.old_total_storage_size = 0
        self.LibvirtStorageVolume.old_storage_free = 0
        self.LibvirtStorageVolume.vmHost.set_id('1')
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        self.flags(healthnmon_notification_drivers=[
            'nova.notifier.test_notifier'])
        test_notifier.NOTIFICATIONS = []
        self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
Beispiel #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()
Beispiel #4
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 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()
Beispiel #6
0
    def setUp(self):
        super(StorageVolumeEventsTest, self).setUp()
        self.connection = LibvirtConnection(False)
        vmHost = VmHost()
        vmHost.set_storageVolumeIds([])
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        self.LibvirtStorageVolume = \
            LibvirtStorageVolume(self.connection._wrapped_conn, '1')
        self.LibvirtStorageVolume.vmHost = vmHost
        self.LibvirtStorageVolume.cur_total_storage_size = 0
        self.LibvirtStorageVolume.curr_storage_free = 0
        self.LibvirtStorageVolume.old_total_storage_size = 0
        self.LibvirtStorageVolume.old_storage_free = 0
        self.LibvirtStorageVolume.vmHost.set_id('1')
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        self.flags(
            healthnmon_notification_drivers=['nova.notifier.test_notifier'])
        test_notifier.NOTIFICATIONS = []
        self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
Beispiel #7
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
Beispiel #8
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
 def test_update_object_in_cache(self):
     ipAddress = IpAddress()
     newHost = VmHost()
     InventoryCacheManager.update_object_in_cache("uuid", ipAddress)
     InventoryCacheManager.update_object_in_cache("uuid1", newHost)
     self.mox.ReplayAll()
     eventlet.sleep(2)
     self.mox.VerifyAll()
     self.assertTrue(InventoryCacheManager.get_object_from_cache("uuid", Constants.VmHost) is None)
     self.assertTrue(InventoryCacheManager.get_object_from_cache("uuid1", Constants.VmHost) is not None)
     self.mox.UnsetStubs()
 def setUp(self):
     self.fakeConn = libvirt.open('qemu:///system')
     self.libvirt_connection_cls = connection.LibvirtConnection
     super(Test_virt_connection, self).setUp()
     self.flags(
         healthnmon_notification_drivers=[
             'healthnmon.notifier.log_notifier']
     )
     vmHost = VmHost()
     vmHost.id = '1'
     vmHost.uuid = '1'
     InventoryCacheManager.update_object_in_cache('1', vmHost)
Beispiel #11
0
 def setUp(self):
     self.connection = LibvirtConnection(False)
     vmHost = VmHost()
     vmHost.set_storageVolumeIds([])
     InventoryCacheManager.update_object_in_cache('1', vmHost)
     self.connection._wrapped_conn = libvirt.open('qemu:///system')
     self.LibvirtStorageVolume = \
         LibvirtStorageVolume(self.connection._wrapped_conn, '1')
     self.connection.compute_rmcontext = \
         ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     self.mock = mox.Mox()
Beispiel #12
0
 def setUp(self):
     self.connection = LibvirtConnection(False)
     vmHost = VmHost()
     vmHost.set_storageVolumeIds([])
     InventoryCacheManager.update_object_in_cache('1', vmHost)
     self.connection._wrapped_conn = libvirt.open('qemu:///system')
     self.LibvirtStorageVolume = \
         LibvirtStorageVolume(self.connection._wrapped_conn, '1')
     self.connection.compute_rmcontext = \
         ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     self.mock = mox.Mox()
Beispiel #13
0
 def test_update_object_in_cache(self):
     ipAddress = IpAddress()
     newHost = VmHost()
     InventoryCacheManager.update_object_in_cache('uuid', ipAddress)
     InventoryCacheManager.update_object_in_cache('uuid1', newHost)
     self.mox.ReplayAll()
     eventlet.sleep(2)
     self.mox.VerifyAll()
     self.assertTrue(
         InventoryCacheManager.get_object_from_cache(
             'uuid', Constants.VmHost) is None)
     self.assertTrue(
         InventoryCacheManager.get_object_from_cache(
             'uuid1', Constants.VmHost) is not None)
     self.mox.UnsetStubs()
 def setUp(self):
     super(test_LibvirtStorage, self).setUp()
     self.connection = LibvirtConnection(False)
     vmHost = VmHost()
     vmHost.set_storageVolumeIds([])
     InventoryCacheManager.update_object_in_cache('1', vmHost)
     self.connection._wrapped_conn = libvirt.open('qemu:///system')
     self.LibvirtStorageVolume = \
         LibvirtStorageVolume(self.connection._wrapped_conn, '1')
     self.connection.compute_rmcontext = \
         ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     cfg.CONF.set_override('healthnmon_notification_drivers',
                           ['healthnmon.notifier.log_notifier'])
     self.mock = mox.Mox()
Beispiel #15
0
    def setUp(self):
        self.connection = LibvirtConnection(False)
        self.vmHost = VmHost()
        self.vmHost.set_virtualMachineIds([])
        InventoryCacheManager.update_object_in_cache('1', self.vmHost)

        #self.connection.setUuid('34353438-3934-434e-3738-313630323543')
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        self.libvirtVM = LibvirtVM(self.connection._wrapped_conn,
                                   '1')
        self.libvirtVM.vmHost.set_id('1')
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        self.mock = mox.Mox()
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
Beispiel #16
0
    def setUp(self):
        self.connection = LibvirtConnection(False)
        self.vmHost = VmHost()
        self.vmHost.set_virtualMachineIds([])
        InventoryCacheManager.update_object_in_cache('1', self.vmHost)

        #self.connection.setUuid('34353438-3934-434e-3738-313630323543')
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        self.libvirtVM = LibvirtVM(self.connection._wrapped_conn,
                                   '1')
        self.libvirtVM.vmHost.set_id('1')
        self.connection.compute_rmcontext = \
            ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165',
                             rmUserName='******',
                             rmPassword='******')
        self.mock = mox.Mox()
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
Beispiel #17
0
 def createInvCache(self, vmrunning, hostconnection='Connected'):
     vmhost = VmHost()
     vmhost.set_id(self.vmhost_id)
     vmhost.set_connectionState(hostconnection)
     vm = Vm()
     vm.set_id(self.vm_id)
     if vmrunning:
         vm.set_powerState(Constants.VM_POWER_STATES[1])
     else:
         vm.set_powerState(Constants.VM_POWER_STATES[0])
     vm.set_vmHostId(self.vmhost_id)
     vmhost.set_virtualMachineIds([self.vm_id])
     vmhost.set_processorSpeedMhz(2100)
     vmhost.set_processorCoresCount(4)
     vmhost.set_processorCount('2')
     vmhost.set_memorySize(2097152)
     vmhost.set_memoryConsumed(2097152)
     InventoryCacheManager.update_object_in_cache(self.vmhost_id, vmhost)
     InventoryCacheManager.update_object_in_cache(self.vm_id, vm)
Beispiel #18
0
 def setUp(self):
     self.connection = LibvirtConnection(False)
     vmHost = VmHost()
     vSwitch = VirtualSwitch()
     vSwitch.set_id('52:54:00:34:14:AE')
     vSwitch.set_name('default')
     vSwitch.set_switchType('nat')
     vmHost.set_virtualSwitches([vSwitch])
     InventoryCacheManager.update_object_in_cache('1', vmHost)
     #self.connection.setUuid('34353438-3934-434e-3738-313630323543')
     self.connection._wrapped_conn = libvirt.open('qemu:///system')
     self.connection.compute_rmcontext = \
         ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     self.LibvirtNetwork = LibvirtNetwork(self.connection, '1')
     self.mock = mox.Mox()
     cfg.CONF.set_override('healthnmon_notification_drivers',
                           ['healthnmon.notifier.log_notifier'])
Beispiel #19
0
 def setUp(self):
     self.connection = LibvirtConnection(False)
     vmHost = VmHost()
     vSwitch = VirtualSwitch()
     vSwitch.set_id('52:54:00:34:14:AE')
     vSwitch.set_name('default')
     vSwitch.set_switchType('nat')
     vmHost.set_virtualSwitches([vSwitch])
     InventoryCacheManager.update_object_in_cache('1', vmHost)
     #self.connection.setUuid('34353438-3934-434e-3738-313630323543')
     self.connection._wrapped_conn = libvirt.open('qemu:///system')
     self.connection.compute_rmcontext = \
         ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     self.LibvirtNetwork = LibvirtNetwork(self.connection, '1')
     self.mock = mox.Mox()
     cfg.CONF.set_override('healthnmon_notification_drivers',
                           ['healthnmon.notifier.log_notifier'])
    def testProcessnetworkDeletes(self):
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')

        api.subnet_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
#        cachedSwitchList = ['52:54:00:34:14:AC',
#                            '52:54:00:34:14:AB',
#                            '52:54:00:34:14:AE']
#        updatedSwitchList = ['52:54:00:34:14:AE']
        cachedSubnetList = \
            ['Subnet_52:54:00:34:14:AF',
             'Subnet_52:54:00:34:14:AG',
             'Subnet_52:54:00:34:14:AE']
        updatedSubnetList = \
            ['Subnet_52:54:00:34:14:AE']
        InventoryCacheManager.update_object_in_cache(
            'Subnet_52:54:00:34:14:AF', Subnet())
        InventoryCacheManager.update_object_in_cache(
            'Subnet_52:54:00:34:14:AG', Subnet())
        InventoryCacheManager.update_object_in_cache(
            'Subnet_52:54:00:34:14:AE', Subnet())
        self.assertEquals(self.LibvirtNetwork._processNetworkDeletes(
                          cachedSubnetList,
                          updatedSubnetList), None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AG', Constants.Network)
        self.assertTrue(subnet is None)
        self.mock.stubs.UnsetAll()
Beispiel #21
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'])
    def test_processUpdates_hostupdate_event(self):
        defaultInstancesPath = cfg.CONF.instances_path
        cfg.CONF.set_override('instances_path', '/var/lib/libvirt/images')
        storagePool = libvirt.virStoragePool()
        self.mock.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(mox.IgnoreArg(),
                                mox.IgnoreArg()).MultipleTimes().\
            AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_INACTIVE
        InventoryCacheManager.update_object_in_cache(
            '95f7101b-892c-c388-867a-8340e5fea27x', cachedStorageVolume)

        self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().\
            AndReturn(None)

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

        InventoryCacheManager.get_compute_conn_driver(None,
                                                      Constants.VmHost).\
            AndReturn(fake.
                      get_connection())

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtStorageVolume.processUpdates(),
                          None)
        self.assertEquals(self.LibvirtStorageVolume._createNovaPool(),
                          None)
        cfg.CONF.set_override('instances_path', defaultInstancesPath)
        self.mock.stubs.UnsetAll()
Beispiel #23
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'])
Beispiel #24
0
    def setUp(self):
        self.mock = mox.Mox()
        self.connection = LibvirtConnection(False)
        self.connection._wrapped_conn = libvirt.open('qemu:///system')
        vmHost = VmHost()
        InventoryCacheManager.update_object_in_cache('1', vmHost)
        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()
#        self.libvirtVmHost = LibvirtVmHost(self.connection, '1')
        cfg.CONF.set_override('healthnmon_notification_drivers',
                              ['healthnmon.notifier.log_notifier'])
        self.libvirtInventoryMonitor = LibvirtInventoryMonitor()
 def createInvCache(self, vmrunning, hostconnection='Connected'):
     vmhost = VmHost()
     vmhost.set_id(self.vmhost_id)
     vmhost.set_connectionState(hostconnection)
     vm = Vm()
     vm.set_id(self.vm_id)
     if vmrunning:
         vm.set_powerState(Constants.VM_POWER_STATES[1])
     else:
         vm.set_powerState(Constants.VM_POWER_STATES[0])
     vm.set_vmHostId(self.vmhost_id)
     vmhost.set_virtualMachineIds([self.vm_id
                                   ])
     vmhost.set_processorSpeedMhz(2100)
     vmhost.set_processorCoresCount(4)
     vmhost.set_processorCount('2')
     vmhost.set_memorySize(2097152)
     vmhost.set_memoryConsumed(2097152)
     InventoryCacheManager.update_object_in_cache(self.vmhost_id, vmhost)
     InventoryCacheManager.update_object_in_cache(
         self.vm_id,
         vm)
Beispiel #26
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 = []
Beispiel #27
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 = []
Beispiel #28
0
 def _updateInventory(self, objlist):
     if objlist is not None:
         for obj in objlist:
             InventoryCacheManager.update_object_in_cache(obj.id, obj)
Beispiel #29
0
 def _updateInventory(self, objlist):
     if objlist is not None:
         for obj in objlist:
             InventoryCacheManager.update_object_in_cache(obj.id, obj)