Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.toolbox
Commits
0f13c98a
Commit
0f13c98a
authored
May 27, 2022
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qemuqmpclient: support qemu 7+
parent
7a7f8178
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
72 deletions
+54
-72
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+19
-18
slapos/test/test_qemuqmpclient.py
slapos/test/test_qemuqmpclient.py
+35
-54
No files found.
slapos/qemuqmpclient/__init__.py
View file @
0f13c98a
...
...
@@ -244,11 +244,10 @@ class QemuQMPWrapper(object):
# Set VNC password
print
(
'Setting VNC password...'
)
result
=
self
.
_send
({
"execute"
:
"
change
"
,
"execute"
:
"
set_password
"
,
"arguments"
:
{
"device"
:
"vnc"
,
"target"
:
"password"
,
"arg"
:
password
"protocol"
:
"vnc"
,
"password"
:
password
}
})
if
result
and
result
.
get
(
'return'
,
None
)
!=
{}:
...
...
@@ -336,17 +335,17 @@ class QemuQMPWrapper(object):
"""
cpu_info_dict
=
{
'hotplugged'
:
[],
'base'
:
[]}
cpu_list
=
self
.
_send
({
'execute'
:
'query-cpus'
'execute'
:
'query-cpus
-fast
'
},
retry
=
5
)[
'return'
]
for
cpu
in
cpu_list
:
if
'unattached'
in
cpu
[
'qom
_
path'
]:
if
'unattached'
in
cpu
[
'qom
-
path'
]:
index
=
'base'
else
:
index
=
'hotplugged'
cpu_info_dict
[
index
].
append
({
'props'
:
cpu
[
'props'
],
'CPU'
:
cpu
[
'
CPU
'
],
'qom_path'
:
cpu
[
'qom
_
path'
]
'CPU'
:
cpu
[
'
cpu-index
'
],
'qom_path'
:
cpu
[
'qom
-
path'
]
})
return
cpu_info_dict
...
...
@@ -438,16 +437,18 @@ class QemuQMPWrapper(object):
'execute'
:
'query-hotpluggable-cpus'
},
retry
=
5
)[
'return'
]
cpu_hotplugable_list
.
reverse
()
for
cpu
in
cpu_hotplugable_list
:
if
cpu
.
get
(
'qom-path'
,
''
)
==
''
:
for
i
,
cpu
in
enumerate
(
cpu_hotplugable_list
):
i
=
'cpu%s'
%
i
path
=
cpu
.
get
(
'qom-path'
)
if
not
path
:
if
len
(
empty_socket_list
)
<
amount
:
cpu
[
'props'
][
'driver'
]
=
cpu_model
cpu
[
'props'
][
'id'
]
=
'cpu%s'
%
(
cpu
[
'props'
][
'socket-id'
])
cpu
[
'props'
][
'id'
]
=
i
empty_socket_list
.
append
(
cpu
[
'props'
])
else
:
# if this is an hotpluggable cpu
if
'/machine/peripheral'
in
cpu
.
get
(
'qom-path'
,
'
'
):
used_socket_id_list
.
append
(
'cpu%s'
%
(
cpu
[
'props'
][
'socket-id'
])
)
if
path
.
startswith
(
'/machine/peripheral/
'
):
used_socket_id_list
.
append
(
i
)
cpu_amount
+=
1
else
:
unremovable_cpu
+=
1
...
...
@@ -544,10 +545,10 @@ class QemuQMPWrapper(object):
'id'
:
dimm
[
'data'
][
'id'
],
'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
for
memdev
in
cleanup_memdev_id_dict
.
keys
()
:
for
memdev
in
cleanup_memdev_id_dict
:
print
(
"Cleaning up memdev %s..."
%
memdev
)
self
.
_removeDevice
(
memdev
,
{
'execute'
:
'object-del'
,
...
...
@@ -557,7 +558,7 @@ class QemuQMPWrapper(object):
},
auto_reboot
=
allow_reboot
)
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
,
slot_size
))
if
(
mem_size
//
slot_size
)
>
slot_amount
:
...
...
@@ -594,14 +595,14 @@ class QemuQMPWrapper(object):
slot_add
=
(
mem_size
-
current_size
)
//
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
self
.
_send
({
'execute'
:
'object-add'
,
'arguments'
:
{
'qom-type'
:
'memory-backend-ram'
,
'id'
:
'mem%s'
%
index
,
'
props'
:
{
'size'
:
slot_size
*
1024
*
1024
}
'
size'
:
slot_size
*
1024
*
1024
}
})
self
.
_send
({
...
...
slapos/test/test_qemuqmpclient.py
View file @
0f13c98a
...
...
@@ -44,7 +44,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
# slot of 1G
self
.
memory_slot_size
=
1024
self
.
event_list
=
[]
self
.
fail
=
False
self
.
_
fail
=
False
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
base_dir
):
...
...
@@ -75,7 +75,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
self
.
setChange
(
'dimm'
,
-
1
*
self
.
memory_slot_size
)
if
message
[
'arguments'
][
'id'
].
startswith
(
'cpu'
):
self
.
setChange
(
'cpu'
,
-
1
)
if
self
.
fail
:
if
self
.
_
fail
:
return
{
"error"
:
{
"class"
:
"CommandFailed"
,
"desc"
:
""
}}
return
{
"return"
:
{}}
...
...
@@ -92,48 +92,42 @@ class TestQemuQMPWrapper(unittest.TestCase):
free_cpu_slot
=
self
.
free_cpu_slot_amount
-
self
.
readChange
(
'cpu'
)
for
i
in
range
(
4
,
4
-
free_cpu_slot
,
-
1
):
hotpluggable_cpu_list
.
append
({
u'props'
:
{
u'core-id'
:
0
,
u'node-id'
:
0
,
u'socket-id'
:
i
,
u'thread-id'
:
0
},
u'type'
:
u'
qemu64
-x86_64-cpu'
,
u'props'
:
{
u'core-id'
:
i
,
u'node-id'
:
0
,
u'socket-id'
:
0
,
u'thread-id'
:
0
},
u'type'
:
u'
host
-x86_64-cpu'
,
u'vcpus-count'
:
1
})
for
i
in
range
(
4
-
free_cpu_slot
,
0
,
-
1
):
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'type'
:
u'
qemu64
-x86_64-cpu'
,
u'type'
:
u'
host
-x86_64-cpu'
,
u'vcpus-count'
:
1
})
# first cpu
hotpluggable_cpu_list
.
append
(
{
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'type'
:
u'
qemu64
-x86_64-cpu'
,
u'type'
:
u'
host
-x86_64-cpu'
,
u'vcpus-count'
:
1
}
)
return
{
"return"
:
hotpluggable_cpu_list
}
elif
message
[
'execute'
]
==
'query-cpus'
:
elif
message
[
'execute'
]
==
'query-cpus
-fast
'
:
cpu_list
=
[]
cpu_slot
=
4
-
self
.
free_cpu_slot_amount
+
self
.
readChange
(
'cpu'
)
cpu_list
.
append
({
u'CPU'
:
0
,
u'arch'
:
u'x86'
,
u'current'
:
True
,
u'halted'
:
True
,
u'pc'
:
-
1694470494
,
u'cpu-index'
:
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
})
for
i
in
range
(
0
,
cpu_slot
):
for
i
in
range
(
1
,
cpu_slot
+
1
):
cpu_list
.
append
({
u'CPU'
:
i
+
1
,
u'arch'
:
u'x86'
,
u'current'
:
False
,
u'halted'
:
True
,
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'cpu-index'
:
i
,
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'target'
:
u'x86_64'
,
u'thread_id'
:
1187
})
return
{
"return"
:
cpu_list
}
...
...
@@ -178,16 +172,14 @@ class TestQemuQMPWrapper(unittest.TestCase):
qmpwrapper
.
_send
=
self
.
fake_send
expected_result
=
{
"execute"
:
"
change
"
,
"execute"
:
"
set_password
"
,
"arguments"
:
{
"device"
:
"vnc"
,
"target"
:
"password"
,
"arg"
:
"my password"
"protocol"
:
"vnc"
,
"password"
:
"my password"
}
}
qmpwrapper
.
setVNCPassword
(
"my password"
)
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
1
)
self
.
assertEqual
(
self
.
call_stack_list
[
0
],
expected_result
)
self
.
assertEqual
(
self
.
call_stack_list
,
[
expected_result
])
def
test_updateDevice_cpu_add
(
self
):
self
.
free_cpu_slot_amount
=
4
...
...
@@ -204,10 +196,10 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'device_add'
,
'arguments'
:
{
u'socket-id'
:
1
,
u'socket-id'
:
0
,
u'thread-id'
:
0
,
'driver'
:
'qemu64-x86_64-cpu'
,
u'core-id'
:
0
,
u'core-id'
:
1
,
u'node-id'
:
0
,
'id'
:
'cpu1'
}
...
...
@@ -215,18 +207,16 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'device_add'
,
'arguments'
:
{
u'socket-id'
:
2
,
u'socket-id'
:
0
,
u'thread-id'
:
0
,
'driver'
:
'qemu64-x86_64-cpu'
,
u'core-id'
:
0
,
u'core-id'
:
2
,
u'node-id'
:
0
,
'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
)
def
test_updateDevice_cpu_increase
(
self
):
...
...
@@ -244,10 +234,10 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'device_add'
,
'arguments'
:
{
u'socket-id'
:
3
,
u'socket-id'
:
0
,
u'thread-id'
:
0
,
'driver'
:
'qemu64-x86_64-cpu'
,
u'core-id'
:
0
,
u'core-id'
:
3
,
u'node-id'
:
0
,
'id'
:
'cpu3'
}
...
...
@@ -255,18 +245,17 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'device_add'
,
'arguments'
:
{
u'socket-id'
:
4
,
u'socket-id'
:
0
,
u'thread-id'
:
0
,
'driver'
:
'qemu64-x86_64-cpu'
,
u'core-id'
:
0
,
u'core-id'
:
4
,
u'node-id'
:
0
,
'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
)
def
test_updateDevice_cpu_remove
(
self
):
...
...
@@ -289,10 +278,9 @@ class TestQemuQMPWrapper(unittest.TestCase):
'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
)
def
test_updateDevice_cpu_no_update
(
self
):
...
...
@@ -309,7 +297,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'query-hotpluggable-cpus'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
1
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_add
(
self
):
...
...
@@ -334,7 +321,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
'arguments'
:
{
'id'
:
'mem1'
,
'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):
'arguments'
:
{
'id'
:
'mem2'
,
'qom-type'
:
'memory-backend-ram'
,
'
props'
:
{
'size'
:
1073741824
}
'
size'
:
1073741824
}
},
{
...
...
@@ -364,7 +351,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'query-memory-devices'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
7
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_increase
(
self
):
...
...
@@ -389,7 +375,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
'arguments'
:
{
'id'
:
'mem3'
,
'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):
{
'execute'
:
'query-memory-devices'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
5
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_delete
(
self
):
...
...
@@ -444,7 +429,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'query-memory-devices'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
7
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_delete_all
(
self
):
...
...
@@ -493,7 +477,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'query-memory-devices'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
9
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_no_update
(
self
):
...
...
@@ -515,14 +498,13 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'query-memdev'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
2
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
def
test_updateDevice_memory_will_reboot
(
self
):
qmpwrapper
=
QemuQMPWrapper
(
self
.
socket_file
,
auto_connect
=
False
)
qmpwrapper
.
_send
=
self
.
fake_send
qmpwrapper
.
getEventList
=
self
.
fake_getEventList
self
.
fail
=
True
self
.
_
fail
=
True
self
.
hotplugged_memory_amount
=
3072
# slot of 1G
self
.
memory_slot_size
=
1024
...
...
@@ -563,7 +545,6 @@ class TestQemuQMPWrapper(unittest.TestCase):
{
'execute'
:
'quit'
}
]
self
.
assertEqual
(
len
(
self
.
call_stack_list
),
9
)
self
.
assertEqual
(
self
.
call_stack_list
,
expected_result
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment