示例#1
0
    def test_storage_added_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(), Constants.StorageVolume).AndReturn(None)

        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        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_STORAGE_ADDED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], storagePool.UUIDString())
示例#2
0
    def test_storage_deleted_event(self):
        self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')
        deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3'
        deleted_storage = StorageVolume()
        deleted_storage.id = deleted_storage_id

        InventoryCacheManager.get_object_from_cache(
            deleted_storage_id,
            Constants.StorageVolume).AndReturn(deleted_storage)
        self.mox.ReplayAll()
        cachedList = [
            deleted_storage_id, '3fbfbefb-17dd-07aa-2dac-13afbedf1234'
        ]
        updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        self.mox.ReplayAll()
        self.LibvirtStorageVolume.processStorageDeletes(
            cachedList, updatedList)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        eventMetaData = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DELETED)
        event_type = eventMetaData.get_event_fully_qal_name()
        self.assertEquals(msg['event_type'], event_type)
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], deleted_storage_id)
示例#3
0
    def test_storage_no_state_change(self):
        storagePool = libvirt.virStoragePool()
        self.mox.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_ACTIVE
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(cachedStorageVolume)
        #        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
        #
        #        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
        #                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        nova_db.service_get_all_by_topic(None, None)
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
示例#4
0
    def test_vm_reconfigured_event(self):
        mapped_tuple = self._mapLibvirtvmToVm()
        domainObj = mapped_tuple[0]
        cachedVm = mapped_tuple[1]
        cachedVm.name = 'OldName'
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(), Constants.Vm).AndReturn(cachedVm)
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        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_VM_RECONFIGURED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
示例#5
0
    def test_vm_deleted_event(self):
        self.mox.StubOutWithMock(api, 'vm_delete_by_ids')

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123'
        deleted_vm = Vm()
        deleted_vm.id = deleted_vm_id
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            deleted_vm_id,
            Constants.Vm).AndReturn(deleted_vm)
        self.mox.ReplayAll()
        cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262',
                      deleted_vm_id]
        updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262']
        self.libvirtVM.processVmDeletes(cachedList, updatedList)
        self.assertTrue(len(test_notifier.NOTIFICATIONS) == 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertTrue(msg is not None)
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], deleted_vm_id)
示例#6
0
    def test_storage_deleted_event(self):
        self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')
        deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3'
        deleted_storage = StorageVolume()
        deleted_storage.id = deleted_storage_id

        InventoryCacheManager.get_object_from_cache(
            deleted_storage_id,
            Constants.StorageVolume).AndReturn(deleted_storage)
        self.mox.ReplayAll()
        cachedList = [deleted_storage_id,
                      '3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        self.mox.ReplayAll()
        self.LibvirtStorageVolume.processStorageDeletes(cachedList,
                                                        updatedList)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        eventMetaData = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DELETED)
        event_type = eventMetaData.get_event_fully_qal_name()
        self.assertEquals(msg['event_type'], event_type)
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], deleted_storage_id)
示例#7
0
    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']
        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()
示例#8
0
    def test_storage_added_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(None)

        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        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_STORAGE_ADDED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'],
                          storagePool.UUIDString())
示例#9
0
    def test_vm_stopped_event(self):
        mapped_tuple = self._mapLibvirtvmToVm()
        domainObj = mapped_tuple[0]
        cachedVm = mapped_tuple[1]
        cachedVm.powerState = Constants.VM_POWER_STATE_ACTIVE
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(),
            Constants.Vm).AndReturn(cachedVm)
        self.mox.StubOutWithMock(domainObj, 'state')
        domainObj.state(0).AndReturn([5])
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        self.assertTrue(len(test_notifier.NOTIFICATIONS) > 0)
        msg = \
            self._getEventMsgForEventType(event_metadata.EVENT_TYPE_VM_STOPPED,
                                          test_notifier.NOTIFICATIONS)
        self.assertTrue(msg is not None)
        self.assertEquals(msg['priority'], notifier_api.WARN)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_STOPPED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
        self.assertEquals(payload['state'],
                          Constants.VM_POWER_STATE_STOPPED)
示例#10
0
    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']
        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()
