Browse Source

Change evacuate test hostnames to preferable ones

The hostname grammar in RFC952 does not allow for underscores in
hostnames. However, some evacuate tests use them in each hostname.
This patch changes them to hyphens instead.

Change-Id: Id961e74a0bbeefbc843678edd74c02466b6d6885
tags/2014.1.b2
Ken'ichi Ohmichi 5 years ago
parent
commit
9888f61128

+ 33
- 11
nova/tests/api/openstack/compute/contrib/test_evacuate.py View File

@@ -47,7 +47,7 @@ def fake_compute_api_get(self, context, instance_id):
47 47
 
48 48
 
49 49
 def fake_service_get_by_compute_host(self, context, host):
50
-    if host == 'bad_host':
50
+    if host == 'bad-host':
51 51
         raise exception.ComputeHostNotFound(host=host)
52 52
     else:
53 53
         return {
@@ -80,7 +80,29 @@ class EvacuateTest(test.NoDBTestCase):
80 80
         req.method = 'POST'
81 81
         req.body = jsonutils.dumps({
82 82
             'evacuate': {
83
-                'host': 'my_host',
83
+                'host': 'my-host',
84
+                'onSharedStorage': 'false',
85
+                'adminPass': 'MyNewPass'
86
+                }
87
+            })
88
+        req.content_type = 'application/json'
89
+        res = req.get_response(app)
90
+        self.assertEqual(res.status_int, 200)
91
+
92
+    def test_evacuate_with_underscore_in_hostname(self):
93
+        ctxt = context.get_admin_context()
94
+        ctxt.user_id = 'fake'
95
+        ctxt.project_id = 'fake'
96
+        ctxt.is_admin = True
97
+        app = fakes.wsgi_app(fake_auth_context=ctxt)
98
+        req = webob.Request.blank('/v2/fake/servers/%s/action' % self.UUID)
99
+        req.method = 'POST'
100
+        req.body = jsonutils.dumps({
101
+            'evacuate': {
102
+                # NOTE: The hostname grammar in RFC952 does not allow for
103
+                # underscores in hostnames. However, we should test that it
104
+                # is supported because it sometimes occurs in real systems.
105
+                'host': 'underscore_hostname',
84 106
                 'onSharedStorage': 'false',
85 107
                 'adminPass': 'MyNewPass'
86 108
                 }
@@ -99,7 +121,7 @@ class EvacuateTest(test.NoDBTestCase):
99 121
         req.method = 'POST'
100 122
         req.body = jsonutils.dumps({
101 123
             'evacuate': {
102
-                'host': 'my_host',
124
+                'host': 'my-host',
103 125
                 'onSharedStorage': 'false',
104 126
                 'adminPass': 'MyNewPass'
105 127
                 }
@@ -119,7 +141,7 @@ class EvacuateTest(test.NoDBTestCase):
119 141
         req.content_type = 'application/json'
120 142
         req.body = jsonutils.dumps({
121 143
             'evacuate': {
122
-                'host': 'my_host',
144
+                'host': 'my-host',
123 145
                 'onSharedStorage': 'false',
124 146
                 'adminPass': 'MyNewPass'
125 147
                 }
@@ -161,7 +183,7 @@ class EvacuateTest(test.NoDBTestCase):
161 183
         req.method = 'POST'
162 184
         req.body = jsonutils.dumps({
163 185
             'evacuate': {
164
-                'host': 'my_host',
186
+                'host': 'my-host',
165 187
                 'adminPass': 'MyNewPass'
166 188
             }
167 189
         })
@@ -179,7 +201,7 @@ class EvacuateTest(test.NoDBTestCase):
179 201
         req.method = 'POST'
180 202
         req.body = jsonutils.dumps({
181 203
             'evacuate': {
182
-                'host': 'bad_host',
204
+                'host': 'bad-host',
183 205
                 'onSharedStorage': 'false',
184 206
                 'adminPass': 'MyNewPass'
185 207
                 }
@@ -199,7 +221,7 @@ class EvacuateTest(test.NoDBTestCase):
199 221
         req.method = 'POST'
200 222
         req.body = jsonutils.dumps({
201 223
             'evacuate': {
202
-                'host': 'my_host',
224
+                'host': 'my-host',
203 225
                 'onSharedStorage': 'false',
204 226
                 'adminPass': 'MyNewPass'
205 227
             }
@@ -228,7 +250,7 @@ class EvacuateTest(test.NoDBTestCase):
228 250
         req.method = 'POST'
229 251
         req.body = jsonutils.dumps({
230 252
             'evacuate': {
231
-                'host': 'my_host',
253
+                'host': 'my-host',
232 254
                 'onSharedStorage': 'True',
233 255
                 'adminPass': 'MyNewPass'
234 256
             }
@@ -255,7 +277,7 @@ class EvacuateTest(test.NoDBTestCase):
255 277
         req.method = 'POST'
256 278
         req.body = jsonutils.dumps({
257 279
             'evacuate': {
258
-                'host': 'my_host',
280
+                'host': 'my-host',
259 281
                 'onSharedStorage': 'False',
260 282
             }
261 283
         })
@@ -284,7 +306,7 @@ class EvacuateTest(test.NoDBTestCase):
284 306
         req.method = 'POST'
285 307
         req.body = jsonutils.dumps({
286 308
             'evacuate': {
287
-                'host': 'my_host',
309
+                'host': 'my-host',
288 310
                 'onSharedStorage': 'True',
289 311
             }
290 312
         })
@@ -307,7 +329,7 @@ class EvacuateTest(test.NoDBTestCase):
307 329
         req.method = 'POST'
308 330
         req.body = jsonutils.dumps({
309 331
             'evacuate': {
310
-                'host': 'my_host',
332
+                'host': 'my-host',
311 333
                 'onSharedStorage': 'True',
312 334
             }
313 335
         })

+ 24
- 9
nova/tests/api/openstack/compute/plugins/v3/test_evacuate.py View File

@@ -43,7 +43,7 @@ def fake_compute_api_get(self, context, instance_id):
43 43
 
44 44
 
45 45
 def fake_service_get_by_compute_host(self, context, host):
46
-    if host == 'bad_host':
46
+    if host == 'bad-host':
47 47
         raise exception.ComputeHostNotFound(host=host)
48 48
     else:
49 49
         return {
@@ -90,13 +90,13 @@ class EvacuateTest(test.NoDBTestCase):
90 90
         self.assertEqual(res.status_int, 400)
91 91
 
92 92
     def test_evacuate_instance_without_on_shared_storage(self):
93
-        req, app = self._gen_request_with_app({'host': 'my_host',
93
+        req, app = self._gen_request_with_app({'host': 'my-host',
94 94
                                                'admin_password': 'MyNewPass'})
95 95
         res = req.get_response(app)
96 96
         self.assertEqual(res.status_int, 400)
97 97
 
98 98
     def test_evacuate_instance_with_bad_host(self):
99
-        req, app = self._gen_request_with_app({'host': 'bad_host',
99
+        req, app = self._gen_request_with_app({'host': 'bad-host',
100 100
                                                'on_shared_storage': 'False',
101 101
                                                'admin_password': 'MyNewPass'})
102 102
 
@@ -104,7 +104,22 @@ class EvacuateTest(test.NoDBTestCase):
104 104
         self.assertEqual(res.status_int, 404)
105 105
 
106 106
     def test_evacuate_instance_with_target(self):
107
-        req, app = self._gen_request_with_app({'host': 'my_host',
107
+        req, app = self._gen_request_with_app({'host': 'my-host',
108
+                                               'on_shared_storage': 'False',
109
+                                               'admin_password': 'MyNewPass'})
110
+
111
+        self.stubs.Set(compute_api.API, 'update', self._fake_update)
112
+
113
+        resp = req.get_response(app)
114
+        self.assertEqual(resp.status_int, 200)
115
+        resp_json = jsonutils.loads(resp.body)
116
+        self.assertEqual("MyNewPass", resp_json['admin_password'])
117
+
118
+    def test_evacuate_instance_with_underscore_in_hostname(self):
119
+        # NOTE: The hostname grammar in RFC952 does not allow for
120
+        # underscores in hostnames. However, we should test that it
121
+        # is supported because it sometimes occurs in real systems.
122
+        req, app = self._gen_request_with_app({'host': 'underscore_hostname',
108 123
                                                'on_shared_storage': 'False',
109 124
                                                'admin_password': 'MyNewPass'})
110 125
 
@@ -116,7 +131,7 @@ class EvacuateTest(test.NoDBTestCase):
116 131
         self.assertEqual("MyNewPass", resp_json['admin_password'])
117 132
 
118 133
     def test_evacuate_shared_and_pass(self):
119
-        req, app = self._gen_request_with_app({'host': 'my_host',
134
+        req, app = self._gen_request_with_app({'host': 'my-host',
120 135
                                                'on_shared_storage': 'True',
121 136
                                                'admin_password': 'MyNewPass'})
122 137
         self.stubs.Set(compute_api.API, 'update', self._fake_update)
@@ -125,7 +140,7 @@ class EvacuateTest(test.NoDBTestCase):
125 140
         self.assertEqual(res.status_int, 400)
126 141
 
127 142
     def test_evacuate_not_shared_pass_generated(self):
128
-        req, app = self._gen_request_with_app({'host': 'my_host',
143
+        req, app = self._gen_request_with_app({'host': 'my-host',
129 144
                                                'on_shared_storage': 'False'})
130 145
 
131 146
         self.stubs.Set(compute_api.API, 'update', self._fake_update)
@@ -137,7 +152,7 @@ class EvacuateTest(test.NoDBTestCase):
137 152
                          len(resp_json['admin_password']))
138 153
 
139 154
     def test_evacuate_shared(self):
140
-        req, app = self._gen_request_with_app({'host': 'my_host',
155
+        req, app = self._gen_request_with_app({'host': 'my-host',
141 156
                                                'on_shared_storage': 'True'})
142 157
         self.stubs.Set(compute_api.API, 'update', self._fake_update)
143 158
 
@@ -147,7 +162,7 @@ class EvacuateTest(test.NoDBTestCase):
147 162
         self.assertIsNone(resp_json['admin_password'])
148 163
 
149 164
     def test_evacuate_with_active_service(self):
150
-        req, app = self._gen_request_with_app({'host': 'my_host',
165
+        req, app = self._gen_request_with_app({'host': 'my-host',
151 166
                                                'on_shared_storage': 'false',
152 167
                                                'admin_password': 'MyNewPass'})
153 168
 
@@ -160,7 +175,7 @@ class EvacuateTest(test.NoDBTestCase):
160 175
         self.assertEqual(res.status_int, 400)
161 176
 
162 177
     def test_not_admin(self):
163
-        req, app = self._gen_request_with_app({'host': 'my_host',
178
+        req, app = self._gen_request_with_app({'host': 'my-host',
164 179
                                                'on_shared_storage': 'True'},
165 180
                                                is_admin=False)
166 181
 

Loading…
Cancel
Save