Change volume create --volume-type to --type

This makes it consistent with the other --type options in OSC.  Also
add a few more volume_create tests.

Change-Id: I50ef927932cabf157ecdfd6c4faa1914b4fdf413
This commit is contained in:
Dean Troyer 2014-05-09 09:28:53 -05:00
parent a93851d6af
commit 870e7ddbcc
3 changed files with 160 additions and 20 deletions

View File

@ -24,7 +24,14 @@ volume_id = 'vvvvvvvv-vvvv-vvvv-vvvvvvvv'
volume_name = 'nigel'
volume_description = 'Nigel Tufnel'
volume_size = 120
volume_metadata = {}
volume_type = 'to-eleven'
volume_zone = 'stonehenge'
volume_metadata = {
'Alpha': 'a',
'Beta': 'b',
'Gamma': 'g',
}
volume_metadata_str = "Alpha='a', Beta='b', Gamma='g'"
VOLUME = {
'id': volume_id,
@ -33,6 +40,8 @@ VOLUME = {
'size': volume_size,
'status': '',
'attach_status': 'detached',
'availability_zone': volume_zone,
'volume_type': volume_type,
'metadata': volume_metadata,
}

View File

@ -71,10 +71,6 @@ class TestVolumeCreate(TestVolume):
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
@ -96,22 +92,90 @@ class TestVolumeCreate(TestVolume):
collist = (
'attach_status',
'availability_zone',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
'type',
)
self.assertEqual(columns, collist)
datalist = (
'detached',
volume_fakes.volume_zone,
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_metadata_str,
volume_fakes.volume_size,
'',
volume_fakes.volume_type,
)
self.assertEqual(data, datalist)
def test_volume_create_options(self):
arglist = [
'--size', str(volume_fakes.volume_size),
'--description', volume_fakes.volume_description,
'--type', volume_fakes.volume_type,
'--availability-zone', volume_fakes.volume_zone,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('description', volume_fakes.volume_description),
('type', volume_fakes.volume_type),
('availability_zone', volume_fakes.volume_zone),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
volume_fakes.volume_description,
volume_fakes.volume_type,
None,
None,
volume_fakes.volume_zone,
None,
None,
)
collist = (
'attach_status',
'availability_zone',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
'type',
)
self.assertEqual(columns, collist)
datalist = (
'detached',
volume_fakes.volume_zone,
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
volume_fakes.volume_metadata_str,
volume_fakes.volume_size,
'',
volume_fakes.volume_type,
)
self.assertEqual(data, datalist)
@ -146,10 +210,6 @@ class TestVolumeCreate(TestVolume):
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
@ -172,22 +232,26 @@ class TestVolumeCreate(TestVolume):
collist = (
'attach_status',
'availability_zone',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
'type',
)
self.assertEqual(columns, collist)
datalist = (
'detached',
volume_fakes.volume_zone,
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_metadata_str,
volume_fakes.volume_size,
'',
volume_fakes.volume_type,
)
self.assertEqual(data, datalist)
@ -222,10 +286,6 @@ class TestVolumeCreate(TestVolume):
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
@ -248,21 +308,86 @@ class TestVolumeCreate(TestVolume):
collist = (
'attach_status',
'availability_zone',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
'type',
)
self.assertEqual(columns, collist)
datalist = (
'detached',
volume_fakes.volume_zone,
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_metadata_str,
volume_fakes.volume_size,
'',
volume_fakes.volume_type,
)
self.assertEqual(data, datalist)
def test_volume_create_properties(self):
arglist = [
'--property', 'Alpha=a',
'--property', 'Beta=b',
'--size', str(volume_fakes.volume_size),
volume_fakes.volume_name,
]
verifylist = [
('property', {'Alpha': 'a', 'Beta': 'b'}),
('size', volume_fakes.volume_size),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
None,
None,
None,
None,
None,
{'Alpha': 'a', 'Beta': 'b'},
None,
)
collist = (
'attach_status',
'availability_zone',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
'type',
)
self.assertEqual(columns, collist)
datalist = (
'detached',
volume_fakes.volume_zone,
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
volume_fakes.volume_metadata_str,
volume_fakes.volume_size,
'',
volume_fakes.volume_type,
)
self.assertEqual(data, datalist)

View File

@ -56,7 +56,7 @@ class CreateVolume(show.ShowOne):
help='Description of the volume',
)
parser.add_argument(
'--volume-type',
'--type',
metavar='<volume-type>',
help='Type of volume',
)
@ -124,7 +124,7 @@ class CreateVolume(show.ShowOne):
source_volume,
parsed_args.name,
parsed_args.description,
parsed_args.volume_type,
parsed_args.type,
user,
project,
parsed_args.availability_zone,
@ -133,7 +133,10 @@ class CreateVolume(show.ShowOne):
)
# Map 'metadata' column to 'properties'
volume._info.update(
{'properties': utils.format_dict(volume._info.pop('metadata'))}
{
'properties': utils.format_dict(volume._info.pop('metadata')),
'type': volume._info.pop('volume_type'),
},
)
return zip(*sorted(six.iteritems(volume._info)))
@ -331,7 +334,10 @@ class ShowVolume(show.ShowOne):
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
# Map 'metadata' column to 'properties'
volume._info.update(
{'properties': utils.format_dict(volume._info.pop('metadata'))}
{
'properties': utils.format_dict(volume._info.pop('metadata')),
'type': volume._info.pop('volume_type'),
},
)
if 'os-vol-tenant-attr:tenant_id' in volume._info:
volume._info.update(