Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > 5c655bb31b7eacedb96e8b5da992c6ce > files > 9

openstack-nova-2011.3.1-11.fc16.src.rpm

From 947a25b6e906e6894cb61e243169e5f67e729e2b Mon Sep 17 00:00:00 2001
From: Mike Lundy <mike@pistoncloud.com>
Date: Mon, 24 Oct 2011 20:05:19 -0700
Subject: [PATCH] Fix undefined glance_host in get_glance_client

get_glance_client is stubbed in the tests, so they didn't catch it.
Added tests to catch it.

This is related to bug 883328.

Also, add myself to Authors file.

[Backported from
7a5b8822791dc9af0afe7166af34c6fb5277f81c and
c7532c62ea6afb4bfcf3d00e42a58cc72b12405b]

Change-Id: Idbe6c06c22ca1a50df589e016ea5e5924b0cc29d
---
 Authors                         |    1 +
 nova/image/glance.py            |    6 ++++--
 nova/tests/image/test_glance.py |   26 ++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/Authors b/Authors
index eddf0e6..97fd649 100644
--- a/Authors
+++ b/Authors
@@ -92,6 +92,7 @@ Masanori Itoh <itoumsn@nttdata.co.jp>
 Matt Dietz <matt.dietz@rackspace.com>
 Matthew Hooker <matt@cloudscaling.com>
 Michael Gundlach <michael.gundlach@rackspace.com>
+Mike Lundy <mike@pistoncloud.com>
 Mike Scherbakov <mihgen@gmail.com>
 Mohammed Naser <mnaser@vexxhost.com>
 Monsyne Dragon <mdragon@rackspace.com>
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 5906634..1d96167 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -107,10 +107,12 @@ def get_glance_client(context, image_href):
         return (glance_client, int(image_href))
 
     try:
-        (image_id, host, port) = _parse_image_ref(image_href)
+        (image_id, glance_host, glance_port) = _parse_image_ref(image_href)
+        glance_client = _create_glance_client(context,
+                                              glance_host,
+                                              glance_port)
     except ValueError:
         raise exception.InvalidImageRef(image_href=image_href)
-    glance_client = _create_glance_client(context, glance_host, glance_port)
     return (glance_client, image_id)
 
 
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index b1ebd84..d30aba4 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -141,6 +141,32 @@ class TestGlanceImageServiceProperties(BaseGlanceTest):
                     'properties': {'prop1': 'propvalue1', 'foo': 'bar'}}]
         self.assertEqual(image_meta, expected)
 
+    def test_glance_client_image_id(self):
+        fixtures = {'image1': {'id': '1', 'name': 'image1', 'is_public': True,
+                               'foo': 'bar',
+                               'properties': {'prop1': 'propvalue1'}}}
+        self.client.images = fixtures
+        client, same_id = glance.get_glance_client(self.context, 1)
+        self.assertEquals(same_id, 1)
+
+    def test_glance_client_image_ref(self):
+        fixtures = {'image1': {'id': '1', 'name': 'image1', 'is_public': True,
+                               'foo': 'bar',
+                               'properties': {'prop1': 'propvalue1'}}}
+        self.client.images = fixtures
+        image_url = 'http://something-less-likely/1'
+        client, same_id = glance.get_glance_client(self.context, image_url)
+        self.assertEquals(same_id, 1)
+        self.assertEquals(client.host, 'something-less-likely')
+
+    def test_glance_client_invalid_image_ref(self):
+        fixtures = {'image1': {'id': '1', 'name': 'image1', 'is_public': True,
+                               'foo': 'bar',
+                               'properties': {'prop1': 'propvalue1'}}}
+        self.client.images = fixtures
+        self.assertRaises(exception.InvalidImageRef, glance.get_glance_client,
+                self.context, 'khan')
+
 
 class TestGetterDateTimeNoneTests(BaseGlanceTest):