Skip to content

Commit acc0297

Browse files
author
Tang Chen
committed
Add functional tests for "volume" commands v2
The tests for v2 "volume" commands are quite similar to v1. This patch also map 'metadata' to 'properties', 'volume_type' to 'type' to align to the v1 output. Change-Id: Icf2c5463b186fc78c890ccd96453090c4a2c2eb6 Partial-bug: #1519503
1 parent 5a978b9 commit acc0297

4 files changed

Lines changed: 116 additions & 2 deletions

File tree

functional/tests/volume/v2/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import os
14+
import uuid
15+
16+
from functional.common import test
17+
18+
19+
class VolumeTests(test.TestCase):
20+
"""Functional tests for volume. """
21+
22+
NAME = uuid.uuid4().hex
23+
OTHER_NAME = uuid.uuid4().hex
24+
HEADERS = ['"Display Name"']
25+
FIELDS = ['name']
26+
27+
@classmethod
28+
def setUpClass(cls):
29+
os.environ['OS_VOLUME_API_VERSION'] = '2'
30+
opts = cls.get_show_opts(cls.FIELDS)
31+
raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts)
32+
expected = cls.NAME + '\n'
33+
cls.assertOutput(expected, raw_output)
34+
35+
@classmethod
36+
def tearDownClass(cls):
37+
# Rename test
38+
raw_output = cls.openstack(
39+
'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
40+
cls.assertOutput('', raw_output)
41+
# Delete test
42+
raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME)
43+
cls.assertOutput('', raw_output)
44+
45+
def test_volume_list(self):
46+
opts = self.get_list_opts(self.HEADERS)
47+
raw_output = self.openstack('volume list' + opts)
48+
self.assertIn(self.NAME, raw_output)
49+
50+
def test_volume_show(self):
51+
opts = self.get_show_opts(self.FIELDS)
52+
raw_output = self.openstack('volume show ' + self.NAME + opts)
53+
self.assertEqual(self.NAME + "\n", raw_output)
54+
55+
def test_volume_properties(self):
56+
raw_output = self.openstack(
57+
'volume set --property a=b --property c=d ' + self.NAME)
58+
self.assertEqual("", raw_output)
59+
opts = self.get_show_opts(["properties"])
60+
raw_output = self.openstack('volume show ' + self.NAME + opts)
61+
self.assertEqual("a='b', c='d'\n", raw_output)
62+
63+
raw_output = self.openstack('volume unset --property a ' + self.NAME)
64+
self.assertEqual("", raw_output)
65+
raw_output = self.openstack('volume show ' + self.NAME + opts)
66+
self.assertEqual("c='d'\n", raw_output)
67+
68+
def test_volume_set(self):
69+
discription = uuid.uuid4().hex
70+
self.openstack('volume set --description ' + discription + ' ' +
71+
self.NAME)
72+
opts = self.get_show_opts(["description", "name"])
73+
raw_output = self.openstack('volume show ' + self.NAME + opts)
74+
self.assertEqual(discription + "\n" + self.NAME + "\n", raw_output)
75+
76+
def test_volume_set_size(self):
77+
self.openstack('volume set --size 2 ' + self.NAME)
78+
opts = self.get_show_opts(["name", "size"])
79+
raw_output = self.openstack('volume show ' + self.NAME + opts)
80+
self.assertEqual(self.NAME + "\n2\n", raw_output)

openstackclient/tests/volume/v2/fakes.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import random
1818
import uuid
1919

20+
from openstackclient.common import utils as common_utils
2021
from openstackclient.tests import fakes
2122
from openstackclient.tests.identity.v3 import fakes as identity_fakes
2223
from openstackclient.tests.image.v2 import fakes as image_fakes
@@ -56,8 +57,31 @@
5657
"attachments": volume_attachments
5758
}
5859

59-
VOLUME_columns = tuple(sorted(VOLUME))
60-
VOLUME_data = tuple((VOLUME[x] for x in sorted(VOLUME)))
60+
VOLUME_columns = (
61+
"attachments",
62+
"availability_zone",
63+
"description",
64+
"id",
65+
"name",
66+
"properties",
67+
"size",
68+
"snapshot_id",
69+
"status",
70+
"type"
71+
)
72+
73+
VOLUME_data = (
74+
volume_attachments,
75+
volume_availability_zone,
76+
volume_description,
77+
volume_id,
78+
volume_name,
79+
common_utils.format_dict(volume_metadata),
80+
volume_size,
81+
volume_snapshot_id,
82+
volume_status,
83+
volume_type
84+
)
6185

6286

6387
snapshot_id = "cb2d364e-4d1c-451a-8c68-b5bbcb340fb2"

openstackclient/volume/v2/volume.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,16 @@ def take_action(self, parsed_args):
394394
volume_client = self.app.client_manager.volume
395395
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
396396

397+
# Special mapping for columns to make the output easier to read:
398+
# 'metadata' --> 'properties'
399+
# 'volume_type' --> 'type'
400+
volume._info.update(
401+
{
402+
'properties': utils.format_dict(volume._info.pop('metadata')),
403+
'type': volume._info.pop('volume_type'),
404+
},
405+
)
406+
397407
# Remove key links from being displayed
398408
volume._info.pop("links", None)
399409
return zip(*sorted(six.iteritems(volume._info)))

0 commit comments

Comments
 (0)