xenapi: Make dom0 serialization consistent.
The dom0 plugin code had been using `pickle` for serializing input and `json` for serializing output which was needlessly inconsistent. This patch makes the code use `pickle`--chosen for its better handling of `datetime` objects--for both sending and receiving data. This patch also refactors the code so that neither the caller nor the callee need to explicitly worry about serialization: the caller just passes in args and kwargs, and the callee's function signature just accepts the args and kwargs as usual. Bonus: Removes unecessary imports Change-Id: I3abb42eeebd8d37d67e6c26fa7bcae66d876b3ee
This commit is contained in:
@@ -2105,6 +2105,10 @@ class VmUtilsTestCase(test.TestCase):
|
|||||||
def call_plugin(session_self, service, command, kwargs):
|
def call_plugin(session_self, service, command, kwargs):
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
def call_plugin_serialized(session_self, service, command, *args,
|
||||||
|
**kwargs):
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def fake_dumps(thing):
|
def fake_dumps(thing):
|
||||||
return thing
|
return thing
|
||||||
|
|
||||||
@@ -2119,7 +2123,7 @@ class VmUtilsTestCase(test.TestCase):
|
|||||||
session = FakeSession()
|
session = FakeSession()
|
||||||
vm_utils.upload_image(ctx, session, instance, "vmi uuids", "image id")
|
vm_utils.upload_image(ctx, session, instance, "vmi uuids", "image id")
|
||||||
|
|
||||||
actual = self.kwargs['params']['properties']
|
actual = self.kwargs['properties']
|
||||||
expected = dict(a=1, b=2, c='c', d='d',
|
expected = dict(a=1, b=2, c='c', d='d',
|
||||||
auto_disk_config='auto disk config',
|
auto_disk_config='auto disk config',
|
||||||
os_type='os type')
|
os_type='os type')
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
"""Stubouts, mocks and fixtures for the test suite"""
|
"""Stubouts, mocks and fixtures for the test suite"""
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import pickle
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ class FakeSessionForVMTests(fake.SessionBase):
|
|||||||
def host_call_plugin(self, _1, _2, plugin, method, _5):
|
def host_call_plugin(self, _1, _2, plugin, method, _5):
|
||||||
if (plugin, method) == ('glance', 'download_vhd'):
|
if (plugin, method) == ('glance', 'download_vhd'):
|
||||||
root_uuid = _make_fake_vdi()
|
root_uuid = _make_fake_vdi()
|
||||||
return jsonutils.dumps(dict(root=dict(uuid=root_uuid)))
|
return pickle.dumps(dict(root=dict(uuid=root_uuid)))
|
||||||
elif (plugin, method) == ("xenhost", "iptables_config"):
|
elif (plugin, method) == ("xenhost", "iptables_config"):
|
||||||
return fake.as_json(out=self._fake_iptables_save_output,
|
return fake.as_json(out=self._fake_iptables_save_output,
|
||||||
err='')
|
err='')
|
||||||
@@ -181,8 +182,8 @@ class FakeSessionForVMTests(fake.SessionBase):
|
|||||||
if (plugin, method) == ('glance', 'download_vhd'):
|
if (plugin, method) == ('glance', 'download_vhd'):
|
||||||
root_uuid = _make_fake_vdi()
|
root_uuid = _make_fake_vdi()
|
||||||
swap_uuid = _make_fake_vdi()
|
swap_uuid = _make_fake_vdi()
|
||||||
return jsonutils.dumps(dict(root=dict(uuid=root_uuid),
|
return pickle.dumps(dict(root=dict(uuid=root_uuid),
|
||||||
swap=dict(uuid=swap_uuid)))
|
swap=dict(uuid=swap_uuid)))
|
||||||
else:
|
else:
|
||||||
return (super(FakeSessionForVMTests, self).
|
return (super(FakeSessionForVMTests, self).
|
||||||
host_call_plugin(_1, _2, plugin, method, _5))
|
host_call_plugin(_1, _2, plugin, method, _5))
|
||||||
|
Reference in New Issue
Block a user