Disallow set node label with empty key CLI v2

Label's key can not be empty string, so need to handle this case and raise error

Change-Id: I23919d26f29246dd392ae44738cc79579b64507a
Closes-Bug: #1484099
This commit is contained in:
ekosareva 2015-08-13 09:45:58 +04:00
parent 4c74a60aa6
commit 6ad5e0eb4d
4 changed files with 20 additions and 1 deletions

View File

@ -88,6 +88,10 @@ class ExecutedErrorNonZeroExitCode(FuelClientException):
"""Subshell command returned non-zero exit code."""
class LabelEmptyKeyError(BadDataException):
"""Should be raised when user provides labels with empty key."""
def exceptions_decorator(func):
"""Handles HTTP errors and expected exceptions that may occur
in methods of APIClient class

View File

@ -61,7 +61,7 @@ class TestHandlers(base.BaseTestCase):
cases = [
("env --create --name=TestEnv --release=1 --mode=multinode",
"400 Client Error: Bad Request (Cannot deploy in multinode "
"mode in current release. Need to be one of [u'ha_compact']")
"mode in current release. Need to be one of: ha_compact")
]
for cmd, err in cases:
self.check_for_stderr(cmd, err, check_errors=False)

View File

@ -156,6 +156,17 @@ class TestNodeFacade(test_api.BaseLibTest):
self.assertTrue(matcher_put.called)
self.assertEqual(data, matcher_put.last_request.json())
def test_set_labels_with_empty_key(self):
labels = ['key_1=val_1', ' = val_2', 'key_3 = ']
node_ids = ['42']
msg = 'Wrong label "{0}" was provided. Label key couldn\'t ' \
'be an empty string.'.format(labels[1])
with self.assertRaisesRegexp(error.LabelEmptyKeyError, msg):
self.client.set_labels_for_nodes(labels=labels, node_ids=node_ids)
self.assertFalse(self.top_matcher.called)
def test_delete_specific_labels_for_all_nodes(self):
labels = ['key_1', ' key_3 ']
data = {'labels': {'key_2': None}}

View File

@ -112,6 +112,10 @@ class NodeClient(base_v1.BaseV1Client):
for label in labels:
key, val, _ = self._split_label(label)
if not key:
msg = 'Wrong label "{0}" was provided. Label key couldn\'t ' \
'be an empty string.'.format(label)
raise error.LabelEmptyKeyError(msg)
labels_to_update[key] = val
if node_ids: