diff options
| author | Ewan Mellor <ewan.mellor@citrix.com> | 2011-11-26 11:40:31 -0800 |
|---|---|---|
| committer | Ewan Mellor <ewan.mellor@citrix.com> | 2011-11-26 14:22:30 -0800 |
| commit | a0baa5c125c0a7ef5bbc8684184ebf2c130bb466 (patch) | |
| tree | c15c3058832c367e75161c4b0eac4811e13197f4 /nova/virt | |
| parent | efc639ff4e0846535e1689a04537021d34c4c77d (diff) | |
Refactor a few things inside the xenapi unit tests.
There were a couple of places where basically the same code was being
used to create a simulated VDI record -- these have been brought together
into _make_fake_vdi.
fake_fetch_image was stubbing out parse_xmlrpc_value, which looks like it
was a workaround for the fact that the task result wasn't being populated
properly. I've fixed the latter, and removed the former. This moved the
JSON handling into xenapi.fake.
There were a couple of implementations of host_call_plugin, which contained
a lot of duplicated code. In particular, they both made a simulated VDI
record, even when the plugin function being called didn't require that.
I have brought the two implementations together into fake.SessionBase, with
overrides in the subclasses for those things that are specific to a given
test. I have also made the baseclass strict about flagging unsimulated
plugin calls, and added explicit handling for agent.version, and a couple
of methods from glance and migration.
Change-Id: Idc3a872870ae15165747a04ecd1b48e889bd90fd
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/fake.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index 59ea19fd0..4f40bb656 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -51,8 +51,10 @@ A fake XenAPI SDK. """ +import json import random import uuid +from xml.sax.saxutils import escape from pprint import pformat @@ -316,6 +318,21 @@ def check_for_session_leaks(): _db_content['session']) +def as_value(s): + """Helper function for simulating XenAPI plugin responses. It + escapes and wraps the given argument.""" + return '<value>%s</value>' % escape(s) + + +def as_json(*args, **kwargs): + """Helper function for simulating XenAPI plugin responses for those + that are returning JSON. If this function is given plain arguments, + then these are rendered as a JSON list. If it's given keyword + arguments then these are rendered as a JSON dict.""" + arg = args or kwargs + return json.dumps(arg) + + class Failure(Exception): def __init__(self, details): self.details = details @@ -435,8 +452,20 @@ class SessionBase(object): #Always return 12GB available return 12 * 1024 * 1024 * 1024 - def host_call_plugin(self, *args): - return 'herp' + def host_call_plugin(self, _1, _2, plugin, method, _5): + if (plugin, method) == ('agent', 'version'): + return as_json(returncode='0', message='1.0') + elif (plugin, method) == ('glance', 'copy_kernel_vdi'): + return '' + elif (plugin, method) == ('glance', 'upload_vhd'): + return '' + elif (plugin, method) == ('migration', 'move_vhds_into_sr'): + return '' + elif (plugin, method) == ('migration', 'transfer_vhd'): + return '' + else: + raise Exception('No simulation in host_call_plugin for %s,%s' % + (plugin, method)) def VDI_resize_online(self, *args): return 'derp' @@ -624,7 +653,10 @@ class SessionBase(object): task = _db_content['task'][task_ref] func = name[len('Async.'):] try: - task['result'] = self.xenapi_request(func, params[1:]) + result = self.xenapi_request(func, params[1:]) + if result: + result = as_value(result) + task['result'] = result task['status'] = 'success' except Failure, exc: task['error_info'] = exc.details |