示例#11
0
    def test_processVmDeletes(self):
        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_object_from_cache')
        deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123'
        deleted_vm = Vm()
        deleted_vm.id = deleted_vm_id

        InventoryCacheManager.get_object_from_cache(
            deleted_vm_id,
            Constants.Vm).AndReturn(deleted_vm)
        self.mock.ReplayAll()
        cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262',
                      deleted_vm_id]
        updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262']
        self.assertEquals(self.libvirtVM.processVmDeletes(cachedList,
                          updatedList), None)
        self.assertTrue(deleted_vm_id not in
                        InventoryCacheManager.get_inventory_cache().keys())
        self.mock.stubs.UnsetAll()
示例#12
0
    def test_vm_reconfigured_event(self):
        mapped_tuple = self._mapLibvirtvmToVm()
        domainObj = mapped_tuple[0]
        cachedVm = mapped_tuple[1]
        cachedVm.name = 'OldName'
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(),
            Constants.Vm).AndReturn(cachedVm)
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        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_VM_RECONFIGURED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
示例#13
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)
示例#14
0
    def test_vm_deleted_event(self):
        self.mox.StubOutWithMock(api, 'vm_delete_by_ids')

        api.vm_delete_by_ids(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123'
        deleted_vm = Vm()
        deleted_vm.id = deleted_vm_id
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            deleted_vm_id, Constants.Vm).AndReturn(deleted_vm)
        self.mox.ReplayAll()
        cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id]
        updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262']
        self.libvirtVM.processVmDeletes(cachedList, updatedList)
        self.assertTrue(len(test_notifier.NOTIFICATIONS) == 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertTrue(msg is not None)
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], deleted_vm_id)
示例#15
0
    def test_vm_suspended_event(self):
        mapped_tuple = self._mapLibvirtvmToVm()
        domainObj = mapped_tuple[0]
        cachedVm = mapped_tuple[1]
        cachedVm.powerState = Constants.VM_POWER_STATE_ACTIVE
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(), Constants.Vm).AndReturn(cachedVm)
        self.mox.StubOutWithMock(domainObj, 'state')
        domainObj.state(0).AndReturn([3])
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        self.assertTrue(len(test_notifier.NOTIFICATIONS) > 0)
        msg = \
            self._getEventMsgForEventType(
                event_metadata.EVENT_TYPE_VM_SUSPENDED,
                test_notifier.NOTIFICATIONS)
        self.assertTrue(msg is not None)
        self.assertEquals(msg['priority'], notifier_api.WARN)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_SUSPENDED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
        self.assertEquals(payload['state'], Constants.VM_POWER_STATE_PAUSED)
示例#16
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)
示例#17
0
    def test_processVmDeletes(self):
        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_object_from_cache'
                                  )
        deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123'
        deleted_vm = Vm()
        deleted_vm.id = deleted_vm_id

        InventoryCacheManager.get_object_from_cache(deleted_vm_id,
                                                    Constants.Vm).AndReturn(deleted_vm)
        self.mock.ReplayAll()
        cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262',
                      deleted_vm_id]
        updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262']
        self.assertEquals(self.libvirtVM.processVmDeletes(cachedList,
                          updatedList), None)
        self.assertTrue(deleted_vm_id not in InventoryCacheManager.get_inventory_cache().keys())
        self.mock.stubs.UnsetAll()
示例#18
0
    def test_storage_no_state_change(self):
        storagePool = libvirt.virStoragePool()
        self.mox.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_ACTIVE
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(storagePool.UUIDString(),
                                                    Constants.StorageVolume).AndReturn(cachedStorageVolume)
#        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
#
#        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
#                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        nova_db.service_get_all_by_topic(None, None)
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
示例#19
0
    def test_vm_created_event(self):
        domainObj = libvirt.virDomain()
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(),
            Constants.Vm).AndReturn(None)
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        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_VM_CREATED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
示例#20
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_delete_object_in_cache(self):
     self._createInvCache()
     vmhost = InventoryCacheManager.get_object_from_cache("vmhost1", Constants.VmHost)
     self.assertNotEquals(vmhost, None)
     InventoryCacheManager.delete_object_in_cache("vmhost1", Constants.VmHost)
     vmhost = InventoryCacheManager.get_object_from_cache("vmhost1", Constants.VmHost)
     self.assertEquals(vmhost, None)
     self.mox.UnsetStubs()
示例#22
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 test_updateInventory(self):
     self._createInvCache()
     im = self.inv_manager
     im._updateInventory(None)
     self.mox.ReplayAll()
     eventlet.sleep(2)
     self.mox.VerifyAll()
     host = InventoryCacheManager.get_object_from_cache("vmhost1", Constants.VmHost)
     self.assertTrue(InventoryCacheManager.get_object_from_cache("vmhost1", Constants.VmHost) is not None)
     self.assertEquals("vmhost1", host.get_id())
     self.mox.UnsetStubs()
示例#25
0
 def test_delete_object_in_cache(self):
     self._createInvCache()
     vmhost = InventoryCacheManager.get_object_from_cache('vmhost1',
                                                          Constants.VmHost)
     self.assertNotEquals(vmhost, None)
     InventoryCacheManager.delete_object_in_cache('vmhost1',
                                                  Constants.VmHost)
     vmhost = InventoryCacheManager.get_object_from_cache('vmhost1',
                                                          Constants.VmHost)
     self.assertEquals(vmhost, None)
     # self.assertEquals(len(self.inv_manager_cls._inventoryCache[Constants.VmHost]), 2)
     self.mox.UnsetStubs()
示例#26
0
 def test_delete_object_in_cache(self):
     self._createInvCache()
     vmhost = InventoryCacheManager.get_object_from_cache(
         'vmhost1', Constants.VmHost)
     self.assertNotEquals(vmhost, None)
     InventoryCacheManager.delete_object_in_cache('vmhost1',
                                                  Constants.VmHost)
     vmhost = InventoryCacheManager.get_object_from_cache(
         'vmhost1', Constants.VmHost)
     self.assertEquals(vmhost, None)
     # self.assertEquals(len(self.inv_manager_cls._inventoryCache[Constants.VmHost]), 2)
     self.mox.UnsetStubs()
示例#27
0
 def test_updateInventory(self):
     self._createInvCache()
     im = self.inv_manager
     im._updateInventory(None)
     self.mox.ReplayAll()
     eventlet.sleep(2)
     self.mox.VerifyAll()
     host = InventoryCacheManager.get_object_from_cache(
         'vmhost1', Constants.VmHost)
     self.assertTrue(
         InventoryCacheManager.get_object_from_cache(
             'vmhost1', Constants.VmHost) is not None)
     self.assertEquals('vmhost1', host.get_id())
     self.mox.UnsetStubs()
示例#28
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()
示例#29
0
    def test_ProcessUpdates_memory_exception(self):
        self.mock.StubOutWithMock(
            self.libvirtVmHost, '_get_compute_running_status')
        self.libvirtVmHost._get_compute_running_status().AndReturn(
            (True, 'host'))
        self.mock.StubOutWithMock(
            self.libvirtVmHost, '_get_network_running_status')
        self.libvirtVmHost._get_network_running_status(
            mox.IgnoreArg()).AndReturn(True)
        self.mock.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.StubOutWithMock(libvirt.virConnect,
                                  'getMemoryStats')
        self.connection._wrapped_conn.getMemoryStats(mox.IgnoreArg(),
                                                     mox.IgnoreArg()). \
            AndRaise(libvirt.libvirtError)

        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '34353438-3934-434e-3738-313630323543', host.get_uuid())
        self.assertEquals('1', host.get_id())
        self.assertEquals('ubuntu164.vmm.hp.com', host.get_name())
        self.mock.stubs.UnsetAll()
示例#30
0
    def test_processUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '52:54:00:34:14:AE', host.get_virtualSwitches()[0].get_id())
        self.assertEquals(
            'nat', host.get_virtualSwitches()[0].get_switchType())
        self.assertEquals('default', host.get_virtualSwitches()[0].get_name())

        self.mock.stubs.UnsetAll()
示例#31
0
    def poll_perfmon(self, context):
        """ Periodically polls to refresh the performance data
        of VmHost and Vm in inventory """
        LOG.info(
            _('Polling performance data periodically for Vmhosts and Vms'))

        def _worker(uuid, conn_driver, perfmon_type):
            conn_driver.update_perfdata(uuid, perfmon_type)

        for host_id in InventoryCacheManager.\
                get_inventory_cache()[Constants.VmHost].keys():
            conn_driver = InventoryCacheManager.get_compute_conn_driver(
                host_id,
                Constants.VmHost)
            if conn_driver is not None:
                self.perf_green_pool.spawn_n(_worker, host_id,
                                             conn_driver, Constants.VmHost)
            else:
                LOG.error(_('Error in monitoring performance data for Host %s '
                            ) % host_id)
            host_obj = InventoryCacheManager.get_inventory_cache(
            )[Constants.VmHost][host_id]
            for vm_id in host_obj.get_virtualMachineIds():
                vm_obj = InventoryCacheManager.get_object_from_cache(
                    vm_id, Constants.Vm)
                if vm_obj.get_powerState() \
                        == Constants.VM_POWER_STATES[1]:
                    conn_driver = InventoryCacheManager.\
                        get_compute_conn_driver(vm_id, Constants.Vm)
                    if conn_driver is not None:
                        self.perf_green_pool.spawn_n(_worker, vm_id,
                                                     conn_driver, Constants.Vm)
                    else:
                        LOG.error(_('Error in monitoring performance \
                        data for VM %s ') % vm_id)
示例#32
0
    def poll_perfmon(self, context):
        """ Periodically polls to refresh the performance data
        of VmHost and Vm in inventory """
        LOG.info(_("Polling performance data periodically for Vmhosts and Vms"))

        def _worker(uuid, conn_driver, perfmon_type):
            conn_driver.update_perfdata(uuid, perfmon_type)

        for host_id in InventoryCacheManager.get_inventory_cache()[Constants.VmHost].keys():
            conn_driver = InventoryCacheManager.get_compute_conn_driver(host_id, Constants.VmHost)
            if conn_driver is not None:
                self.perf_green_pool.spawn_n(_worker, host_id, conn_driver, Constants.VmHost)
            else:
                LOG.error(_("Error in monitoring performance data for Host %s ") % host_id)
            host_obj = InventoryCacheManager.get_inventory_cache()[Constants.VmHost][host_id]
            for vm_id in host_obj.get_virtualMachineIds():
                vm_obj = InventoryCacheManager.get_object_from_cache(vm_id, Constants.Vm)
                if vm_obj.get_powerState() == Constants.VM_POWER_STATES[1]:
                    conn_driver = InventoryCacheManager.get_compute_conn_driver(vm_id, Constants.Vm)
                    if conn_driver is not None:
                        self.perf_green_pool.spawn_n(_worker, vm_id, conn_driver, Constants.Vm)
                    else:
                        LOG.error(
                            _(
                                "Error in monitoring performance \
                        data for VM %s "
                            )
                            % vm_id
                        )
示例#33
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')
示例#34
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')
示例#35
0
    def test_processUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '52:54:00:34:14:AE', host.get_virtualSwitches()[0].get_id())
        self.assertEquals(
            'nat', host.get_virtualSwitches()[0].get_switchType())
        self.assertEquals('default', host.get_virtualSwitches()[0].get_name())

        self.mock.stubs.UnsetAll()
示例#36
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()
示例#37
0
    def test_processVm_disk_exception_next_retry(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(novadb, 'instance_get_by_uuid')
        novadb.instance_get_by_uuid(mox.IgnoreArg(),
                                    mox.IgnoreArg())\
            .AndReturn({'display_name': 'test_vm'})

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

        self.mock.ReplayAll()
        InventoryCacheManager.delete_object_in_cache(
            '25f04dd3-e924-02b2-9eac-876e3c943262', Constants.Vm)
        libvirt_inventorymonitor.incomplete_vms = {
            self.libvirtVM.compute_id: {}}
        self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()), None)
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        self.assertEqual(len(
            vm.get_vmDisks()), 0, "Instance disk should not exist when there \
            is an exception")
        self.mock.VerifyAll()
        self.mock.stubs.UnsetAll()
 def test_getObjectFromCache(self):
     self._createInvCache()
     vmhost = InventoryCacheManager.get_object_from_cache("vmhost1", Constants.VmHost)
     self.assertNotEquals(vmhost, None)
     self.assertEquals("vmhost1", vmhost.get_id())
     self.assertTrue("vm1" in vmhost.get_virtualMachineIds())
     self.mox.UnsetStubs()
示例#39
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()
示例#40
0
    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()
示例#41
0
 def test_getObjectFromCache(self):
     self._createInvCache()
     vmhost = InventoryCacheManager.get_object_from_cache(
         'vmhost1', Constants.VmHost)
     self.assertNotEquals(vmhost, None)
     self.assertEquals('vmhost1', vmhost.get_id())
     self.assertTrue('vm1' in vmhost.get_virtualMachineIds())
     self.mox.UnsetStubs()
示例#42
0
    def test_processStorageDeletes(self):
        self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        cachedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf3be3',
                      '3fbfbefb-17dd-07aa-2dac-13afbedf1234',
                      '3fbfbefb-17dd-07aa-2dac-13afbedf4321']
        updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        self.assertEquals(
            self.LibvirtStorageVolume.processStorageDeletes(cachedList,
                                                            updatedList), None)
        storage = InventoryCacheManager.get_object_from_cache(
            '3fbfbefb-17dd-07aa-2dac-13afbedf3be3', Constants.StorageVolume)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertTrue(storage is None)
        self.assertTrue('3fbfbefb-17dd-07aa-2dac-13afbedf1234' not in host.get_storageVolumeIds())
        self.mock.stubs.UnsetAll()
示例#43
0
    def test_processStorage(self):
        self.mock.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(
            self.LibvirtStorageVolume._processStorage(
                libvirt.virStoragePool()),
            None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        storage = InventoryCacheManager.get_object_from_cache(
            '95f7101b-892c-c388-867a-8340e5fea27a', Constants.StorageVolume)
        self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27a',
                        host.get_storageVolumeIds())
        self.assertTrue(storage is not None)
        self.assertEquals('default', storage.get_name())
        self.mock.stubs.UnsetAll()
示例#44
0
 def testVmHostPayload_with_storage_size(self):
     self.flags(instances_path="/var/lib/nova/instances")
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_HOST_ADDED)
     obj = VmHost()
     obj.name = 'TestVmHost'
     ipProfile = IpProfile()
     ipProfile.ipAddress = '10.10.10.1'
     obj.add_ipAddresses(ipProfile)
     storage_obj = StorageVolume()
     storage_obj.id = "storage_id"
     storage_obj.name = 'TestStorageVolume'
     storage_obj.connectionState = 'ACTIVE'
     storage_obj.size = 200
     storage_obj.free = 100
     storage_obj.volumeType = 'DIR'
     storage_obj.volumeId = 'TestVolumeId'
     storage_obj.createEpoch = long(time.time() * 1000)
     storage_obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/var/lib/nova/instances')
     mount_point.set_vmHostId('TestVmHost')
     storage_obj.add_mountPoints(mount_point)
     obj.add_storageVolumeIds("storage_id")
     self.mox.StubOutWithMock(
         InventoryCacheManager, 'get_object_from_cache')
     InventoryCacheManager.get_object_from_cache(
         storage_obj.id,
         Constants.StorageVolume).AndReturn(storage_obj)
     self.mox.ReplayAll()
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'],
                       obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['ipAddresses'],
                       ipProfile.ipAddress)
     self.assertEquals(payload['totalStorageSize'],
                       storage_obj.size)
     self.assertEquals(payload['storageUsed'],
                       storage_obj.free)
示例#45
0
    def test_processStorage(self):
        self.mock.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(mox.IgnoreArg(),
                                mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(
            self.LibvirtStorageVolume._processStorage(
                libvirt.virStoragePool()),
            None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        storage = InventoryCacheManager.get_object_from_cache(
            '95f7101b-892c-c388-867a-8340e5fea27a', Constants.StorageVolume)
        self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27a',
                        host.get_storageVolumeIds())
        self.assertTrue(storage is not None)
        self.assertEquals('default', storage.get_name())
        self.assertEquals('34353438-3934-434e-3738-313630323543',
                          storage.get_resourceManagerId())
        self.mock.stubs.UnsetAll()
示例#46
0
    def test_storage_disabled_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.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_ACTIVE
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(storagePool.UUIDString(),
                                                    Constants.StorageVolume).AndReturn(cachedStorageVolume)
        self.mox.StubOutWithMock(storagePool, 'isActive')
        storagePool.isActive().AndReturn(0)

#        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
#
#        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
#                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.WARN)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DISABLED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'],
                          storagePool.UUIDString())
        self.assertEquals(payload['state'],
                          Constants.STORAGE_STATE_INACTIVE)
