summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-30 17:22:55 +0000
committerGerrit Code Review <review@openstack.org>2013-01-30 17:22:55 +0000
commitef35e9dee06922a275beb40e91e42329f5cfcab5 (patch)
tree394b236c70c3b7bbd180deabe0e7eaefceb55298 /nova/tests
parent1584ebba0bf2b6330909abd3802e163ad6b788ac (diff)
parentc9af27c2302dda74e702c1cdc50a521fe0b32431 (diff)
Merge "xenapi: Add support for different image upload drivers"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_xenapi.py68
-rw-r--r--nova/tests/virt/xenapi/imageupload/__init__.py0
-rw-r--r--nova/tests/virt/xenapi/imageupload/test_glance.py74
3 files changed, 92 insertions, 50 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 067e28a13..aa640810b 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -19,7 +19,6 @@
import ast
import base64
import contextlib
-import cPickle as pickle
import functools
import os
import re
@@ -48,6 +47,7 @@ from nova.virt.xenapi import agent
from nova.virt.xenapi import driver as xenapi_conn
from nova.virt.xenapi import fake as xenapi_fake
from nova.virt.xenapi import host
+from nova.virt.xenapi.imageupload import glance
from nova.virt.xenapi import pool
from nova.virt.xenapi import pool_states
from nova.virt.xenapi import vm_utils
@@ -431,15 +431,29 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
{'task_state': task_states.IMAGE_UPLOADING,
'expected_state': task_states.IMAGE_PENDING_UPLOAD}}]
func_call_matcher = matchers.FunctionCallMatcher(expected_calls)
+ image_id = "my_snapshot_id"
stubs.stubout_instance_snapshot(self.stubs)
stubs.stubout_is_snapshot(self.stubs)
# Stubbing out firewall driver as previous stub sets alters
# xml rpc result parsing
stubs.stubout_firewall_driver(self.stubs, self.conn)
+
instance = self._create_instance()
- image_id = "my_snapshot_id"
+ self.fake_upload_called = False
+
+ def fake_image_upload(_self, ctx, session, inst, vdi_uuids,
+ img_id):
+ self.fake_upload_called = True
+ self.assertEqual(ctx, self.context)
+ self.assertEqual(inst, instance)
+ self.assertTrue(isinstance(vdi_uuids, list))
+ self.assertEqual(img_id, image_id)
+
+ self.stubs.Set(glance.GlanceStore, 'upload_image',
+ fake_image_upload)
+
self.conn.snapshot(self.context, instance, image_id,
func_call_matcher.call)
@@ -469,6 +483,8 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
name_label = vdi_rec["name_label"]
self.assert_(not name_label.endswith('snapshot'))
+ self.assertTrue(self.fake_upload_called)
+
def create_vm_record(self, conn, os_type, name):
instances = conn.list_instances()
self.assertEquals(instances, [name])
@@ -2574,54 +2590,6 @@ class SwapXapiHostTestCase(test.TestCase):
"http://someserver", 'otherserver'))
-class VmUtilsTestCase(test.TestCase):
- """Unit tests for xenapi utils."""
-
- def test_upload_image(self):
- def fake_instance_system_metadata_get(context, uuid):
- return dict(image_a=1, image_b=2, image_c='c', d='d')
-
- def fake_get_sr_path(session):
- return "foo"
-
- class FakeInstance(dict):
- def __init__(self):
- super(FakeInstance, self).__init__({
- 'auto_disk_config': 'auto disk config',
- 'os_type': 'os type'})
-
- def __missing__(self, item):
- return "whatever"
-
- class FakeSession(object):
- 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
-
- self.stubs.Set(db, "instance_system_metadata_get",
- fake_instance_system_metadata_get)
- self.stubs.Set(vm_utils, "get_sr_path", fake_get_sr_path)
- self.stubs.Set(pickle, "dumps", fake_dumps)
-
- ctx = context.get_admin_context()
-
- instance = FakeInstance()
- session = FakeSession()
- vm_utils.upload_image(ctx, session, instance, "vmi uuids", "image id")
-
- actual = self.kwargs['properties']
- # Inheritance happens in another place, now
- expected = dict(auto_disk_config='auto disk config',
- os_type='os type')
- self.assertEquals(expected, actual)
-
-
class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
"""Unit tests for live_migration."""
def setUp(self):
diff --git a/nova/tests/virt/xenapi/imageupload/__init__.py b/nova/tests/virt/xenapi/imageupload/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/nova/tests/virt/xenapi/imageupload/__init__.py
diff --git a/nova/tests/virt/xenapi/imageupload/test_glance.py b/nova/tests/virt/xenapi/imageupload/test_glance.py
new file mode 100644
index 000000000..b0518228d
--- /dev/null
+++ b/nova/tests/virt/xenapi/imageupload/test_glance.py
@@ -0,0 +1,74 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+import mox
+
+from nova import context
+from nova import test
+from nova.virt.xenapi.imageupload import glance
+from nova.virt.xenapi import vm_utils
+
+
+class TestGlanceStore(test.TestCase):
+ def setUp(self):
+ super(TestGlanceStore, self).setUp()
+ self.store = glance.GlanceStore()
+ self.mox = mox.Mox()
+
+ def tearDown(self):
+ super(TestGlanceStore, self).tearDown()
+
+ def test_upload_image(self):
+ glance_host = '0.1.2.3'
+ glance_port = 8143
+ glance_use_ssl = False
+ sr_path = '/fake/sr/path'
+ self.flags(glance_host=glance_host)
+ self.flags(glance_port=glance_port)
+ self.flags(glance_api_insecure=glance_use_ssl)
+
+ def fake_get_sr_path(*_args, **_kwargs):
+ return sr_path
+
+ self.stubs.Set(vm_utils, 'get_sr_path', fake_get_sr_path)
+
+ ctx = context.RequestContext('user', 'project', auth_token='foobar')
+ properties = {
+ 'auto_disk_config': True,
+ 'os_type': 'default',
+ }
+ image_id = 'fake_image_uuid'
+ vdi_uuids = ['fake_vdi_uuid']
+ instance = {'uuid': 'blah'}
+ instance.update(properties)
+
+ params = {'vdi_uuids': vdi_uuids,
+ 'image_id': image_id,
+ 'glance_host': glance_host,
+ 'glance_port': glance_port,
+ 'glance_use_ssl': glance_use_ssl,
+ 'sr_path': sr_path,
+ 'auth_token': 'foobar',
+ 'properties': properties}
+ session = self.mox.CreateMockAnything()
+ session.call_plugin_serialized('glance', 'upload_vhd', **params)
+ self.mox.ReplayAll()
+
+ self.store.upload_image(ctx, session, instance, vdi_uuids, image_id)
+
+ self.mox.VerifyAll()