Cinder REST API test: Make list_extensions test work properly
Previously cinder list_extensions test was disabled (by starting the test name with an underscore) and REST API for cinder extensions did not work properly. This commit fixes the REST API and corresponding unit test. To make it easy to write the test, test data for list_extensions response of cinder v2 API is also added. Related-Bug: #1752917 Change-Id: I5ac014d62462529e186e9dde3842c6a8a629f1c4
This commit is contained in:
parent
64d5ba8515
commit
196ce77141
@ -289,7 +289,6 @@ class Extensions(generic.View):
|
||||
'description': e.description,
|
||||
'links': e.links,
|
||||
'name': e.name,
|
||||
'namespace': e.namespace,
|
||||
'updated': e.updated
|
||||
|
||||
} for e in result]}
|
||||
|
@ -15,6 +15,7 @@
|
||||
from cinderclient.v2 import availability_zones
|
||||
from cinderclient.v2 import cgsnapshots
|
||||
from cinderclient.v2 import consistencygroups
|
||||
from cinderclient.v2.contrib import list_extensions as cinder_list_extensions
|
||||
from cinderclient.v2 import pools
|
||||
from cinderclient.v2 import qos_specs
|
||||
from cinderclient.v2 import quotas
|
||||
@ -45,6 +46,7 @@ def data(TEST):
|
||||
TEST.cinder_qos_specs = utils.TestDataContainer()
|
||||
TEST.cinder_qos_spec_associations = utils.TestDataContainer()
|
||||
TEST.cinder_volume_snapshots = utils.TestDataContainer()
|
||||
TEST.cinder_extensions = utils.TestDataContainer()
|
||||
TEST.cinder_quotas = utils.TestDataContainer()
|
||||
TEST.cinder_quota_usages = utils.TestDataContainer()
|
||||
TEST.cinder_availability_zones = utils.TestDataContainer()
|
||||
@ -297,6 +299,32 @@ def data(TEST):
|
||||
TEST.cinder_volume_encryption.add(vol_enc_metadata1)
|
||||
TEST.cinder_volume_encryption.add(vol_unenc_metadata1)
|
||||
|
||||
# v2 extensions
|
||||
|
||||
extensions = [
|
||||
{'alias': 'os-services',
|
||||
'description': 'Services support.',
|
||||
'links': '[]',
|
||||
'name': 'Services',
|
||||
'updated': '2012-10-28T00:00:00-00:00'},
|
||||
{'alias': 'os-admin-actions',
|
||||
'description': 'Enable admin actions.',
|
||||
'links': '[]',
|
||||
'name': 'AdminActions',
|
||||
'updated': '2012-08-25T00:00:00+00:00'},
|
||||
{'alias': 'os-volume-transfer',
|
||||
'description': 'Volume transfer management support.',
|
||||
'links': '[]',
|
||||
'name': 'VolumeTransfer',
|
||||
'updated': '2013-05-29T00:00:00+00:00'},
|
||||
]
|
||||
extensions = [
|
||||
cinder_list_extensions.ListExtResource(
|
||||
cinder_list_extensions.ListExtManager(None), ext)
|
||||
for ext in extensions
|
||||
]
|
||||
TEST.cinder_extensions.add(*extensions)
|
||||
|
||||
# Quota Sets
|
||||
quota_data = dict(volumes='1',
|
||||
snapshots='1',
|
||||
|
@ -12,9 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from django.conf import settings
|
||||
import mock
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.api.base import Quota
|
||||
from openstack_dashboard.api.cinder import VolTypeExtraSpec
|
||||
@ -266,23 +263,17 @@ class CinderRestTestCase(test.TestCase):
|
||||
#
|
||||
# Extensions
|
||||
#
|
||||
# TODO(amotoki): This is actually not tested. Make this work.
|
||||
# TODO(amotoki): There is no such setting named
|
||||
# OPENSTACK_CINDER_EXTENSIONS_BLACKLIST.
|
||||
@test.create_mocks({api.cinder: ['list_extensions']})
|
||||
@mock.patch.object(settings,
|
||||
'OPENSTACK_CINDER_EXTENSIONS_BLACKLIST', ['baz'])
|
||||
def _test_extension_list(self):
|
||||
def test_extension_list(self):
|
||||
request = self.mock_rest_request()
|
||||
self.mock_list_extensions.return_value = [
|
||||
mock.Mock(**{'to_dict.return_value': {'name': 'foo'}}),
|
||||
mock.Mock(**{'to_dict.return_value': {'name': 'bar'}}),
|
||||
mock.Mock(**{'to_dict.return_value': {'name': 'baz'}}),
|
||||
]
|
||||
exts = tuple(self.cinder_extensions.list())
|
||||
self.mock_list_extensions.return_value = exts
|
||||
|
||||
response = cinder.Extensions().get(request)
|
||||
|
||||
self.assertStatusCode(response, 200)
|
||||
self.assertEqual(response.content,
|
||||
'{"items": [{"name": "foo"}, {"name": "bar"}]}')
|
||||
self.assertEqual([ext.to_dict() for ext in exts],
|
||||
response.json['items'])
|
||||
self.mock_list_extensions.assert_called_once_with(request)
|
||||
|
||||
@test.create_mocks({api.cinder: ['qos_specs_list']})
|
||||
|
Loading…
x
Reference in New Issue
Block a user