Merge "Correct api version check conditional for node.name"

This commit is contained in:
Jenkins 2016-04-10 12:50:03 +00:00 committed by Gerrit Code Review
commit 1bff8ddee4
3 changed files with 46 additions and 2 deletions

View File

@ -1213,7 +1213,7 @@ class NodesController(rest.RestController):
e.code = http_client.BAD_REQUEST
raise e
if node.name:
if (node.name != wtypes.Unset and node.name is not None):
error_msg = _("Cannot create node with invalid name "
"%(name)s") % {'name': node.name}
self._check_name_acceptable(node.name, error_msg)
@ -1264,7 +1264,7 @@ class NodesController(rest.RestController):
msg % node_ident, status_code=http_client.CONFLICT)
name = api_utils.get_patch_value(patch, '/name')
if name:
if name is not None:
error_msg = _("Node %(node)s: Cannot change name to invalid "
"name '%(name)s'") % {'node': node_ident,
'name': name}

View File

@ -1269,6 +1269,29 @@ class TestPatch(test_api_base.BaseApiTest):
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_add_name_empty_invalid(self):
test_name = ''
response = self.patch_json('/nodes/%s' % self.node_no_name.uuid,
[{'path': '/name',
'op': 'add',
'value': test_name}],
headers={api_base.Version.string: "1.5"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_add_name_empty_not_acceptable(self):
test_name = ''
response = self.patch_json('/nodes/%s' % self.node_no_name.uuid,
[{'path': '/name',
'op': 'add',
'value': test_name}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_name_replace_ok(self):
self.mock_update_node.return_value = self.node
test_name = 'guido-van-rossum'
@ -1380,6 +1403,22 @@ class TestPost(test_api_base.BaseApiTest):
self.assertEqual(urlparse.urlparse(response.location).path,
expected_location)
def test_create_node_name_empty_invalid(self):
ndict = test_api_utils.post_get_test_node(name='')
response = self.post_json('/nodes', ndict,
headers={api_base.Version.string: "1.10"},
expect_errors=True)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_node_name_empty_not_acceptable(self):
ndict = test_api_utils.post_get_test_node(name='')
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_node_default_state_none(self):
ndict = test_api_utils.post_get_test_node()
response = self.post_json('/nodes', ndict,

View File

@ -0,0 +1,5 @@
---
fixes:
- Correct api version check conditional for node.name to address
an issue that we could set node name to '' using API version lower than
1.5, where node names were introduced.