Merge "Fix ValueError when incorrect metadata passed"
This commit is contained in:
commit
296b5da84b
|
@ -614,6 +614,14 @@ class ShellTest(utils.TestCase):
|
||||||
}},
|
}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_boot_with_incorrect_metadata(self):
|
||||||
|
cmd = ('boot --image %s --flavor 1 --meta foo '
|
||||||
|
'some-server ' % FAKE_UUID_1)
|
||||||
|
result = self.assertRaises(argparse.ArgumentTypeError,
|
||||||
|
self.run_command, cmd)
|
||||||
|
expected = "'['foo']' is not in the format of 'key=value'"
|
||||||
|
self.assertEqual(expected, result.args[0])
|
||||||
|
|
||||||
def test_boot_hints(self):
|
def test_boot_hints(self):
|
||||||
self.run_command('boot --image %s --flavor 1 '
|
self.run_command('boot --image %s --flavor 1 '
|
||||||
'--hint a=b0=c0 --hint a=b1=c1 some-server ' %
|
'--hint a=b0=c0 --hint a=b1=c1 some-server ' %
|
||||||
|
@ -1206,6 +1214,13 @@ class ShellTest(utils.TestCase):
|
||||||
{'createImage': {'name': 'mysnapshot', 'metadata': {}}},
|
{'createImage': {'name': 'mysnapshot', 'metadata': {}}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_create_image_with_incorrect_metadata(self):
|
||||||
|
cmd = 'image-create sample-server mysnapshot --metadata foo'
|
||||||
|
result = self.assertRaises(argparse.ArgumentTypeError,
|
||||||
|
self.run_command, cmd)
|
||||||
|
expected = "'['foo']' is not in the format of 'key=value'"
|
||||||
|
self.assertEqual(expected, result.args[0])
|
||||||
|
|
||||||
def test_create_image_with_metadata(self):
|
def test_create_image_with_metadata(self):
|
||||||
self.run_command(
|
self.run_command(
|
||||||
'image-create sample-server mysnapshot --metadata mykey=123')
|
'image-create sample-server mysnapshot --metadata mykey=123')
|
||||||
|
@ -1442,6 +1457,13 @@ class ShellTest(utils.TestCase):
|
||||||
self.assert_called('GET', '/flavors/1', pos=4)
|
self.assert_called('GET', '/flavors/1', pos=4)
|
||||||
self.assert_called('GET', '/v2/images/%s' % FAKE_UUID_2, pos=5)
|
self.assert_called('GET', '/v2/images/%s' % FAKE_UUID_2, pos=5)
|
||||||
|
|
||||||
|
def test_rebuild_with_incorrect_metadata(self):
|
||||||
|
cmd = 'rebuild sample-server %s --name asdf --meta foo' % FAKE_UUID_1
|
||||||
|
result = self.assertRaises(argparse.ArgumentTypeError,
|
||||||
|
self.run_command, cmd)
|
||||||
|
expected = "'['foo']' is not in the format of 'key=value'"
|
||||||
|
self.assertEqual(expected, result.args[0])
|
||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
self.run_command('start sample-server')
|
self.run_command('start sample-server')
|
||||||
self.assert_called('POST', '/servers/1234/action', {'os-start': None})
|
self.assert_called('POST', '/servers/1234/action', {'os-start': None})
|
||||||
|
|
|
@ -75,7 +75,11 @@ def _key_value_pairing(text):
|
||||||
|
|
||||||
|
|
||||||
def _meta_parsing(metadata):
|
def _meta_parsing(metadata):
|
||||||
return dict(v.split('=', 1) for v in metadata)
|
try:
|
||||||
|
return dict(v.split('=', 1) for v in metadata)
|
||||||
|
except ValueError:
|
||||||
|
msg = _("'%s' is not in the format of 'key=value'") % metadata
|
||||||
|
raise argparse.ArgumentTypeError(msg)
|
||||||
|
|
||||||
|
|
||||||
def _match_image(cs, wanted_properties):
|
def _match_image(cs, wanted_properties):
|
||||||
|
|
Loading…
Reference in New Issue