]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Merge "Handle terminate_connection() exception in volume manager"
authorJenkins <jenkins@review.openstack.org>
Sun, 29 Dec 2013 09:38:37 +0000 (09:38 +0000)
committerGerrit Code Review <review@openstack.org>
Sun, 29 Dec 2013 09:38:37 +0000 (09:38 +0000)
1  2 
cinder/api/contrib/volume_actions.py
cinder/tests/api/contrib/test_volume_actions.py
cinder/volume/manager.py

Simple merge
index 82f4e126d2caa7078ed9b410a941fe9741675543,e13c5435f5f86c3b00306480ab5ef9b39d1ebb2a..1a70daffd2a017c63594bbf492bde922c7c06155
@@@ -67,74 -67,74 +67,84 @@@ class VolumeActionsTest(test.TestCase)
              self.assertEqual(res.status_int, 202)
  
      def test_initialize_connection(self):
 -        def fake_initialize_connection(*args, **kwargs):
 -            return {}
 -        self.stubs.Set(volume.API, 'initialize_connection',
 -                       fake_initialize_connection)
 -
 -        body = {'os-initialize_connection': {'connector': 'fake'}}
 -        req = webob.Request.blank('/v2/fake/volumes/1/action')
 -        req.method = "POST"
 -        req.body = jsonutils.dumps(body)
 -        req.headers["content-type"] = "application/json"
 +        with mock.patch.object(volume_api.API,
 +                               'initialize_connection') as init_conn:
 +            init_conn.return_value = {}
 +            body = {'os-initialize_connection': {'connector': 'fake'}}
 +            req = webob.Request.blank('/v2/fake/volumes/1/action')
 +            req.method = "POST"
 +            req.body = jsonutils.dumps(body)
 +            req.headers["content-type"] = "application/json"
  
 -        res = req.get_response(fakes.wsgi_app())
 -        self.assertEqual(res.status_int, 200)
 +            res = req.get_response(fakes.wsgi_app())
 +            self.assertEqual(res.status_int, 200)
  
      def test_initialize_connection_without_connector(self):
 -        def fake_initialize_connection(*args, **kwargs):
 -            return {}
 -        self.stubs.Set(volume.API, 'initialize_connection',
 -                       fake_initialize_connection)
 -
 -        body = {'os-initialize_connection': {}}
 -        req = webob.Request.blank('/v2/fake/volumes/1/action')
 -        req.method = "POST"
 -        req.body = jsonutils.dumps(body)
 -        req.headers["content-type"] = "application/json"
 -
 -        res = req.get_response(fakes.wsgi_app())
 -        self.assertEqual(res.status_int, 400)
 +        with mock.patch.object(volume_api.API,
 +                               'initialize_connection') as init_conn:
 +            init_conn.return_value = {}
 +            body = {'os-initialize_connection': {}}
 +            req = webob.Request.blank('/v2/fake/volumes/1/action')
 +            req.method = "POST"
 +            req.body = jsonutils.dumps(body)
 +            req.headers["content-type"] = "application/json"
 +
 +            res = req.get_response(fakes.wsgi_app())
 +            self.assertEqual(res.status_int, 400)
 +
 +    def test_initialize_connection_exception(self):
 +        with mock.patch.object(volume_api.API,
 +                               'initialize_connection') as init_conn:
 +            init_conn.side_effect = \
 +                exception.VolumeBackendAPIException(data=None)
 +            body = {'os-initialize_connection': {'connector': 'fake'}}
 +            req = webob.Request.blank('/v2/fake/volumes/1/action')
 +            req.method = "POST"
 +            req.body = jsonutils.dumps(body)
 +            req.headers["content-type"] = "application/json"
 +
 +            res = req.get_response(fakes.wsgi_app())
 +            self.assertEqual(res.status_int, 500)
  
      def test_terminate_connection(self):
-         def fake_terminate_connection(*args, **kwargs):
-             return {}
-         self.stubs.Set(volume.API, 'terminate_connection',
-                        fake_terminate_connection)
-         body = {'os-terminate_connection': {'connector': 'fake'}}
-         req = webob.Request.blank('/v2/fake/volumes/1/action')
-         req.method = "POST"
-         req.body = jsonutils.dumps(body)
-         req.headers["content-type"] = "application/json"
+         with mock.patch.object(volume_api.API,
+                                'terminate_connection') as terminate_conn:
+             terminate_conn.return_value = {}
+             body = {'os-terminate_connection': {'connector': 'fake'}}
+             req = webob.Request.blank('/v2/fake/volumes/1/action')
+             req.method = "POST"
+             req.body = jsonutils.dumps(body)
+             req.headers["content-type"] = "application/json"
  
-         res = req.get_response(fakes.wsgi_app())
-         self.assertEqual(res.status_int, 202)
+             res = req.get_response(fakes.wsgi_app())
+             self.assertEqual(res.status_int, 202)
  
      def test_terminate_connection_without_connector(self):
-         def fake_terminate_connection(*args, **kwargs):
-             return {}
-         self.stubs.Set(volume.API, 'terminate_connection',
-                        fake_terminate_connection)
+         with mock.patch.object(volume_api.API,
+                                'terminate_connection') as terminate_conn:
+             terminate_conn.return_value = {}
+             body = {'os-terminate_connection': {}}
+             req = webob.Request.blank('/v2/fake/volumes/1/action')
+             req.method = "POST"
+             req.body = jsonutils.dumps(body)
+             req.headers["content-type"] = "application/json"
  
-         body = {'os-terminate_connection': {}}
-         req = webob.Request.blank('/v2/fake/volumes/1/action')
-         req.method = "POST"
-         req.body = jsonutils.dumps(body)
-         req.headers["content-type"] = "application/json"
+             res = req.get_response(fakes.wsgi_app())
+             self.assertEqual(res.status_int, 400)
  
-         res = req.get_response(fakes.wsgi_app())
-         self.assertEqual(res.status_int, 400)
+     def test_terminate_connection_with_exception(self):
+         with mock.patch.object(volume_api.API,
+                                'terminate_connection') as terminate_conn:
+             terminate_conn.side_effect = \
+                 exception.VolumeBackendAPIException(data=None)
+             body = {'os-terminate_connection': {'connector': 'fake'}}
+             req = webob.Request.blank('/v2/fake/volumes/1/action')
+             req.method = "POST"
+             req.body = jsonutils.dumps(body)
+             req.headers["content-type"] = "application/json"
+             res = req.get_response(fakes.wsgi_app())
+             self.assertEqual(res.status_int, 500)
  
      def test_attach_to_instance(self):
          body = {'os-attach': {'instance_uuid': 'fake',
Simple merge