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:
parent
6bfaec0ac8
commit
065d6ab1d0
@ -2105,6 +2105,10 @@ class VmUtilsTestCase(test.TestCase):
|
||||
def call_plugin(session_self, service, command, kwargs):
|
||||
self.kwargs = kwargs
|
||||
|
||||
def call_plugin_serialized(session_self, service, command, *args,
|
||||
**kwargs):
|
||||
self.kwargs = kwargs
|
||||
|
||||
def fake_dumps(thing):
|
||||
return thing
|
||||
|
||||
@ -2119,7 +2123,7 @@ class VmUtilsTestCase(test.TestCase):
|
||||
session = FakeSession()
|
||||
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',
|
||||
auto_disk_config='auto disk config',
|
||||
os_type='os type')
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""Stubouts, mocks and fixtures for the test suite"""
|
||||
|
||||
import contextlib
|
||||
import pickle
|
||||
import random
|
||||
import sys
|
||||
|
||||
@ -169,7 +170,7 @@ class FakeSessionForVMTests(fake.SessionBase):
|
||||
def host_call_plugin(self, _1, _2, plugin, method, _5):
|
||||
if (plugin, method) == ('glance', 'download_vhd'):
|
||||
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"):
|
||||
return fake.as_json(out=self._fake_iptables_save_output,
|
||||
err='')
|
||||
@ -181,8 +182,8 @@ class FakeSessionForVMTests(fake.SessionBase):
|
||||
if (plugin, method) == ('glance', 'download_vhd'):
|
||||
root_uuid = _make_fake_vdi()
|
||||
swap_uuid = _make_fake_vdi()
|
||||
return jsonutils.dumps(dict(root=dict(uuid=root_uuid),
|
||||
swap=dict(uuid=swap_uuid)))
|
||||
return pickle.dumps(dict(root=dict(uuid=root_uuid),
|
||||
swap=dict(uuid=swap_uuid)))
|
||||
else:
|
||||
return (super(FakeSessionForVMTests, self).
|
||||
host_call_plugin(_1, _2, plugin, method, _5))
|
||||
|
Loading…
Reference in New Issue
Block a user