Fix v3 swap volume with wrong signature
Fix bug 1219672 Fix the signature and add related integrated test. And fix test_servers missing subs 'glance_host'. Change-Id: I040dafe2c1bcfc014fdeba3f735b322908af96c0
This commit is contained in:
parent
2e359c3f2a
commit
764860a029
16
doc/v3/api_samples/os-extended-volumes/server-post-req.json
Normal file
16
doc/v3/api_samples/os-extended-volumes/server-post-req.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"server" : {
|
||||||
|
"name" : "new-server-test",
|
||||||
|
"image_ref" : "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
|
||||||
|
"flavor_ref" : "http://openstack.example.com/flavors/1",
|
||||||
|
"metadata" : {
|
||||||
|
"My Server Name" : "Apache1"
|
||||||
|
},
|
||||||
|
"personality" : [
|
||||||
|
{
|
||||||
|
"path" : "/etc/banner.txt",
|
||||||
|
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
19
doc/v3/api_samples/os-extended-volumes/server-post-req.xml
Normal file
19
doc/v3/api_samples/os-extended-volumes/server-post-req.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<server xmlns="http://docs.openstack.org/compute/api/v1.1" image_ref="http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b" flavor_ref="http://openstack.example.com/flavors/1" name="new-server-test">
|
||||||
|
<metadata>
|
||||||
|
<meta key="My Server Name">Apache1</meta>
|
||||||
|
</metadata>
|
||||||
|
<personality>
|
||||||
|
<file path="/etc/banner.txt">
|
||||||
|
ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp
|
||||||
|
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k
|
||||||
|
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs
|
||||||
|
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g
|
||||||
|
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo
|
||||||
|
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv
|
||||||
|
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy
|
||||||
|
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6
|
||||||
|
b25zLiINCg0KLVJpY2hhcmQgQmFjaA==
|
||||||
|
</file>
|
||||||
|
</personality>
|
||||||
|
</server>
|
16
doc/v3/api_samples/os-extended-volumes/server-post-resp.json
Normal file
16
doc/v3/api_samples/os-extended-volumes/server-post-resp.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"admin_pass": "wCGJKvs9RApD",
|
||||||
|
"id": "c43b584c-86ac-438c-aa9d-70aac14c2b27",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"href": "http://openstack.example.com/v3/servers/c43b584c-86ac-438c-aa9d-70aac14c2b27",
|
||||||
|
"rel": "self"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"href": "http://openstack.example.com/servers/c43b584c-86ac-438c-aa9d-70aac14c2b27",
|
||||||
|
"rel": "bookmark"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="4c256475-e5c7-4d1a-aafe-80992cc742ba" admin_pass="uRZ58nFyiwMn">
|
||||||
|
<metadata/>
|
||||||
|
<atom:link href="http://openstack.example.com/v3/servers/4c256475-e5c7-4d1a-aafe-80992cc742ba" rel="self"/>
|
||||||
|
<atom:link href="http://openstack.example.com/servers/4c256475-e5c7-4d1a-aafe-80992cc742ba" rel="bookmark"/>
|
||||||
|
</server>
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"swap": {
|
||||||
|
"old_volume_id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
|
||||||
|
"new_volume_id": "a26887c6-c47b-4654-abb5-dfadf7d3f804"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<swap old_volume_id="a26887c6-c47b-4654-abb5-dfadf7d3f803" new_volume_id="a26887c6-c47b-4654-abb5-dfadf7d3f804" />
|
@ -54,7 +54,7 @@ class ExtendedVolumesController(wsgi.Controller):
|
|||||||
|
|
||||||
@extensions.expected_errors((400, 404, 409))
|
@extensions.expected_errors((400, 404, 409))
|
||||||
@wsgi.action('swap_volume_attachment')
|
@wsgi.action('swap_volume_attachment')
|
||||||
def swap(self, req, server_id, body):
|
def swap(self, req, id, body):
|
||||||
context = req.environ['nova.context']
|
context = req.environ['nova.context']
|
||||||
authorize_swap(context)
|
authorize_swap(context)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ExtendedVolumesController(wsgi.Controller):
|
|||||||
raise exc.HTTPBadRequest("The request body is invalid")
|
raise exc.HTTPBadRequest("The request body is invalid")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
instance = self.compute_api.get(context, server_id,
|
instance = self.compute_api.get(context, id,
|
||||||
want_objects=True)
|
want_objects=True)
|
||||||
except exception.InstanceNotFound as e:
|
except exception.InstanceNotFound as e:
|
||||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"server" : {
|
||||||
|
"name" : "new-server-test",
|
||||||
|
"image_ref" : "%(glance_host)s/images/%(image_id)s",
|
||||||
|
"flavor_ref" : "%(host)s/flavors/1",
|
||||||
|
"metadata" : {
|
||||||
|
"My Server Name" : "Apache1"
|
||||||
|
},
|
||||||
|
"personality" : [
|
||||||
|
{
|
||||||
|
"path" : "/etc/banner.txt",
|
||||||
|
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<server xmlns="http://docs.openstack.org/compute/api/v1.1" image_ref="%(glance_host)s/images/%(image_id)s" flavor_ref="%(host)s/flavors/1" name="new-server-test">
|
||||||
|
<metadata>
|
||||||
|
<meta key="My Server Name">Apache1</meta>
|
||||||
|
</metadata>
|
||||||
|
<personality>
|
||||||
|
<file path="/etc/banner.txt">
|
||||||
|
ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp
|
||||||
|
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k
|
||||||
|
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs
|
||||||
|
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g
|
||||||
|
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo
|
||||||
|
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv
|
||||||
|
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy
|
||||||
|
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6
|
||||||
|
b25zLiINCg0KLVJpY2hhcmQgQmFjaA==
|
||||||
|
</file>
|
||||||
|
</personality>
|
||||||
|
</server>
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"admin_pass": "%(password)s",
|
||||||
|
"id": "%(id)s",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"href": "%(host)s/v3/servers/%(uuid)s",
|
||||||
|
"rel": "self"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"href": "%(host)s/servers/%(uuid)s",
|
||||||
|
"rel": "bookmark"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="%(id)s" admin_pass="%(password)s">
|
||||||
|
<metadata/>
|
||||||
|
<atom:link href="%(host)s/v3/servers/%(uuid)s" rel="self"/>
|
||||||
|
<atom:link href="%(host)s/servers/%(uuid)s" rel="bookmark"/>
|
||||||
|
</server>
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"swap_volume_attachment": {
|
||||||
|
"old_volume_id": "%(old_volume_id)s",
|
||||||
|
"new_volume_id": "%(new_volume_id)s"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<swap_volume_attachment old_volume_id="%(old_volume_id)s" new_volume_id="%(new_volume_id)s" />
|
74
nova/tests/integrated/v3/test_extended_volumes.py
Normal file
74
nova/tests/integrated/v3/test_extended_volumes.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
# Copyright 2012 Nebula, Inc.
|
||||||
|
# Copyright 2013 IBM Corp.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from nova.compute import api as compute_api
|
||||||
|
from nova.compute import manager as compute_manager
|
||||||
|
from nova.tests.api.openstack import fakes
|
||||||
|
from nova.tests.integrated.v3 import test_servers
|
||||||
|
from nova.volume import cinder
|
||||||
|
|
||||||
|
|
||||||
|
class ExtendedVolumesSampleJsonTests(test_servers.ServersSampleBase):
|
||||||
|
extension_name = "os-extended-volumes"
|
||||||
|
|
||||||
|
def _stub_compute_api_get_instance_bdms(self, server_id):
|
||||||
|
|
||||||
|
def fake_compute_api_get_instance_bdms(self, context, instance):
|
||||||
|
bdms = [
|
||||||
|
{'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f803',
|
||||||
|
'instance_uuid': server_id,
|
||||||
|
'device_name': '/dev/sdd'},
|
||||||
|
{'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f804',
|
||||||
|
'instance_uuid': server_id,
|
||||||
|
'device_name': '/dev/sdc'}
|
||||||
|
]
|
||||||
|
return bdms
|
||||||
|
|
||||||
|
self.stubs.Set(compute_api.API, "get_instance_bdms",
|
||||||
|
fake_compute_api_get_instance_bdms)
|
||||||
|
|
||||||
|
def test_swap_volume(self):
|
||||||
|
server_id = self._post_server()
|
||||||
|
old_volume_id = "a26887c6-c47b-4654-abb5-dfadf7d3f803"
|
||||||
|
old_new_volume = 'a26887c6-c47b-4654-abb5-dfadf7d3f805'
|
||||||
|
self._stub_compute_api_get_instance_bdms(server_id)
|
||||||
|
|
||||||
|
def stub_volume_get(self, context, volume_id):
|
||||||
|
if volume_id == old_volume_id:
|
||||||
|
return fakes.stub_volume(volume_id, instance_uuid=server_id)
|
||||||
|
else:
|
||||||
|
return fakes.stub_volume(volume_id, instance_uuid=None,
|
||||||
|
attach_status='detached')
|
||||||
|
|
||||||
|
self.stubs.Set(cinder.API, 'get', stub_volume_get)
|
||||||
|
self.stubs.Set(cinder.API, 'begin_detaching', lambda *a, **k: None)
|
||||||
|
self.stubs.Set(cinder.API, 'check_attach', lambda *a, **k: None)
|
||||||
|
self.stubs.Set(cinder.API, 'check_detach', lambda *a, **k: None)
|
||||||
|
self.stubs.Set(cinder.API, 'reserve_volume', lambda *a, **k: None)
|
||||||
|
self.stubs.Set(compute_manager.ComputeManager, 'swap_volume',
|
||||||
|
lambda *a, **k: None)
|
||||||
|
subs = {
|
||||||
|
'old_volume_id': old_volume_id,
|
||||||
|
'new_volume_id': old_new_volume
|
||||||
|
}
|
||||||
|
response = self._do_post('servers/%s/action' % server_id,
|
||||||
|
'swap-volume-req', subs)
|
||||||
|
self.assertEqual(response.status, 202)
|
||||||
|
self.assertEqual(response.read(), '')
|
||||||
|
|
||||||
|
|
||||||
|
class ExtendedVolumesSampleXmlTests(ExtendedVolumesSampleJsonTests):
|
||||||
|
ctype = 'xml'
|
@ -23,6 +23,7 @@ class ServersSampleBase(api_sample_base.ApiSampleTestBaseV3):
|
|||||||
subs = {
|
subs = {
|
||||||
'image_id': fake.get_valid_image_id(),
|
'image_id': fake.get_valid_image_id(),
|
||||||
'host': self._get_host(),
|
'host': self._get_host(),
|
||||||
|
'glance_host': self._get_glance_host()
|
||||||
}
|
}
|
||||||
response = self._do_post('servers', 'server-post-req', subs)
|
response = self._do_post('servers', 'server-post-req', subs)
|
||||||
subs = self._get_regexes()
|
subs = self._get_regexes()
|
||||||
|
Loading…
Reference in New Issue
Block a user