Allocation API: correct setting name to None

This is a follow-up to commit aec48ca275.

Change-Id: Id87c0a6e3232a9cdd98cb5ee1f722815986fb9c5
This commit is contained in:
Dmitry Tantsur 2019-05-22 13:12:49 +02:00
parent ed5c3d940d
commit a0f0e52b8e
2 changed files with 12 additions and 1 deletions

View File

@ -409,7 +409,7 @@ class AllocationsController(pecan.rest.RestController):
self._validate_patch(patch)
names = api_utils.get_patch_values(patch, '/name')
for name in names:
if len(name) and not api_utils.is_valid_logical_name(name):
if name and not api_utils.is_valid_logical_name(name):
msg = _("Cannot update allocation with invalid name "
"'%(name)s'") % {'name': name}
raise exception.Invalid(msg)

View File

@ -466,6 +466,17 @@ class TestPatch(test_api_base.BaseApiTest):
obj_fields.NotificationLevel.INFO,
obj_fields.NotificationStatus.END)])
def test_replace_name_with_none(self):
response = self.patch_json('/allocations/%s' % self.allocation.uuid,
[{'path': '/name',
'value': None, 'op': 'replace'}],
headers=self.headers)
self.assertEqual('application/json', response.content_type)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/allocations/%s' % self.allocation.uuid,
headers=self.headers)
self.assertIsNone(result['name'])
@mock.patch.object(notification_utils, '_emit_api_notification')
@mock.patch.object(objects.Allocation, 'save')
def test_update_error(self, mock_save, mock_notify):