summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2011-04-07 13:17:13 -0400
committerTodd Willey <todd@ansolabs.com>2011-04-07 13:17:13 -0400
commitfb31d50e89bec43b6d8490d970f04d6341ef4859 (patch)
tree741ecabf1b145c43b33241abae200df2484e1047 /nova/tests
parent2b79fa82872c55368167fc7433cb28a2369f5191 (diff)
parent7bd99e33796f1e90b6f8b0b9caa122c541f99015 (diff)
Merge trunk.
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_faults.py9
-rw-r--r--nova/tests/api/openstack/test_images.py19
-rw-r--r--nova/tests/api/openstack/test_limits.py16
-rw-r--r--nova/tests/integrated/test_xml.py56
-rw-r--r--nova/tests/test_cloud.py33
5 files changed, 118 insertions, 15 deletions
diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py
index 9746e8168..4d86ffb26 100644
--- a/nova/tests/api/openstack/test_faults.py
+++ b/nova/tests/api/openstack/test_faults.py
@@ -22,6 +22,7 @@ import webob.dec
import webob.exc
from nova import test
+from nova.api.openstack import common
from nova.api.openstack import faults
@@ -47,10 +48,10 @@ class TestFaults(test.TestCase):
response = request.get_response(fault)
expected = self._prepare_xml("""
- <badRequest code="400">
+ <badRequest code="400" xmlns="%s">
<message>scram</message>
</badRequest>
- """)
+ """ % common.XML_NS_V10)
actual = self._prepare_xml(response.body)
self.assertEqual(response.content_type, "application/xml")
@@ -91,11 +92,11 @@ class TestFaults(test.TestCase):
response = request.get_response(fault)
expected = self._prepare_xml("""
- <overLimit code="413">
+ <overLimit code="413" xmlns="%s">
<message>sorry</message>
<retryAfter>4</retryAfter>
</overLimit>
- """)
+ """ % common.XML_NS_V10)
actual = self._prepare_xml(response.body)
self.assertEqual(expected, actual)
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 69cc3116d..ae86d0686 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -146,7 +146,7 @@ class LocalImageServiceTest(_BaseImageServiceTests):
for x in [1, 2, 3]:
tempfile.mkstemp(prefix='ami-', dir=self.tempdir)
# create some valid image directories names
- for x in ["1485baed", "1a60f0ee", "3123a73d"]:
+ for x in ["1485baed", "1a60f0ee", "3123a73d"]:
os.makedirs(os.path.join(self.tempdir, x))
found_image_ids = self.service._ids()
self.assertEqual(True, isinstance(found_image_ids, list))
@@ -335,7 +335,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
name="public image"
updated="%(expected_now)s"
created="%(expected_now)s"
- status="ACTIVE" />
+ status="ACTIVE"
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0" />
""" % (locals()))
self.assertEqual(expected_image.toxml(), actual_image.toxml())
@@ -353,7 +354,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
name="None"
updated="%(expected_now)s"
created="%(expected_now)s"
- status="ACTIVE" />
+ status="ACTIVE"
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0" />
""" % (locals()))
self.assertEqual(expected_image.toxml(), actual_image.toxml())
@@ -372,7 +374,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
name="public image"
updated="%(expected_now)s"
created="%(expected_now)s"
- status="ACTIVE">
+ status="ACTIVE"
+ xmlns="http://docs.openstack.org/compute/api/v1.1">
<links>
<link href="%(expected_href)s" rel="self"/>
<link href="%(expected_href)s" rel="bookmark"
@@ -408,7 +411,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.assertEqual(404, response.status_int)
expected = minidom.parseString("""
- <itemNotFound code="404">
+ <itemNotFound code="404"
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0">
<message>
Image not found.
</message>
@@ -441,8 +445,11 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
response = request.get_response(fakes.wsgi_app())
self.assertEqual(404, response.status_int)
+ # NOTE(justinsb): I believe this should still use the v1.0 XSD,
+ # because the element hasn't changed definition
expected = minidom.parseString("""
- <itemNotFound code="404">
+ <itemNotFound code="404"
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0">
<message>
Image not found.
</message>
diff --git a/nova/tests/api/openstack/test_limits.py b/nova/tests/api/openstack/test_limits.py
index 05cfacc60..df367005d 100644
--- a/nova/tests/api/openstack/test_limits.py
+++ b/nova/tests/api/openstack/test_limits.py
@@ -136,10 +136,17 @@ class LimitsControllerTest(BaseLimitTestSuite):
request = self._get_index_request("application/xml")
response = request.get_response(self.controller)
- expected = "<limits><rate/><absolute/></limits>"
- body = response.body.replace("\n", "").replace(" ", "")
+ expected = parseString("""
+ <limits
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0">
+ <rate/>
+ <absolute/>
+ </limits>
+ """.replace(" ", ""))
- self.assertEqual(expected, body)
+ body = parseString(response.body.replace(" ", ""))
+
+ self.assertEqual(expected.toxml(), body.toxml())
def test_index_xml(self):
"""Test getting limit details in XML."""
@@ -148,7 +155,8 @@ class LimitsControllerTest(BaseLimitTestSuite):
response = request.get_response(self.controller)
expected = parseString("""
- <limits>
+ <limits
+ xmlns="http://docs.rackspacecloud.com/servers/api/v1.0">
<rate>
<limit URI="*" regex=".*" remaining="10" resetTime="0"
unit="MINUTE" value="10" verb="GET"/>
diff --git a/nova/tests/integrated/test_xml.py b/nova/tests/integrated/test_xml.py
new file mode 100644
index 000000000..8a9754777
--- /dev/null
+++ b/nova/tests/integrated/test_xml.py
@@ -0,0 +1,56 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 Justin Santa Barbara
+# 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.
+
+from nova import flags
+from nova.log import logging
+from nova.tests.integrated import integrated_helpers
+from nova.api.openstack import common
+
+
+LOG = logging.getLogger('nova.tests.integrated')
+
+
+FLAGS = flags.FLAGS
+FLAGS.verbose = True
+
+
+class XmlTests(integrated_helpers._IntegratedTestBase):
+ """"Some basic XML sanity checks."""
+
+ def test_namespace_limits(self):
+ """/limits should have v1.0 namespace (hasn't changed in 1.1)."""
+ headers = {}
+ headers['Accept'] = 'application/xml'
+
+ response = self.api.api_request('/limits', headers=headers)
+ data = response.read()
+ LOG.debug("data: %s" % data)
+
+ prefix = '<limits xmlns="%s"' % common.XML_NS_V10
+ self.assertTrue(data.startswith(prefix))
+
+ def test_namespace_servers(self):
+ """/servers should have v1.1 namespace (has changed in 1.1)."""
+ headers = {}
+ headers['Accept'] = 'application/xml'
+
+ response = self.api.api_request('/servers', headers=headers)
+ data = response.read()
+ LOG.debug("data: %s" % data)
+
+ prefix = '<servers xmlns="%s"' % common.XML_NS_V11
+ self.assertTrue(data.startswith(prefix))
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index 00803d0ad..5cb969979 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -41,6 +41,7 @@ from nova.compute import power_state
from nova.api.ec2 import cloud
from nova.api.ec2 import ec2utils
from nova.image import local
+from nova.exception import NotFound
FLAGS = flags.FLAGS
@@ -71,7 +72,8 @@ class CloudTestCase(test.TestCase):
host = self.network.get_network_host(self.context.elevated())
def fake_show(meh, context, id):
- return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
+ return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
+ 'type': 'machine'}}
self.stubs.Set(local.LocalImageService, 'show', fake_show)
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
@@ -216,6 +218,35 @@ class CloudTestCase(test.TestCase):
db.service_destroy(self.context, comp1['id'])
db.service_destroy(self.context, comp2['id'])
+ def test_describe_images(self):
+ describe_images = self.cloud.describe_images
+
+ def fake_detail(meh, context):
+ return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
+ 'type': 'machine'}}]
+
+ def fake_show_none(meh, context, id):
+ raise NotFound
+
+ self.stubs.Set(local.LocalImageService, 'detail', fake_detail)
+ # list all
+ result1 = describe_images(self.context)
+ result1 = result1['imagesSet'][0]
+ self.assertEqual(result1['imageId'], 'ami-00000001')
+ # provided a valid image_id
+ result2 = describe_images(self.context, ['ami-00000001'])
+ self.assertEqual(1, len(result2['imagesSet']))
+ # provide more than 1 valid image_id
+ result3 = describe_images(self.context, ['ami-00000001',
+ 'ami-00000002'])
+ self.assertEqual(2, len(result3['imagesSet']))
+ # provide an non-existing image_id
+ self.stubs.UnsetAll()
+ self.stubs.Set(local.LocalImageService, 'show', fake_show_none)
+ self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show_none)
+ self.assertRaises(NotFound, describe_images,
+ self.context, ['ami-fake'])
+
def test_console_output(self):
instance_type = FLAGS.default_instance_type
max_count = 1