示例#47
0
    def testProcessNetworkInterface(self):
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork._processNetworkInterface(
            libvirt.virLibvirtInterfaceEth0()),
            None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertTrue(host.get_ipAddresses is not None)
        self.mock.stubs.UnsetAll()
示例#48
0
    def test_storage_disabled_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.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_ACTIVE
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(cachedStorageVolume)
        self.mox.StubOutWithMock(storagePool, 'isActive')
        storagePool.isActive().AndReturn(0)

        #        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
        #
        #        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
        #                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.WARN)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DISABLED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], storagePool.UUIDString())
        self.assertEquals(payload['state'], Constants.STORAGE_STATE_INACTIVE)
示例#49
0
    def test_ProcessUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '34353438-3934-434e-3738-313630323543', host.get_uuid())
        self.assertEquals('1', host.get_id())
        self.assertEquals('ubuntu164.vmm.hp.com', host.get_name())
        self.mock.stubs.UnsetAll()
示例#50
0
    def test_processUpdates(self):
        self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        defaultInstancesPath = cfg.CONF.instances_path
        cfg.CONF.set_override('instances_path',
                              '/var/lib/nova/instances')
        self.assertEquals(self.LibvirtStorageVolume.processUpdates(),
                          None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(self.LibvirtStorageVolume._createNovaPool(),
                          None)
        storage = InventoryCacheManager.get_object_from_cache(
            '95f7101b-892c-c388-867a-8340e5fea27x', Constants.StorageVolume)
        self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27x',
                        host.get_storageVolumeIds())
        self.assertTrue(storage is not None)
        self.assertEquals('inactivePool', storage.get_name())
        cfg.CONF.set_override('instances_path', defaultInstancesPath)
        self.mock.stubs.UnsetAll()
示例#51
0
    def test_ProcessUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.libvirtVmHost.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '34353438-3934-434e-3738-313630323543', host.get_uuid())
        self.assertEquals('1', host.get_id())
        self.assertEquals('ubuntu164.vmm.hp.com', host.get_name())
        self.mock.stubs.UnsetAll()
示例#52
0
    def test_vm_created_event(self):
        domainObj = libvirt.virDomain()
        self.mox.StubOutWithMock(api, 'vm_save')

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            domainObj.UUIDString(), Constants.Vm).AndReturn(None)
        self.mox.ReplayAll()
        self.libvirtVM._processVm(domainObj)
        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_VM_CREATED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], domainObj.UUIDString())
示例#53
0
    def testProcessNetwork(self):
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork._processVirtualNetwork(
            libvirt.virLibvirtNetwork()),
            None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        self.assertFalse(subnet.get_isBootNetwork())
        self.assertEquals('default', subnet.get_name())
        self.mock.stubs.UnsetAll()
示例#54
0
 def testVmHostPayload_with_storage_size(self):
     self.flags(instances_path="/var/lib/nova/instances")
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_HOST_ADDED)
     obj = VmHost()
     obj.name = 'TestVmHost'
     ipProfile = IpProfile()
     ipProfile.ipAddress = '10.10.10.1'
     obj.add_ipAddresses(ipProfile)
     storage_obj = StorageVolume()
     storage_obj.id = "storage_id"
     storage_obj.name = 'TestStorageVolume'
     storage_obj.connectionState = 'ACTIVE'
     storage_obj.size = 200
     storage_obj.free = 100
     storage_obj.volumeType = 'DIR'
     storage_obj.volumeId = 'TestVolumeId'
     storage_obj.createEpoch = long(time.time() * 1000)
     storage_obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/var/lib/nova/instances')
     mount_point.set_vmHostId('TestVmHost')
     storage_obj.add_mountPoints(mount_point)
     obj.add_storageVolumeIds("storage_id")
     self.mox.StubOutWithMock(InventoryCacheManager,
                              'get_object_from_cache')
     InventoryCacheManager.get_object_from_cache(
         storage_obj.id, Constants.StorageVolume).AndReturn(storage_obj)
     self.mox.ReplayAll()
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'], obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['ipAddresses'], ipProfile.ipAddress)
     self.assertEquals(payload['totalStorageSize'], storage_obj.size)
     self.assertEquals(payload['storageUsed'], storage_obj.free)
