From 065d6ab1d0b55218406f343ed775d258f28ba197 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 6 Sep 2012 21:42:08 +0000 Subject: [PATCH] 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 --- nova/tests/test_xenapi.py | 6 +++++- nova/tests/xenapi/stubs.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index ea6ed857c..2bf7429bd 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -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') diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index bb31a5327..3bfdd3dbe 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -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))