Пример #1
0
    def create_compute_inventory(self):
        compute_inventory = ComputeInventory(self.connection.compute_rmcontext)
        InventoryCacheManager.get_all_compute_inventory()[
            self.vmhost_id] = compute_inventory
        InventoryCacheManager.get_all_compute_inventory()[
            self.vm_id] = compute_inventory

        self.mox.StubOutWithMock(ComputeInventory, 'get_compute_conn_driver')
        compute_inventory.get_compute_conn_driver().AndReturn(self.connection)
        self.mox.ReplayAll()
Пример #2
0
    def create_compute_inventory(self):
        compute_inventory = ComputeInventory(self.connection.compute_rmcontext)
        InventoryCacheManager.get_all_compute_inventory(
        )[self.vmhost_id] = compute_inventory
        InventoryCacheManager.get_all_compute_inventory(
        )[self.vm_id] = compute_inventory

        self.mox.StubOutWithMock(ComputeInventory, 'get_compute_conn_driver')
        compute_inventory.get_compute_conn_driver().AndReturn(self.connection)
        self.mox.ReplayAll()
Пример #3
0
    def test_poll_perfmon(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.poll_perfmon(None)
        self.assertTrue(im.perf_green_pool is not None)
        self.assertTrue(
            InventoryCacheManager.get_all_compute_inventory() is not None)
        eventlet.sleep(2)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
Пример #4
0
    def test_update_inventory(self):
        self.mox.StubOutWithMock(libvirt, 'openReadOnly')
        libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
        self.mox.StubOutWithMock(api, 'vm_save')
        self.mox.StubOutWithMock(api, 'vm_host_save')
        self.mox.StubOutWithMock(api, 'storage_volume_save')

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

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

        api.vm_save(mox.IgnoreArg(),
                    mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.ReplayAll()
        conn = connection.get_connection(True)
        compute_rmcontext = ComputeRMContext(rmType='QEMU',
                                             rmIpAddress='10.10.155.165',
                                             rmUserName='******',
                                             rmPassword='******')

        InventoryCacheManager.get_all_compute_inventory()['1'] = \
            ComputeInventory(compute_rmcontext)

        conn.init_rmcontext(compute_rmcontext)
        conn._wrapped_conn = self.fakeConn

        conn.update_inventory('1')
Пример #5
0
    def test_host_removed_event(self):
        self.__mock_service_get_all_by_topic()
        deleted_host = VmHost()
        deleted_host.set_id('compute1')
        deleted_host.set_name('compute1')
        self.mox.StubOutWithMock(api, 'vm_host_get_all')
        api.vm_host_get_all(mox.IgnoreArg()).AndReturn([deleted_host])
        self.mox.StubOutWithMock(api, 'vm_get_all')
        api.vm_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'storage_volume_get_all')
        api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'subnet_get_all')
        api.subnet_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(nova_db, 'compute_node_get_all')
        nova_db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'vm_host_delete_by_ids')

        api.vm_host_delete_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(
            'compute1', Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        compute_service = dict(host='host1')
        compute = dict(id='compute1',
                       hypervisor_type='fake',
                       service=compute_service)
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=compute_service['host'],
                                       rmUserName='******', rmPassword='******')

        InventoryCacheManager.get_all_compute_inventory().clear()

        InventoryCacheManager.get_all_compute_inventory(
        )['compute1'] = ComputeInventory(rm_context)
        InventoryCacheManager.get_compute_inventory(
            'compute1').update_compute_info(rm_context, deleted_host)
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 1)
        inv_manager = InventoryManager()
        inv_manager._refresh_from_db(None)
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_HOST_REMOVED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'VmHost')
        self.assertEquals(payload['entity_id'], deleted_host.id)
Пример #6
0
 def test_register_libvirt_events(self):
     libvirtEvents = libvirt_event_monitor.LibvirtEvents()
     libvirtEvents.compute_id = '1'
     connection = LibvirtConnection(False)
     connection.compute_rmcontext = \
         ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['1'] = \
         ComputeInventory(connection.compute_rmcontext)
     libvirtEvents.register_libvirt_events()
     self.mock.VerifyAll()
Пример #7
0
    def test_host_removed_event_none_host(self):
        deleted_host = VmHost()
        deleted_host.set_id('compute1')
        deleted_host.set_name('compute1')
        self.mox.StubOutWithMock(api, 'vm_host_get_all')
        api.vm_host_get_all(mox.IgnoreArg()).AndReturn([deleted_host])
        self.mox.StubOutWithMock(api, 'vm_get_all')
        api.vm_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'storage_volume_get_all')
        api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'subnet_get_all')
        api.subnet_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(nova_db, 'compute_node_get_all')
        nova_db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
        self.mox.StubOutWithMock(api, 'vm_host_delete_by_ids')

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

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

        InventoryCacheManager.get_compute_conn_driver(
            'compute1', Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()

        compute_service = dict(host='host1')
        compute = dict(id='compute1',
                       hypervisor_type='fake',
                       service=compute_service)
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=compute_service['host'],
                                       rmUserName='******', rmPassword='******')

        InventoryCacheManager.get_all_compute_inventory().clear()

        InventoryCacheManager.get_all_compute_inventory(
        )['compute1'] = ComputeInventory(rm_context)
        InventoryCacheManager.get_compute_inventory(
            'compute1').update_compute_info(rm_context, deleted_host)
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 1)
        InventoryCacheManager.get_inventory_cache()[Constants.VmHost][
            deleted_host.get_id()] = None

        inv_manager = InventoryManager()
        inv_manager._refresh_from_db(None)
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
Пример #8
0
 def setUp(self):
     super(NetworkEventsTest, self).setUp()
     self.connection = LibvirtConnection(False)
     self.connection._wrapped_conn = libvirt.open("qemu:///system")
     rm_context = ComputeRMContext(rmType='QEMU',
                                   rmIpAddress='10.10.155.165',
                                   rmUserName='******',
                                   rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['1'] = \
         ComputeInventory(rm_context)
     self.libvirtNetwork = LibvirtNetwork(self.connection._wrapped_conn,
                                          '1')
     self.flags(
         healthnmon_notification_drivers=['nova.notifier.test_notifier'])
     test_notifier.NOTIFICATIONS = []
Пример #9
0
    def test_get_compute_list(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='compute1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory().clear()
        InventoryCacheManager.get_all_compute_inventory()['compute1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['compute1'].update_compute_info(rm_context, compute)
        compute_info = self.inv_manager.get_compute_list()
        self.assertEquals(compute_info[0]['hypervisor_type'], 'fake')
        self.mox.UnsetStubs()
Пример #10
0
 def test_register_libvirt_events_conn_none(self):
     libvirtEvents = libvirt_event_monitor.LibvirtEvents()
     libvirtEvents.compute_id = '1'
     connection = LibvirtConnection(False)
     connection.compute_rmcontext = \
         ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
                          rmUserName='******',
                          rmPassword='******')
     InventoryCacheManager.get_all_compute_inventory()['2'] = \
         ComputeInventory(connection.compute_rmcontext)
     from healthnmon.virt.fake import FakeConnection
     self.mock.StubOutWithMock(FakeConnection, 'get_new_connection')
     fc = FakeConnection()
     fc.get_new_connection(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None)
     self.mock.ReplayAll()
     libvirtEvents.register_libvirt_events()
     self.mock.VerifyAll()
Пример #11
0
    def test_refresh_from_db_delete_host(self):
        self._createInvCache()
        InventoryCacheManager.get_all_compute_inventory().clear()
        compute = []
        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        db.compute_node_get_all(mox.IgnoreArg()).AndReturn(compute)

        im = self.inv_manager
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)

        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        vmhost = VmHost()
        vmhost.set_id('vmhost1')
        vmhost.set_name('vmhost1')
        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].update_compute_info(rm_context, vmhost)

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

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

        self.mox.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.mox.ReplayAll()

        im._refresh_from_db(None)
        self.mox.VerifyAll()
        self.mox.stubs.UnsetAll()
        self.assertEquals(
            len(InventoryCacheManager.get_all_compute_inventory()), 0)
        self.assertTrue(InventoryCacheManager.get_all_compute_inventory().get(
            'compute1') is None)

        self.mox.UnsetStubs()
Пример #12
0
    def test_get_resource_utilization(self):
        self._createInvCache()
        compute = _create_Compute(compute_id='vmhost1')
        service = compute['service']
        rm_context = \
            rmcontext.ComputeRMContext(rmType=compute['hypervisor_type'
                                                      ], rmIpAddress=service['host'], rmUserName='******',
                                       rmPassword='******')
        InventoryCacheManager.get_all_compute_inventory()['vmhost1'] = \
            ComputeInventory(rm_context)

        InventoryCacheManager.get_all_compute_inventory(
        )['vmhost1'].get_compute_conn_driver()

        im = self.inv_manager

        self.mox.ReplayAll()
        im.get_resource_utilization(None, 'vmhost1', Constants.VmHost, 5)
        self.mox.VerifyAll()

        self.mox.UnsetStubs()
Пример #13
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()
Пример #14
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'])
Пример #15
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 = []