Report better error message --ephemeral poor usage

The eph_dict expects the format size=value.Catch valueError and return
proper error text

Change-Id: I99ef7efe7dc14aa346913009e244ad4eea0369a9
Closes-bug: #1433200
This commit is contained in:
Ramaraja Ramachandran 2015-04-01 11:31:46 +05:30
parent 493a33a024
commit 2761606fbf
2 changed files with 10 additions and 2 deletions
novaclient
tests/unit/v2
v2

@ -16,6 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import base64
import datetime
import os
@ -686,6 +687,10 @@ class ShellTest(utils.TestCase):
}
}, pos=4)
def test_boot_invalid_ephemeral_data_format(self):
cmd = 'boot --flavor 1 --image 1 --ephemeral 1 some-server'
self.assertRaises(argparse.ArgumentTypeError, self.run_command, cmd)
def test_flavor_list(self):
self.run_command('flavor-list')
self.assert_called_anytime('GET', '/flavors/detail')

@ -118,8 +118,11 @@ def _parse_block_device_mapping_v2(args, image):
for ephemeral_spec in args.ephemeral:
bdm_dict = {'source_type': 'blank', 'destination_type': 'local',
'boot_index': -1, 'delete_on_termination': True}
eph_dict = dict(v.split('=') for v in ephemeral_spec.split(','))
try:
eph_dict = dict(v.split('=') for v in ephemeral_spec.split(','))
except ValueError:
err_msg = (_("Invalid ephemeral argument '%s'.") % args.ephemeral)
raise argparse.ArgumentTypeError(err_msg)
if 'size' in eph_dict:
bdm_dict['volume_size'] = eph_dict['size']
if 'format' in eph_dict: