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
This commit is contained in:
Walter A. Boring IV 2016-01-11 03:43:09 -08:00
parent 81f7986c16
commit 3632173486
2 changed files with 11 additions and 20 deletions

View 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)

View 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',