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
Gabriel Monnerat
slapos.toolbox
Commits
f3aa60e4
Commit
f3aa60e4
authored
Feb 07, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some improvement
parent
bdd0294a
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
217 additions
and
62 deletions
+217
-62
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+174
-58
slapos/test/test_qemuqmpclient.py
slapos/test/test_qemuqmpclient.py
+43
-4
No files found.
slapos/qemuqmpclient/__init__.py
View file @
f3aa60e4
This diff is collapsed.
Click to expand it.
slapos/test/test_qemuqmpclient.py
View file @
f3aa60e4
...
@@ -31,7 +31,7 @@ import os
...
@@ -31,7 +31,7 @@ import os
import
tempfile
import
tempfile
import
shutil
import
shutil
from
slapos.qemuqmpclient
import
QemuQMPWrapper
from
slapos.qemuqmpclient
import
QemuQMPWrapper
,
QmpDeviceRemoveError
class
TestQemuQMPWrapper
(
unittest
.
TestCase
):
class
TestQemuQMPWrapper
(
unittest
.
TestCase
):
...
@@ -43,6 +43,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -43,6 +43,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
self
.
hotplugged_memory_amount
=
0
self
.
hotplugged_memory_amount
=
0
# slot of 1G
# slot of 1G
self
.
memory_slot_size
=
1024
self
.
memory_slot_size
=
1024
self
.
event_list
=
[]
self
.
fail
=
False
def
tearDown
(
self
):
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
base_dir
):
if
os
.
path
.
exists
(
self
.
base_dir
):
...
@@ -73,8 +75,16 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -73,8 +75,16 @@ 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
:
return
{
"error"
:
{
"class"
:
"CommandFailed"
,
"message"
:
""
}}
return
{
"return"
:
{}}
return
{
"return"
:
{}}
def
fake_getEventList
(
self
,
timeout
=
0
,
cleanup
=
False
):
if
self
.
event_list
:
return
self
.
event_list
else
:
return
[]
def
returnQueryResult
(
self
,
message
):
def
returnQueryResult
(
self
,
message
):
if
message
[
'execute'
]
==
'query-hotpluggable-cpus'
:
if
message
[
'execute'
]
==
'query-hotpluggable-cpus'
:
# return 4 hotpluggable cpu slots
# return 4 hotpluggable cpu slots
...
@@ -263,6 +273,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -263,6 +273,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
self
.
free_cpu_slot_amount
=
2
self
.
free_cpu_slot_amount
=
2
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
self
.
event_list
=
[{
"event"
:
"DEVICE_DELETED"
}]
# add 2 more cpu
# add 2 more cpu
cpu_option
=
{
cpu_option
=
{
'device'
:
'cpu'
,
'device'
:
'cpu'
,
...
@@ -397,6 +409,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -397,6 +409,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
def
test_updateDevice_memory_delete
(
self
):
def
test_updateDevice_memory_delete
(
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
self
.
event_list
=
[{
"event"
:
"DEVICE_DELETED"
}]
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
...
@@ -436,6 +450,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -436,6 +450,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
def
test_updateDevice_memory_delete_all
(
self
):
def
test_updateDevice_memory_delete_all
(
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
self
.
event_list
=
[{
"event"
:
"DEVICE_DELETED"
}]
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
...
@@ -505,6 +521,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -505,6 +521,8 @@ class TestQemuQMPWrapper(unittest.TestCase):
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
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
...
@@ -516,15 +534,36 @@ class TestQemuQMPWrapper(unittest.TestCase):
...
@@ -516,15 +534,36 @@ class TestQemuQMPWrapper(unittest.TestCase):
'slot'
:
self
.
memory_slot_size
,
'slot'
:
self
.
memory_slot_size
,
'canreboot'
:
True
'canreboot'
:
True
}
}
with
self
.
assertRaises
(
Valu
eError
):
with
self
.
assertRaises
(
QmpDeviceRemov
eError
):
qmpwrapper
.
updateDevice
(
cpu_option
)
qmpwrapper
.
updateDevice
(
cpu_option
)
expected_result
=
[
expected_result
=
[
{
'execute'
:
'query-memory-devices'
},
{
'execute'
:
'query-memory-devices'
},
{
'execute'
:
'query-memdev'
},
{
'execute'
:
'query-memdev'
},
{
'execute'
:
'system_powerdown'
}
{
'execute'
:
'device_del'
,
'arguments'
:
{
'id'
:
u'dimm3'
}
},
{
'execute'
:
'device_del'
,
'arguments'
:
{
'id'
:
u'dimm3'
}
},
{
'execute'
:
'device_del'
,
'arguments'
:
{
'id'
:
u'dimm3'
}
},
{
'execute'
:
'device_del'
,
'arguments'
:
{
'id'
:
u'dimm3'
}
},
{
'execute'
:
'device_del'
,
'arguments'
:
{
'id'
:
u'dimm3'
}
},
{
'execute'
:
'system_powerdown'
},
{
'execute'
:
'quit'
}
]
]
self
.
assertEquals
(
len
(
self
.
call_stack_list
),
3
)
self
.
assertEquals
(
len
(
self
.
call_stack_list
),
9
)
self
.
assertEquals
(
self
.
call_stack_list
,
expected_result
)
self
.
assertEquals
(
self
.
call_stack_list
,
expected_result
)
if
__name__
==
'__main__'
:
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