diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index b1b9b8085..9b3728e0b 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -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') diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 33653a121..d3108a941 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -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: