From 852bd46805098e03fdd85a83ccbeec403bfb4836 Mon Sep 17 00:00:00 2001 From: Chen Hanxiao Date: Fri, 29 Dec 2017 10:15:36 +0800 Subject: [PATCH] boot: error out if no images match the property from --image-with We may fail to get a image when setting --image-with meta_key=meta_value. We should error out, rather than sending a request then waiting for the errors from the remote side. Change-Id: I54a645a533e39b069e50fdee6893f8b0cced494c Signed-off-by: Chen Hanxiao --- novaclient/tests/unit/v2/test_shell.py | 5 +++++ novaclient/v2/shell.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 453c8eacc..30b695e88 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -157,6 +157,11 @@ class ShellTest(utils.TestCase): }}, ) + def test_boot_image_with_error_out_no_match(self): + cmd = ("boot --flavor 1" + " --image-with fake_key=fake_value some-server") + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_boot_key(self): self.run_command('boot --flavor 1 --image %s --key-name 1 some-server' % FAKE_UUID_1) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 0f211d0a0..7976adf88 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -409,6 +409,9 @@ def _boot(cs, args): emit_duplicated_image_with_warning(images, args.image_with) if images: image = images[0] + else: + raise exceptions.CommandError(_("No images match the property " + "expected by --image-with")) min_count = 1 max_count = 1