Example #1
0
    def test_refresh_perfdata_NoCache(self):
        self.libvirtPerf_monitor.delete_perfdata_fromCache(self.vm_id)
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn, self.vm_id, Constants.VmHost)
Example #2
0
class TestLibvirtVmHostPerfData(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.connection = LibvirtConnection(False)
        cls.mox = mox.Mox()
        cls.connection._wrapped_conn = libvirt.open('qemu:///system')
        rm_context = ComputeRMContext(rmType='fake',
                                      rmIpAddress='host',
                                      rmUserName='******',
                                      rmPassword='******')
        cls.connection.init_rmcontext(rm_context)
        cls.connection.libvirt = libvirt
        cls.vm_id = '25f04dd3-e924-02b2-9eac-876e3c943262'
        cls.vmhost_id = '1'

    def setUp(self):
        self.libvirtPerf_monitor = LibvirtPerfMonitor()
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self._createPerfCache()

    def _createPerfCache(self):

        self.libvirtPerf_monitor.perfDataCache[self.vmhost_id] = {
            Constants.OLD_STATS: None,
            Constants.NEW_STATS: None
        }

    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()

    def test_refresh_perfdata(self):
        for _ in xrange(2):
            self._create_compute_inventory()
            self.libvirtVmHost.refresh_perfdata()
            self.mox.UnsetStubs()

        self.assertNotEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                self.vmhost_id, Constants.NEW_STATS), None)
        self.assertNotEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                self.vmhost_id, Constants.OLD_STATS), None)

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}
        self.mox.UnsetStubs()
class TestLibvirtVmHostPerfData(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.connection = LibvirtConnection(False)
        cls.mox = mox.Mox()
        cls.connection._wrapped_conn = libvirt.open('qemu:///system')
        rm_context = ComputeRMContext(
            rmType='fake', rmIpAddress='host', rmUserName='******',
            rmPassword='******')
        cls.connection.init_rmcontext(rm_context)
        cls.connection.libvirt = libvirt
        cls.vm_id = '25f04dd3-e924-02b2-9eac-876e3c943262'
        cls.vmhost_id = '1'

    def setUp(self):
        self.libvirtPerf_monitor = LibvirtPerfMonitor()
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self._createPerfCache()

    def _createPerfCache(self):

        self.libvirtPerf_monitor.perfDataCache[
            self.vmhost_id
        ] = {Constants.OLD_STATS: None,
             Constants.NEW_STATS: None}

    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()

    def test_refresh_perfdata(self):
        for _ in xrange(2):
            self._create_compute_inventory()
            self.libvirtVmHost.refresh_perfdata()
            self.mox.UnsetStubs()

        self.assertNotEquals(self.libvirtPerf_monitor.get_perfdata_fromCache(
            self.vmhost_id, Constants.NEW_STATS), None)
        self.assertNotEquals(self.libvirtPerf_monitor.get_perfdata_fromCache(
            self.vmhost_id, Constants.OLD_STATS), None)

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}
        self.mox.UnsetStubs()
Example #4
0
    def test_refresh_perfdata_forHost(self):
        self.mox.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn, self.vmhost_id, Constants.VmHost)
        self.assert_(True)
    def test_refresh_perfdata_NoCache(self):
        self.libvirtPerf_monitor.delete_perfdata_fromCache(
            self.vm_id
        )
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn,
            self.vm_id,
            Constants.VmHost)
    def test_refresh_perfdata_forHost(self):
        self.mox.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn,
            self.vmhost_id,
            Constants.VmHost)
        self.assert_(True)
class TestLibvirtPerfData(unittest.TestCase):

    inv_manager_cls = inventory_manager.InventoryManager
    paramiko.SSHClient = FakeSSH.SSHClient
    connection.libvirt = libvirt

    @classmethod
    def setUpClass(cls):
        cls.connection = LibvirtConnection(False)
        cls.mox = mox.Mox()
        cls.connection._wrapped_conn = libvirt.open('qemu:///system')
        cls.connection.libvirt = libvirt
        cls.vm_id = '25f04dd3-e924-02b2-9eac-876e3c943262'
        cls.vmhost_id = '1'

    def setUp(self):
        self.libvirtPerf_monitor = LibvirtPerfMonitor()
        self._createPerfCache()

    def _createPerfCache(self):

        self.libvirtPerf_monitor.perfDataCache[
            self.vm_id
        ] = {Constants.OLD_STATS: None,
             Constants.NEW_STATS: None}
        self.libvirtPerf_monitor.perfDataCache[
            self.vmhost_id
        ] = {Constants.OLD_STATS: None,
             Constants.NEW_STATS: None}

    def testDelete_perfdata_fromCache(self):
        self.assertEquals(len(self.libvirtPerf_monitor.perfDataCache),
                          2)
        self.libvirtPerf_monitor.delete_perfdata_fromCache(
            self.vm_id
        )
        self.assertEquals(len(self.libvirtPerf_monitor.perfDataCache),
                          1)

    def test_refresh_perfdata_forVm(self):
        self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           self.vm_id)
        self.mox.StubOutWithMock(LibvirtVmPerfData, 'refresh_perfdata')
        self.libvirtVM.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()

        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn,
            self.vm_id,
            Constants.Vm)

        self.assert_(True)

    def test_refresh_perfdata_forHost(self):
        self.mox.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn,
            self.vmhost_id,
            Constants.VmHost)
        self.assert_(True)

    def test_refresh_perfdata_NoCache(self):
        self.libvirtPerf_monitor.delete_perfdata_fromCache(
            self.vm_id
        )
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn,
            self.vm_id,
            Constants.VmHost)

    def test_get_host_resource_utilization(self):
        self.sample_perfdata = SamplePerfData()
        self.mox.StubOutWithMock(SamplePerfData, 'sample_host_perfdata')
        self.sample_perfdata.sample_host_perfdata(
            self.vmhost_id, 5).AndReturn(None)
        self.mox.ReplayAll()

        result = \
            self.libvirtPerf_monitor.get_resource_utilization(
                self.vmhost_id,
                Constants.VmHost, 5)
        self.assert_(True)

    def test_get_vm_resource_utilization(self):
        self.sample_perfdata = SamplePerfData()
        self.mox.StubOutWithMock(SamplePerfData, 'sample_vm_perfdata')
        self.sample_perfdata.sample_vm_perfdata(self.vm_id, 5).AndReturn(None)
        self.mox.ReplayAll()
        result = \
            self.libvirtPerf_monitor.get_resource_utilization(
                self.vm_id,
                Constants.Vm, 5)

        self.assert_(True)

    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)

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}
        self.mox.UnsetStubs()
 def setUp(self):
     self.libvirtPerf_monitor = LibvirtPerfMonitor()
     self.libvirtVmHost = LibvirtVmHostPerfData(
         self.connection._wrapped_conn, self.vmhost_id)
     self._createPerfCache()
