From 3632173486f89d541c121be8e041a1da636edf32 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Mon, 11 Jan 2016 03:43:09 -0800 Subject: [PATCH] Allow host and instance_uuid at attach 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 | 10 +-------- .../unit/api/contrib/test_volume_actions.py | 21 +++++++++---------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index c6e0c7195ec..225ad5e272d 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -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) diff --git a/cinder/tests/unit/api/contrib/test_volume_actions.py b/cinder/tests/unit/api/contrib/test_volume_actions.py index 5c25c94fceb..99abddf8631 100644 --- a/cinder/tests/unit/api/contrib/test_volume_actions.py +++ b/cinder/tests/unit/api/contrib/test_volume_actions.py @@ -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',