示例#55
0
    def test_processVm(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.ReplayAll()
        self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()),
                          None)
        vm = InventoryCacheManager.get_object_from_cache(
            "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
        #self.assertEquals('Disconnected', vm.get_connectionState())
#        self.assertEquals('TestVirtMgrVM7', str(vm.get_name()))
        self.assertEquals("1048576", str(vm.get_memorySize()))
        #self.assertEquals("hd", str(vm.get_bootOrder()).strip())

        self.mock.stubs.UnsetAll()
示例#56
0
    def refresh_perfdata(
        self,
        conn,
        uuid,
        perfmon_type,
    ):
        '''Refreshes the performance data  '''

        LOG.info(_('Entering refresh_perfdata for uuid :' + uuid))
        if uuid not in LibvirtPerfMonitor.perfDataCache:
            LibvirtPerfMonitor.perfDataCache[uuid] = \
                {Constants.OLD_STATS: None, Constants.NEW_STATS: None}

        if perfmon_type == Constants.VmHost:
            LibvirtVmHostPerfData(conn, uuid).refresh_perfdata()
            host_obj = InventoryCacheManager.get_object_from_cache(
                uuid, Constants.VmHost)
            if host_obj is not None:
                event_api.notify_host_update(
                    event_metadata.EVENT_TYPE_HOST_UPDATED, host_obj)
        elif perfmon_type == Constants.Vm:
            LibvirtVmPerfData(conn, uuid).refresh_perfdata()
        LOG.info(_('Exiting refresh_perfdata for uuid :' + uuid))
示例#57
0
    def generate_payload(
        self,
        event_metadata,
        obj,
        **kwargs
    ):
        """Generate the vmhost specific payload

            Parameters:
                event_metadata - EventMetaData object for this event
                obj - VmHost object for which this event is to be generated
            Keyword arguments:
                additional_data - Any additional data that needs to be added for this event.
                                  This goes in the additional_data field of the message payload
                other key word arguments - This will have all the placeholder values that are to be substituted for event's long desc and short desc
            Returns:
                A dictionary having all the attributes of the payload
        """

        payload = super(VmHostPayloadGenerator,
                        self).generate_payload(event_metadata, obj,
                                               **kwargs)

        # Add ipAddresses

        ipAddresses = []
        vmHostIpProfiles = _getattr_no_none(obj, 'ipAddresses', [])
        for ipProfile in vmHostIpProfiles:
            ipAddresses.append(ipProfile.get_ipAddress())
        payload['ipAddresses'] = ','.join(ipAddresses)

        state = _getattr_no_none(obj, 'connectionState', '')
        state_desc = self._get_VmHost_state_desc(state)
        payload['connectionState'] = state
        payload['state_description'] = state_desc

        system_model = _getattr_no_none(obj, 'model', '')
        payload['systemModel'] = system_model
        vm_ids = _getattr_no_none(obj, 'virtualMachineIds', [])
        payload['vmCount'] = len(vm_ids)
        vmHostOsProfile = _getattr_no_none(obj, 'os', None)
        if vmHostOsProfile is not None:
            payload['osVersion'] = vmHostOsProfile.get_osVersion()

        #Utilization data
        utilization_sample = {}
        utilization_data = _getattr_no_none(obj, 'utilization', None)
        if utilization_data is not None:
            memoryConsumed = utilization_data.get_totalMemory(
            ) - utilization_data.get_freeMemory()
            utilization_sample = {'cpuUserLoad': utilization_data.get_cpuUserLoad(),
                                  'processorCoresCount': utilization_data.get_ncpus(),
                                  'totalMemory': utilization_data.get_totalMemory(),
                                  'memoryConsumed': memoryConsumed,
                                  }
            payload['utilizationSampleStatus'] = utilization_data.get_status()
            payload['utilizationSample'] = utilization_sample

        total_storage_size = 0
        storage_free = 0
        storageVolumeIds = _getattr_no_none(obj, 'storageVolumeIds', [])
        for storageVolumeId in storageVolumeIds:
            storageVolume = InventoryCacheManager.get_object_from_cache(
                storageVolumeId,
                Constants.StorageVolume)
            storage_pool_path = storageVolume.get_mountPoints()[0].get_path()
            if storage_pool_path == getFlagByKey('instances_path'):
                total_storage_size = long(storageVolume.get_size())
                storage_free = long(storageVolume.get_free())
                break
        payload['totalStorageSize'] = total_storage_size
        payload['storageUsed'] = total_storage_size - storage_free

        return payload