~corey.bryant/cinder/2014.2.2

« back to all changes in this revision

Viewing changes to debian/patches/fix-glance-tests.patch

  • Committer: james.page at ubuntu
  • Date: 2014-10-01 09:00:23 UTC
  • Revision ID: james.page@ubuntu.com-20141001090023-bc2pitk14mta3lav
Tags: 1:2014.2~rc1-0ubuntu1
releasing package cinder version 1:2014.2~rc1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From 04abab869d28e007d9b869122740f70cd839daf7 Mon Sep 17 00:00:00 2001
2
 
From: Rushi Agrawal <rushi.agr@gmail.com>
3
 
Date: Mon, 8 Sep 2014 00:28:57 +0530
4
 
Subject: [PATCH] Mock glance client object in version unit tests
5
 
 
6
 
This patch changes the glance client version unit tests
7
 
to mock the Client object completely.  Previously the
8
 
tests were ensuring the right version of the client was
9
 
returned, but that required too much knowledge of glance's
10
 
implementation and ended up breaking the tests when glance
11
 
changed the implementation details of the Client class.
12
 
 
13
 
The new code tests if cinder is calling the integration
14
 
point correctly for the version, rather than if glance
15
 
is correctly returning the right client; that should be
16
 
a glance test, not a cinder test.
17
 
 
18
 
Closes-Bug: 1366596
19
 
Change-Id: I979175e6c3b5f98076bde6d36ca52fb8b03009b8
20
 
---
21
 
 cinder/tests/image/test_glance.py | 47 +++++++++++----------------------------
22
 
 1 file changed, 13 insertions(+), 34 deletions(-)
23
 
 
24
 
diff --git a/cinder/tests/image/test_glance.py b/cinder/tests/image/test_glance.py
25
 
index c2421dd..b252ac9 100644
26
 
--- a/cinder/tests/image/test_glance.py
27
 
+++ b/cinder/tests/image/test_glance.py
28
 
@@ -17,7 +17,7 @@
29
 
 import datetime
30
 
 
31
 
 import glanceclient.exc
32
 
-from glanceclient.v2 import client as glance_client_v2
33
 
+import mock
34
 
 from oslo.config import cfg
35
 
 
36
 
 from cinder import context
37
 
@@ -588,45 +588,24 @@ def __init__(self, metadata):
38
 
 
39
 
 class TestGlanceClientVersion(test.TestCase):
40
 
     """Tests the version of the glance client generated."""
41
 
-    def setUp(self):
42
 
-        super(TestGlanceClientVersion, self).setUp()
43
 
-
44
 
-        def fake_get_model(self):
45
 
-            return
46
 
-
47
 
-        self.stubs.Set(glance_client_v2.Client, '_get_image_model',
48
 
-                       fake_get_model)
49
 
-
50
 
-        try:
51
 
-            self.stubs.Set(glance_client_v2.Client, '_get_member_model',
52
 
-                           fake_get_model)
53
 
-        except AttributeError:
54
 
-            # method requires stubbing only with newer glanceclients.
55
 
-            pass
56
 
 
57
 
-    def test_glance_version_by_flag(self):
58
 
+    @mock.patch('cinder.image.glance.glanceclient.Client')
59
 
+    def test_glance_version_by_flag(self, _mockglanceclient):
60
 
         """Test glance version set by flag is honoured."""
61
 
-        client_wrapper_v1 = glance.GlanceClientWrapper('fake', 'fake_host',
62
 
-                                                       9292)
63
 
-        self.assertEqual(client_wrapper_v1.client.__module__,
64
 
-                         'glanceclient.v1.client')
65
 
+        glance.GlanceClientWrapper('fake', 'fake_host', 9292)
66
 
+        self.assertEqual('1', _mockglanceclient.call_args[0][0])
67
 
         self.flags(glance_api_version=2)
68
 
-        client_wrapper_v2 = glance.GlanceClientWrapper('fake', 'fake_host',
69
 
-                                                       9292)
70
 
-        self.assertEqual(client_wrapper_v2.client.__module__,
71
 
-                         'glanceclient.v2.client')
72
 
+        glance.GlanceClientWrapper('fake', 'fake_host', 9292)
73
 
+        self.assertEqual('2', _mockglanceclient.call_args[0][0])
74
 
         CONF.reset()
75
 
 
76
 
-    def test_glance_version_by_arg(self):
77
 
+    @mock.patch('cinder.image.glance.glanceclient.Client')
78
 
+    def test_glance_version_by_arg(self, _mockglanceclient):
79
 
         """Test glance version set by arg to GlanceClientWrapper"""
80
 
-        client_wrapper_v1 = glance.GlanceClientWrapper('fake', 'fake_host',
81
 
-                                                       9292, version=1)
82
 
-        self.assertEqual(client_wrapper_v1.client.__module__,
83
 
-                         'glanceclient.v1.client')
84
 
-        client_wrapper_v2 = glance.GlanceClientWrapper('fake', 'fake_host',
85
 
-                                                       9292, version=2)
86
 
-        self.assertEqual(client_wrapper_v2.client.__module__,
87
 
-                         'glanceclient.v2.client')
88
 
+        glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=1)
89
 
+        self.assertEqual('1', _mockglanceclient.call_args[0][0])
90
 
+        glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=2)
91
 
+        self.assertEqual('2', _mockglanceclient.call_args[0][0])
92
 
 
93
 
 
94
 
 def _create_failing_glance_client(info):