]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow host and instance_uuid at attach
authorWalter A. Boring IV <walter.boring@hpe.com>
Mon, 11 Jan 2016 11:43:09 +0000 (03:43 -0800)
committerWalter A. Boring IV <walter.boring@hpe.com>
Mon, 11 Jan 2016 11:43:09 +0000 (03:43 -0800)
This patch removes the restriction on passing both
host name and instance_uuid during os-attach call.

Change-Id: I2a66920a76d3abfd6da384d2dd963f054ce61c03
Partial-Bug: #1471278

cinder/api/contrib/volume_actions.py
cinder/tests/unit/api/contrib/test_volume_actions.py

index c6e0c7195ec09b6211b4e5b2c2f50ac7bfe48b05..225ad5e272d7978f1e4d9be863b7fa6b33679a3b 100644 (file)
@@ -98,15 +98,7 @@ class VolumeActionsController(wsgi.Controller):
         else:
             mode = 'rw'
 
-        if instance_uuid and host_name:
-            msg = _("Invalid request to attach volume to an "
-                    "instance %(instance_uuid)s and a "
-                    "host %(host_name)s simultaneously") % {
-                'instance_uuid': instance_uuid,
-                'host_name': host_name,
-            }
-            raise webob.exc.HTTPBadRequest(explanation=msg)
-        elif instance_uuid is None and host_name is None:
+        if instance_uuid is None and host_name is None:
             msg = _("Invalid request to attach volume to an invalid target")
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
index 5c25c94fceb09789cc5a8faef0ae52745780c336..99abddf8631c537c6315e90b20955ffe48006b19 100644 (file)
@@ -179,6 +179,16 @@ class VolumeActionsTest(test.TestCase):
         res = req.get_response(fakes.wsgi_app())
         self.assertEqual(202, res.status_int)
 
+        body = {'os-attach': {'instance_uuid': 'fake',
+                              'host_name': 'fake_host',
+                              'mountpoint': '/dev/vdc'}}
+        req = webob.Request.blank('/v2/fake/volumes/1/action')
+        req.method = "POST"
+        req.headers["content-type"] = "application/json"
+        req.body = jsonutils.dumps(body)
+        res = req.get_response(fakes.wsgi_app())
+        self.assertEqual(202, res.status_int)
+
     def test_attach_to_host(self):
         # using 'read-write' mode attach volume by default
         body = {'os-attach': {'host_name': 'fake_host',
@@ -277,17 +287,6 @@ class VolumeActionsTest(test.TestCase):
         res = req.get_response(fakes.wsgi_app())
         self.assertEqual(400, res.status_int)
 
-        # Invalid request to attach volume to an instance and a host
-        body = {'os-attach': {'instance_uuid': 'fake',
-                              'host_name': 'fake_host',
-                              'mountpoint': '/dev/vdc'}}
-        req = webob.Request.blank('/v2/fake/volumes/1/action')
-        req.method = "POST"
-        req.headers["content-type"] = "application/json"
-        req.body = jsonutils.dumps(body)
-        res = req.get_response(fakes.wsgi_app())
-        self.assertEqual(400, res.status_int)
-
         # Invalid request to attach volume with an invalid mode
         body = {'os-attach': {'instance_uuid': 'fake',
                               'mountpoint': '/dev/vdc',