Commit f3aa60e4 authored by Alain Takoudjou's avatar Alain Takoudjou

some improvement

parent bdd0294a
This diff is collapsed.
...@@ -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(ValueError): with self.assertRaises(QmpDeviceRemoveError):
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__':
......
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