Example #9
0
class TestLibvirtPerfData(unittest.TestCase):

    inv_manager_cls = inventory_manager.InventoryManager
    paramiko.SSHClient = FakeSSH.SSHClient
    connection.libvirt = libvirt

    @classmethod
    def setUpClass(cls):
        cls.connection = LibvirtConnection(False)
        cls.mox = mox.Mox()
        cls.connection._wrapped_conn = libvirt.open('qemu:///system')
        cls.connection.libvirt = libvirt
        cls.vm_id = '25f04dd3-e924-02b2-9eac-876e3c943262'
        cls.vmhost_id = '1'

    def setUp(self):
        self.libvirtPerf_monitor = LibvirtPerfMonitor()
        self._createPerfCache()

    def _createPerfCache(self):

        self.libvirtPerf_monitor.perfDataCache[self.vm_id] = {
            Constants.OLD_STATS: None,
            Constants.NEW_STATS: None
        }
        self.libvirtPerf_monitor.perfDataCache[self.vmhost_id] = {
            Constants.OLD_STATS: None,
            Constants.NEW_STATS: None
        }

    def testDelete_perfdata_fromCache(self):
        self.assertEquals(len(self.libvirtPerf_monitor.perfDataCache), 2)
        self.libvirtPerf_monitor.delete_perfdata_fromCache(self.vm_id)
        self.assertEquals(len(self.libvirtPerf_monitor.perfDataCache), 1)

    def test_refresh_perfdata_forVm(self):
        self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           self.vm_id)
        self.mox.StubOutWithMock(LibvirtVmPerfData, 'refresh_perfdata')
        self.libvirtVM.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()

        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn, self.vm_id, Constants.Vm)

        self.assert_(True)

    def test_refresh_perfdata_forHost(self):
        self.mox.StubOutWithMock(event_api, 'notify_host_update')
        event_api.notify_host_update(mox.IgnoreArg(), mox.IgnoreArg())

        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn, self.vmhost_id, Constants.VmHost)
        self.assert_(True)

    def test_refresh_perfdata_NoCache(self):
        self.libvirtPerf_monitor.delete_perfdata_fromCache(self.vm_id)
        self.libvirtVmHost = LibvirtVmHostPerfData(
            self.connection._wrapped_conn, self.vmhost_id)
        self.mox.StubOutWithMock(LibvirtVmHostPerfData, 'refresh_perfdata')
        self.libvirtVmHost.refresh_perfdata().AndReturn(None)

        self.mox.ReplayAll()
        self.libvirtPerf_monitor.refresh_perfdata(
            self.connection._wrapped_conn, self.vm_id, Constants.VmHost)

    def test_get_host_resource_utilization(self):
        self.sample_perfdata = SamplePerfData()
        self.mox.StubOutWithMock(SamplePerfData, 'sample_host_perfdata')
        self.sample_perfdata.sample_host_perfdata(self.vmhost_id,
                                                  5).AndReturn(None)
        self.mox.ReplayAll()

        result = \
            self.libvirtPerf_monitor.get_resource_utilization(
                self.vmhost_id,
                Constants.VmHost, 5)
        self.assert_(True)

    def test_get_vm_resource_utilization(self):
        self.sample_perfdata = SamplePerfData()
        self.mox.StubOutWithMock(SamplePerfData, 'sample_vm_perfdata')
        self.sample_perfdata.sample_vm_perfdata(self.vm_id, 5).AndReturn(None)
        self.mox.ReplayAll()
        result = \
            self.libvirtPerf_monitor.get_resource_utilization(
                self.vm_id,
                Constants.Vm, 5)

        self.assert_(True)

    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)

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}
        self.mox.UnsetStubs()
Example #10
0
 def setUp(self):
     self.libvirtPerf_monitor = LibvirtPerfMonitor()
     self.libvirtVmHost = LibvirtVmHostPerfData(
         self.connection._wrapped_conn, self.vmhost_id)
     self._createPerfCache()