Ejemplo n.º 1
0
    def test_refresh_perfdata_nonactive(self):
        self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           'dummy')
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                'dummy', Constants.NEW_STATS), None)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_refresh_perfdata_nonactive(self):
        self.libvirtVM = LibvirtVmPerfData(
            self.connection._wrapped_conn, 'dummy')
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.
            get_perfdata_fromCache('dummy', Constants.NEW_STATS), None)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
 def setUp(self):
     self.libvirtPerf_monitor = LibvirtPerfMonitor()
     self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                        self.vm_id)
     self._createPerfCache()
Ejemplo n.º 7
0
class TestLibvirtVmPerfData(unittest.TestCase):

    libvirt_domain_cls = libvirt.virDomain

    @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.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           self.vm_id)
        self._createPerfCache()

    def _createPerfCache(self):

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

    def test_refresh_perfdata(self):
        for _ in xrange(2):
            self.libvirtVM.refresh_perfdata()

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

    def test_refresh_perfdata_notvalid(self):
        for _ in xrange(2):
            self.libvirtVM.refresh_perfdata()

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

    def test_refresh_perfdata_nonactive(self):
        self.libvirtVM = LibvirtVmPerfData(
            self.connection._wrapped_conn, 'dummy')
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.
            get_perfdata_fromCache('dummy', Constants.NEW_STATS), None)

    def test_refresh_perfdata_nodomainInfo(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls, 'info')
        self.libvirtVM.domainObj.info().AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(self.libvirtPerf_monitor.get_perfdata_fromCache(
            self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def test_refresh_perfdata_netException(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls,
                                 'interfaceStats')
        self.libvirtVM.domainObj.interfaceStats(mox.IgnoreArg()). \
            AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(self.libvirtPerf_monitor.get_perfdata_fromCache(
            self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def test_refresh_perfdata_diskException(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls, 'blockStats')
        self.libvirtVM.domainObj.blockStats(mox.IgnoreArg()). \
            AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(self.libvirtPerf_monitor.get_perfdata_fromCache(
            self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
 def setUp(self):
     self.libvirtPerf_monitor = LibvirtPerfMonitor()
     self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                        self.vm_id)
     self._createPerfCache()
Ejemplo n.º 10
0
class TestLibvirtVmPerfData(unittest.TestCase):

    libvirt_domain_cls = libvirt.virDomain

    @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.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           self.vm_id)
        self._createPerfCache()

    def _createPerfCache(self):

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

    def test_refresh_perfdata(self):
        for _ in xrange(2):
            self.libvirtVM.refresh_perfdata()

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

    def test_refresh_perfdata_notvalid(self):
        for _ in xrange(2):
            self.libvirtVM.refresh_perfdata()

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

    def test_refresh_perfdata_nonactive(self):
        self.libvirtVM = LibvirtVmPerfData(self.connection._wrapped_conn,
                                           'dummy')
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                'dummy', Constants.NEW_STATS), None)

    def test_refresh_perfdata_nodomainInfo(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls, 'info')
        self.libvirtVM.domainObj.info().AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def test_refresh_perfdata_netException(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls, 'interfaceStats')
        self.libvirtVM.domainObj.interfaceStats(mox.IgnoreArg()). \
            AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def test_refresh_perfdata_diskException(self):
        self.libvirtVM.domainObj = \
            self.connection._wrapped_conn.lookupByUUIDString(
                self.vm_id
            )
        self.mox.StubOutWithMock(self.libvirt_domain_cls, 'blockStats')
        self.libvirtVM.domainObj.blockStats(mox.IgnoreArg()). \
            AndRaise(libvirt.libvirtError)

        self.mox.ReplayAll()
        self.libvirtVM.refresh_perfdata()

        self.assertEquals(
            self.libvirtPerf_monitor.get_perfdata_fromCache(
                self.vm_id, Constants.NEW_STATS).status, -1)
        self.mox.UnsetStubs()

    def tearDown(self):
        self.libvirtPerf_monitor.perfDataCache = {}