summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-09-20 15:21:06 -0500
committerJosh Kearney <josh@jk0.org>2011-09-20 15:21:06 -0500
commitc07b24cdd6606950b0a4fef730c277b499eb65f4 (patch)
treecad418eadab027ee2285840233f62b58cb2d8b46
parent13e346df0bc88279242ed1c56ad39b36a22c8a39 (diff)
downloadnova-c07b24cdd6606950b0a4fef730c277b499eb65f4.tar.gz
nova-c07b24cdd6606950b0a4fef730c277b499eb65f4.tar.xz
nova-c07b24cdd6606950b0a4fef730c277b499eb65f4.zip
Fixed unit tests with some minor refactoring.
-rw-r--r--nova/api/openstack/views/images.py13
-rw-r--r--nova/tests/api/openstack/test_images.py102
-rw-r--r--nova/utils.py7
3 files changed, 108 insertions, 14 deletions
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py
index c41123f5e..659bfd463 100644
--- a/nova/api/openstack/views/images.py
+++ b/nova/api/openstack/views/images.py
@@ -18,10 +18,7 @@
import os.path
from nova.api.openstack import common
-from nova import flags
-
-
-FLAGS = flags.FLAGS
+from nova import utils
class ViewBuilder(object):
@@ -174,7 +171,7 @@ class ViewBuilderV11(ViewBuilder):
def generate_alternate(self, image_id):
"""Create an alternate link for a specific flavor id."""
- # TODO(jk0): This will eventually need to take SSL into consideration
- # when supported in glance.
- return "http://%s:%d/%s/images/%s" % (FLAGS.glance_host,
- FLAGS.glance_port, self.project_id, str(image_id))
+ glance_url = utils.generate_glance_url()
+
+ return "%s/%s/images/%s" % (glance_url, self.project_id,
+ str(image_id))
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 7053db37d..c0a246a91 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -30,18 +30,15 @@ import stubout
import webob
from nova import context
-from nova import flags
import nova.api.openstack
from nova.api.openstack import images
from nova.api.openstack import xmlutil
from nova.api.openstack.views import images as images_view
from nova import test
+from nova import utils
from nova.tests.api.openstack import fakes
-FLAGS = flags.FLAGS
-
-
NS = "{http://docs.openstack.org/compute/api/v1.1}"
ATOMNS = "{http://www.w3.org/2005/Atom}"
NOW_API_FORMAT = "2010-10-11T10:30:22Z"
@@ -124,6 +121,7 @@ class ImagesTest(test.TestCase):
href = "http://localhost/v1.1/fake/images/124"
bookmark = "http://localhost/fake/images/124"
+ alternate = "%s/fake/images/124" % utils.generate_glance_url()
server_href = "http://localhost/v1.1/servers/42"
server_bookmark = "http://localhost/servers/42"
@@ -157,6 +155,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": bookmark,
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": alternate
}],
},
}
@@ -294,6 +297,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/123",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/123" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -308,6 +317,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/124",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/124" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -322,6 +337,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/125",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/125" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -336,6 +357,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/126",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/126" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -350,6 +377,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/127",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/127" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -364,6 +397,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/128",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/128" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -378,6 +417,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/129",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/129" %
+ utils.generate_glance_url()
+ },
],
},
{
@@ -392,6 +437,12 @@ class ImagesTest(test.TestCase):
"rel": "bookmark",
"href": "http://localhost/fake/images/130",
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/130" %
+ utils.generate_glance_url()
+ },
],
},
]
@@ -498,6 +549,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/123",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/123" % utils.generate_glance_url()
}],
},
{
@@ -529,6 +585,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/124",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/124" % utils.generate_glance_url()
}],
},
{
@@ -560,6 +621,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/125",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/125" % utils.generate_glance_url()
}],
},
{
@@ -591,6 +657,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/126",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/126" % utils.generate_glance_url()
}],
},
{
@@ -622,6 +693,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/127",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/127" % utils.generate_glance_url()
}],
},
{
@@ -653,6 +729,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/128",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/128" % utils.generate_glance_url()
}],
},
{
@@ -684,6 +765,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/129",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/129" % utils.generate_glance_url()
}],
},
{
@@ -701,6 +787,11 @@ class ImagesTest(test.TestCase):
{
"rel": "bookmark",
"href": "http://localhost/fake/images/130",
+ },
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": "%s/fake/images/130" % utils.generate_glance_url()
}],
},
]
@@ -973,8 +1064,7 @@ class ImagesTest(test.TestCase):
# when supported in glance.
view = images_view.ViewBuilderV11(1)
generated_url = view.generate_alternate(1)
- actual_url = "http://%s:%d//images/1" % (FLAGS.glance_host,
- FLAGS.glance_port)
+ actual_url = "%s//images/1" % utils.generate_glance_url()
self.assertEqual(generated_url, actual_url)
diff --git a/nova/utils.py b/nova/utils.py
index 81157a4cd..57c93d9d0 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -910,3 +910,10 @@ def convert_to_list_dict(lst, label):
if not isinstance(lst, list):
lst = [lst]
return [{label: x} for x in lst]
+
+
+def generate_glance_url():
+ """Generate the URL to glance."""
+ # TODO(jk0): This will eventually need to take SSL into consideration
+ # when supported in glance.
+ return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)