Commit 0f13c98a authored by Julien Muchembled's avatar Julien Muchembled

qemuqmpclient: support qemu 7+

parent 7a7f8178
...@@ -244,11 +244,10 @@ class QemuQMPWrapper(object): ...@@ -244,11 +244,10 @@ class QemuQMPWrapper(object):
# Set VNC password # Set VNC password
print('Setting VNC password...') print('Setting VNC password...')
result = self._send({ result = self._send({
"execute": "change", "execute": "set_password",
"arguments": { "arguments": {
"device": "vnc", "protocol": "vnc",
"target": "password", "password": password
"arg": password
} }
}) })
if result and result.get('return', None) != {}: if result and result.get('return', None) != {}:
...@@ -336,17 +335,17 @@ class QemuQMPWrapper(object): ...@@ -336,17 +335,17 @@ class QemuQMPWrapper(object):
""" """
cpu_info_dict = {'hotplugged': [], 'base': []} cpu_info_dict = {'hotplugged': [], 'base': []}
cpu_list = self._send({ cpu_list = self._send({
'execute': 'query-cpus' 'execute': 'query-cpus-fast'
}, retry=5)['return'] }, retry=5)['return']
for cpu in cpu_list: for cpu in cpu_list:
if 'unattached' in cpu['qom_path']: if 'unattached' in cpu['qom-path']:
index = 'base' index = 'base'
else: else:
index = 'hotplugged' index = 'hotplugged'
cpu_info_dict[index].append({ cpu_info_dict[index].append({
'props': cpu['props'], 'props': cpu['props'],
'CPU': cpu['CPU'], 'CPU': cpu['cpu-index'],
'qom_path': cpu['qom_path'] 'qom_path': cpu['qom-path']
}) })
return cpu_info_dict return cpu_info_dict
...@@ -438,16 +437,18 @@ class QemuQMPWrapper(object): ...@@ -438,16 +437,18 @@ class QemuQMPWrapper(object):
'execute': 'query-hotpluggable-cpus' 'execute': 'query-hotpluggable-cpus'
}, retry=5)['return'] }, retry=5)['return']
cpu_hotplugable_list.reverse() cpu_hotplugable_list.reverse()
for cpu in cpu_hotplugable_list: for i, cpu in enumerate(cpu_hotplugable_list):
if cpu.get('qom-path', '') == '': i = 'cpu%s' % i
path = cpu.get('qom-path')
if not path:
if len(empty_socket_list) < amount: if len(empty_socket_list) < amount:
cpu['props']['driver'] = cpu_model cpu['props']['driver'] = cpu_model
cpu['props']['id'] = 'cpu%s' % (cpu['props']['socket-id']) cpu['props']['id'] = i
empty_socket_list.append(cpu['props']) empty_socket_list.append(cpu['props'])
else: else:
# if this is an hotpluggable cpu # if this is an hotpluggable cpu
if '/machine/peripheral' in cpu.get('qom-path', ''): if path.startswith('/machine/peripheral/'):
used_socket_id_list.append('cpu%s' % (cpu['props']['socket-id'])) used_socket_id_list.append(i)
cpu_amount += 1 cpu_amount += 1
else: else:
unremovable_cpu += 1 unremovable_cpu += 1
...@@ -544,10 +545,10 @@ class QemuQMPWrapper(object): ...@@ -544,10 +545,10 @@ class QemuQMPWrapper(object):
'id': dimm['data']['id'], 'id': dimm['data']['id'],
'size': dimm['data']['size']//(1024 * 1024), 'size': dimm['data']['size']//(1024 * 1024),
}) })
memory_id_list = sorted(memory_id_list, key=itemgetter('id')) memory_id_list.sort(key=itemgetter('id'))
# cleanup memdev that was not removed because of failure # cleanup memdev that was not removed because of failure
for memdev in cleanup_memdev_id_dict.keys(): for memdev in cleanup_memdev_id_dict:
print("Cleaning up memdev %s..." % memdev) print("Cleaning up memdev %s..." % memdev)
self._removeDevice(memdev, { self._removeDevice(memdev, {
'execute': 'object-del', 'execute': 'object-del',
...@@ -557,7 +558,7 @@ class QemuQMPWrapper(object): ...@@ -557,7 +558,7 @@ class QemuQMPWrapper(object):
}, auto_reboot=allow_reboot) }, auto_reboot=allow_reboot)
num_slot_used = len(memory_id_list) num_slot_used = len(memory_id_list)
if (mem_size % slot_size) != 0: if mem_size % slot_size:
raise ValueError("Memory size %r is not a multiple of %r" % (mem_size, raise ValueError("Memory size %r is not a multiple of %r" % (mem_size,
slot_size)) slot_size))
if (mem_size // slot_size) > slot_amount: if (mem_size // slot_size) > slot_amount:
...@@ -594,14 +595,14 @@ class QemuQMPWrapper(object): ...@@ -594,14 +595,14 @@ class QemuQMPWrapper(object):
slot_add = (mem_size - current_size) // slot_size slot_add = (mem_size - current_size) // slot_size
print("Adding %s memory slot(s) of %s MB..." % (slot_add, slot_size)) print("Adding %s memory slot(s) of %s MB..." % (slot_add, slot_size))
for i in range(0, slot_add): for i in range(slot_add):
index = num_slot_used + i + 1 index = num_slot_used + i + 1
self._send({ self._send({
'execute': 'object-add', 'execute': 'object-add',
'arguments': { 'arguments': {
'qom-type': 'memory-backend-ram', 'qom-type': 'memory-backend-ram',
'id': 'mem%s' % index, 'id': 'mem%s' % index,
'props': { 'size': slot_size * 1024 * 1024 } 'size': slot_size * 1024 * 1024
} }
}) })
self._send({ self._send({
......
...@@ -44,7 +44,7 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -44,7 +44,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
# slot of 1G # slot of 1G
self.memory_slot_size = 1024 self.memory_slot_size = 1024
self.event_list = [] self.event_list = []
self.fail = False self._fail = False
def tearDown(self): def tearDown(self):
if os.path.exists(self.base_dir): if os.path.exists(self.base_dir):
...@@ -75,7 +75,7 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -75,7 +75,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
self.setChange('dimm', -1 * self.memory_slot_size) self.setChange('dimm', -1 * self.memory_slot_size)
if message['arguments']['id'].startswith('cpu'): if message['arguments']['id'].startswith('cpu'):
self.setChange('cpu', -1) self.setChange('cpu', -1)
if self.fail: if self._fail:
return {"error": {"class": "CommandFailed", "desc": ""}} return {"error": {"class": "CommandFailed", "desc": ""}}
return {"return": {}} return {"return": {}}
...@@ -92,48 +92,42 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -92,48 +92,42 @@ class TestQemuQMPWrapper(unittest.TestCase):
free_cpu_slot = self.free_cpu_slot_amount - self.readChange('cpu') free_cpu_slot = self.free_cpu_slot_amount - self.readChange('cpu')
for i in range(4, 4 - free_cpu_slot, -1): for i in range(4, 4 - free_cpu_slot, -1):
hotpluggable_cpu_list.append({ hotpluggable_cpu_list.append({
u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': i, u'thread-id': 0}, u'props': {u'core-id': i, u'node-id': 0, u'socket-id': 0, u'thread-id': 0},
u'type': u'qemu64-x86_64-cpu', u'type': u'host-x86_64-cpu',
u'vcpus-count': 1 u'vcpus-count': 1
}) })
for i in range(4 - free_cpu_slot, 0, -1): for i in range(4 - free_cpu_slot, 0, -1):
hotpluggable_cpu_list.append({ hotpluggable_cpu_list.append({
u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': i, u'thread-id': 0}, u'props': {u'core-id': i, u'node-id': 0, u'socket-id': 0, u'thread-id': 0},
u'qom-path': u'/machine/peripheral/cpu%s' % i, u'qom-path': u'/machine/peripheral/cpu%s' % i,
u'type': u'qemu64-x86_64-cpu', u'type': u'host-x86_64-cpu',
u'vcpus-count': 1 u'vcpus-count': 1
}) })
# first cpu # first cpu
hotpluggable_cpu_list.append( hotpluggable_cpu_list.append(
{u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': 0, u'thread-id': 0}, {u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': 0, u'thread-id': 0},
u'qom-path': u'/machine/unattached/device[0]', u'qom-path': u'/machine/unattached/device[0]',
u'type': u'qemu64-x86_64-cpu', u'type': u'host-x86_64-cpu',
u'vcpus-count': 1 u'vcpus-count': 1
} }
) )
return {"return": hotpluggable_cpu_list} return {"return": hotpluggable_cpu_list}
elif message['execute'] == 'query-cpus': elif message['execute'] == 'query-cpus-fast':
cpu_list = [] cpu_list = []
cpu_slot = 4 - self.free_cpu_slot_amount + self.readChange('cpu') cpu_slot = 4 - self.free_cpu_slot_amount + self.readChange('cpu')
cpu_list.append({ cpu_list.append({
u'CPU': 0, u'cpu-index': 0,
u'arch': u'x86',
u'current': True,
u'halted': True,
u'pc': -1694470494,
u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': 0, u'thread-id': 0}, u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': 0, u'thread-id': 0},
u'qom_path': u'/machine/unattached/device[0]', u'qom-path': u'/machine/unattached/device[0]',
u'target': u'x86_64',
u'thread_id': 1181 u'thread_id': 1181
}) })
for i in range(0, cpu_slot): for i in range(1, cpu_slot+1):
cpu_list.append({ cpu_list.append({
u'CPU': i + 1, u'cpu-index': i,
u'arch': u'x86', u'props': {u'core-id': i, u'node-id': 0, u'socket-id': 0, u'thread-id': 0},
u'current': False, u'qom-path': u'/machine/peripheral/cpu%s' % i,
u'halted': True, u'target': u'x86_64',
u'pc': -1694470494,
u'props': {u'core-id': 0, u'node-id': 0, u'socket-id': i + 1, u'thread-id': 0},
u'qom_path': u'/machine/peripheral/cpu%s' % (i + 1),
u'thread_id': 1187 u'thread_id': 1187
}) })
return {"return": cpu_list} return {"return": cpu_list}
...@@ -178,16 +172,14 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -178,16 +172,14 @@ class TestQemuQMPWrapper(unittest.TestCase):
qmpwrapper._send = self.fake_send qmpwrapper._send = self.fake_send
expected_result = { expected_result = {
"execute": "change", "execute": "set_password",
"arguments": { "arguments": {
"device": "vnc", "protocol": "vnc",
"target": "password", "password": "my password"
"arg": "my password"
} }
} }
qmpwrapper.setVNCPassword("my password") qmpwrapper.setVNCPassword("my password")
self.assertEqual(len(self.call_stack_list), 1) self.assertEqual(self.call_stack_list, [expected_result])
self.assertEqual(self.call_stack_list[0], expected_result)
def test_updateDevice_cpu_add(self): def test_updateDevice_cpu_add(self):
self.free_cpu_slot_amount = 4 self.free_cpu_slot_amount = 4
...@@ -204,10 +196,10 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -204,10 +196,10 @@ class TestQemuQMPWrapper(unittest.TestCase):
{ {
'execute': 'device_add', 'execute': 'device_add',
'arguments': { 'arguments': {
u'socket-id': 1, u'socket-id': 0,
u'thread-id': 0, u'thread-id': 0,
'driver': 'qemu64-x86_64-cpu', 'driver': 'qemu64-x86_64-cpu',
u'core-id': 0, u'core-id': 1,
u'node-id': 0, u'node-id': 0,
'id': 'cpu1' 'id': 'cpu1'
} }
...@@ -215,18 +207,16 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -215,18 +207,16 @@ class TestQemuQMPWrapper(unittest.TestCase):
{ {
'execute': 'device_add', 'execute': 'device_add',
'arguments': { 'arguments': {
u'socket-id': 2, u'socket-id': 0,
u'thread-id': 0, u'thread-id': 0,
'driver': 'qemu64-x86_64-cpu', 'driver': 'qemu64-x86_64-cpu',
u'core-id': 0, u'core-id': 2,
u'node-id': 0, u'node-id': 0,
'id': 'cpu2' 'id': 'cpu2'
} }
}, },
{'execute': 'query-cpus'} {'execute': 'query-cpus-fast'}
] ]
self.assertEqual(len(self.call_stack_list), 4)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_cpu_increase(self): def test_updateDevice_cpu_increase(self):
...@@ -244,10 +234,10 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -244,10 +234,10 @@ class TestQemuQMPWrapper(unittest.TestCase):
{ {
'execute': 'device_add', 'execute': 'device_add',
'arguments': { 'arguments': {
u'socket-id': 3, u'socket-id': 0,
u'thread-id': 0, u'thread-id': 0,
'driver': 'qemu64-x86_64-cpu', 'driver': 'qemu64-x86_64-cpu',
u'core-id': 0, u'core-id': 3,
u'node-id': 0, u'node-id': 0,
'id': 'cpu3' 'id': 'cpu3'
} }
...@@ -255,18 +245,17 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -255,18 +245,17 @@ class TestQemuQMPWrapper(unittest.TestCase):
{ {
'execute': 'device_add', 'execute': 'device_add',
'arguments': { 'arguments': {
u'socket-id': 4, u'socket-id': 0,
u'thread-id': 0, u'thread-id': 0,
'driver': 'qemu64-x86_64-cpu', 'driver': 'qemu64-x86_64-cpu',
u'core-id': 0, u'core-id': 4,
u'node-id': 0, u'node-id': 0,
'id': 'cpu4' 'id': 'cpu4'
} }
}, },
{'execute': 'query-cpus'} {'execute': 'query-cpus-fast'}
] ]
self.assertEqual(len(self.call_stack_list), 4)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_cpu_remove(self): def test_updateDevice_cpu_remove(self):
...@@ -289,10 +278,9 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -289,10 +278,9 @@ class TestQemuQMPWrapper(unittest.TestCase):
'id': 'cpu2' 'id': 'cpu2'
} }
}, },
{'execute': 'query-cpus'} {'execute': 'query-cpus-fast'}
] ]
self.assertEqual(len(self.call_stack_list), 3)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_cpu_no_update(self): def test_updateDevice_cpu_no_update(self):
...@@ -309,7 +297,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -309,7 +297,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-hotpluggable-cpus'} {'execute': 'query-hotpluggable-cpus'}
] ]
self.assertEqual(len(self.call_stack_list), 1)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_add(self): def test_updateDevice_memory_add(self):
...@@ -334,7 +321,7 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -334,7 +321,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
'arguments': { 'arguments': {
'id': 'mem1', 'id': 'mem1',
'qom-type': 'memory-backend-ram', 'qom-type': 'memory-backend-ram',
'props': {'size': self.memory_slot_size * 1024 * 1024} 'size': self.memory_slot_size * 1024 * 1024
} }
}, },
{ {
...@@ -350,7 +337,7 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -350,7 +337,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
'arguments': { 'arguments': {
'id': 'mem2', 'id': 'mem2',
'qom-type': 'memory-backend-ram', 'qom-type': 'memory-backend-ram',
'props': {'size': 1073741824} 'size': 1073741824
} }
}, },
{ {
...@@ -364,7 +351,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -364,7 +351,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-memory-devices'} {'execute': 'query-memory-devices'}
] ]
self.assertEqual(len(self.call_stack_list), 7)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_increase(self): def test_updateDevice_memory_increase(self):
...@@ -389,7 +375,7 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -389,7 +375,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
'arguments': { 'arguments': {
'id': 'mem3', 'id': 'mem3',
'qom-type': 'memory-backend-ram', 'qom-type': 'memory-backend-ram',
'props': {'size': self.memory_slot_size * 1024 * 1024} 'size': self.memory_slot_size * 1024 * 1024
} }
}, },
{ {
...@@ -403,7 +389,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -403,7 +389,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-memory-devices'} {'execute': 'query-memory-devices'}
] ]
self.assertEqual(len(self.call_stack_list), 5)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_delete(self): def test_updateDevice_memory_delete(self):
...@@ -444,7 +429,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -444,7 +429,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-memory-devices'} {'execute': 'query-memory-devices'}
] ]
self.assertEqual(len(self.call_stack_list), 7)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_delete_all(self): def test_updateDevice_memory_delete_all(self):
...@@ -493,7 +477,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -493,7 +477,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-memory-devices'} {'execute': 'query-memory-devices'}
] ]
self.assertEqual(len(self.call_stack_list), 9)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_no_update(self): def test_updateDevice_memory_no_update(self):
...@@ -515,14 +498,13 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -515,14 +498,13 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'query-memdev'} {'execute': 'query-memdev'}
] ]
self.assertEqual(len(self.call_stack_list), 2)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
def test_updateDevice_memory_will_reboot(self): def test_updateDevice_memory_will_reboot(self):
qmpwrapper = QemuQMPWrapper(self.socket_file, auto_connect=False) qmpwrapper = QemuQMPWrapper(self.socket_file, auto_connect=False)
qmpwrapper._send = self.fake_send qmpwrapper._send = self.fake_send
qmpwrapper.getEventList = self.fake_getEventList qmpwrapper.getEventList = self.fake_getEventList
self.fail = True self._fail = True
self.hotplugged_memory_amount = 3072 self.hotplugged_memory_amount = 3072
# slot of 1G # slot of 1G
self.memory_slot_size = 1024 self.memory_slot_size = 1024
...@@ -563,7 +545,6 @@ class TestQemuQMPWrapper(unittest.TestCase): ...@@ -563,7 +545,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{'execute': 'quit'} {'execute': 'quit'}
] ]
self.assertEqual(len(self.call_stack_list), 9)
self.assertEqual(self.call_stack_list, expected_result) self.assertEqual(self.call_stack_list, expected_result)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment