class TestNumaUtils(TestCaseBase): @MonkeyPatch(ET, 'parse', lambda x: ET.fromstring(_VM_RUN_FILE_CONTENT)) def testVcpuPid(self): vcpuPids = numaUtils.getVcpuPid('testvm') expectedVcpuPids = {0: '12266', 1: '12267', 2: '12268', 3: '12269'} self.assertEqual(vcpuPids, expectedVcpuPids) @MonkeyPatch(numaUtils, 'supervdsm', fake.SuperVdsm()) @MonkeyPatch(caps, 'getNumaTopology', lambda: {'0': {'cpus': [0, 1, 2, 3], 'totalMemory': '49141'}, '1': {'cpus': [4, 5, 6, 7], 'totalMemory': '49141'}}) def testVmNumaNodeRuntimeInfo(self): VM_PARAMS = {'guestNumaNodes': [{'cpus': '0,1', 'memory': '1024', 'nodeIndex': 0}, {'cpus': '2,3', 'memory': '1024', 'nodeIndex': 1}]} with fake.VM(VM_PARAMS) as testvm: testvm._vmStats = fake.VmStatsThread(testvm) expectedResult = {'0': [0, 1], '1': [0, 1]} vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(testvm) self.assertEqual(expectedResult, vmNumaNodeRuntimeMap)
def test_console_pty_not_prepare_path(self): supervdsm = fake.SuperVdsm() with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]): dev = {'device': 'console'} con = vmdevices.core.Console(self.cfg, self.log, **dev) con.prepare() self.assertEqual(supervdsm.prepared_path, None)
def test_console_usock_prepare_path(self): supervdsm = fake.SuperVdsm() with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]): dev = {'device': 'console', 'specParams': {'enableSocket': True}} con = vmdevices.core.Console(self.cfg, self.log, **dev) con.prepare() self.assertEqual(supervdsm.prepared_path, self._expected_path) self.assertEqual(supervdsm.prepared_path_group, constants.OVIRT_VMCONSOLE_GROUP)
def test_disk_hotplug(self): vm = self.vm params = {'xml': self.DISK_HOTPLUG} supervdsm = fake.SuperVdsm() with MonkeyPatchScope([(vmdevices.network, 'supervdsm', supervdsm)]): vm.hotplugDisk(params) self.assertEqual(len(vm.getDiskDevices()), 1) dev = vm._devices[hwclass.DISK][0] self.assertEqual(dev.serial, '1234') self.assertEqual(dev.domainID, '1111') self.assertEqual(dev.name, 'sda')
def setUp(self): devices = [{'nicModel': 'virtio', 'network': 'ovirtmgmt', 'macAddr': "11:22:33:44:55:66", 'device': 'bridge', 'type': 'interface', 'alias': 'net1', 'name': 'net1', 'linkActive': 'true', }] with fake.VM(devices=devices, create_device_objects=True) as vm: vm._dom = fake.Domain(vm=vm) self.vm = vm self.supervdsm = fake.SuperVdsm()
def test_console_pty_not_prepare_path(self): supervdsm = fake.SuperVdsm() with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]): dom = xmlutils.fromstring(""" <console type="pty"> <source path="/abc/def"/> <target port="0" type="serial"/> <alias name="ua-1234"/> </console> """) vmdevices.core.prepare_console(dom, self.cfg['vmId']) self.assertEqual(supervdsm.prepared_path, None)
def test_console_usock_prepare_path(self): supervdsm = fake.SuperVdsm() with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]): dom = xmlutils.fromstring(""" <console type="unix"> <source mode="bind" path="%s"/> <target port="0" type="serial"/> <alias name="ua-1234"/> </console> """ % (self._expected_path, )) vmdevices.core.prepare_console(dom, self.cfg['vmId']) self.assertEqual(supervdsm.prepared_path, self._expected_path) self.assertEqual(supervdsm.prepared_path_group, constants.OVIRT_VMCONSOLE_GROUP)
def setUp(self): devices = ''' <interface type="bridge"> <mac address="11:22:33:44:55:66"/> <model type="virtio"/> <source bridge="ovirtmgmt"/> <virtualport type="openvswitch"/> <link state="down"/> <alias name="net1"/> <target dev="net1"/> </interface> ''' with fake.VM(xmldevices=devices, create_device_objects=True) as vm: vm._dom = fake.Domain(vm=vm) self.vm = vm self.supervdsm = fake.SuperVdsm()
class TestNumaUtils(TestCaseBase): @MonkeyPatch(ET, 'parse', lambda x: ET.fromstring(_VM_RUN_FILE_CONTENT)) @MonkeyPatch(os.path, 'getmtime', lambda x: 0) def testVcpuPid(self): vcpuPids = numa.getVcpuPid('testvm') expectedVcpuPids = {0: '12266', 1: '12267', 2: '12268', 3: '12269'} self.assertEqual(vcpuPids, expectedVcpuPids) @MonkeyPatch(numa, 'supervdsm', fake.SuperVdsm()) @MonkeyPatch( numa, 'topology', lambda: { '0': { 'cpus': [0, 1, 2, 3], 'totalMemory': '49141' }, '1': { 'cpus': [4, 5, 6, 7], 'totalMemory': '49141' } }) def testVmNumaNodeRuntimeInfo(self): VM_PARAMS = { 'guestNumaNodes': [{ 'cpus': '0,1', 'memory': '1024', 'nodeIndex': 0 }, { 'cpus': '2,3', 'memory': '1024', 'nodeIndex': 1 }] } with fake.VM(VM_PARAMS) as testvm: expectedResult = {'0': [0, 1], '1': [0, 1]} self.assertTrue(testvm.hasGuestNumaNode) sample = [ (0, 1, 19590000000, 1), (1, 1, 10710000000, 1), (2, 1, 19590000000, 0), (3, 1, 19590000000, 2), # CPU not assigned by Engine, should be ignored: (4, 1, 10710000000, 0) ] with MonkeyPatchScope([(numa, "_get_vcpu_positioning", lambda vm: sample)]): vm_numa_info = numa.getVmNumaNodeRuntimeInfo(testvm) self.assertEqual(expectedResult, vm_numa_info)