Merge "Strip leading or trailing spaces from Instance names during update and create"
This commit is contained in:
commit
5db645b8b0
@ -650,7 +650,7 @@ def server_create(request, name, image, flavor, key_name, user_data,
|
||||
disk_config=None, config_drive=None, meta=None,
|
||||
scheduler_hints=None):
|
||||
return Server(novaclient(request).servers.create(
|
||||
name, image, flavor, userdata=user_data,
|
||||
name.strip(), image, flavor, userdata=user_data,
|
||||
security_groups=security_groups,
|
||||
key_name=key_name, block_device_mapping=block_device_mapping,
|
||||
block_device_mapping_v2=block_device_mapping_v2,
|
||||
@ -740,7 +740,7 @@ def server_rebuild(request, instance_id, image_id, password=None,
|
||||
|
||||
|
||||
def server_update(request, instance_id, name):
|
||||
return novaclient(request).servers.update(instance_id, name=name)
|
||||
return novaclient(request).servers.update(instance_id, name=name.strip())
|
||||
|
||||
|
||||
def server_migrate(request, instance_id):
|
||||
|
@ -354,6 +354,19 @@ class NovaRestTestCase(test.TestCase):
|
||||
[{'name': 'root'}]
|
||||
)
|
||||
|
||||
@mock.patch.object(nova.api, 'nova')
|
||||
def test_server_create_with_leading_trailing_space(self, nc):
|
||||
request = self.mock_rest_request(body='''{"name": " Ni! ",
|
||||
"source_id": "image123", "flavor_id": "flavor123",
|
||||
"key_name": "sekrit", "user_data": "base64 yes",
|
||||
"security_groups": [{"name": "root"}]}
|
||||
''')
|
||||
new = nc.server_create.return_value
|
||||
new.to_dict.return_value = {'name': ' Ni! '.strip()}
|
||||
response = nova.Servers().post(request)
|
||||
self.assertStatusCode(response, 201)
|
||||
self.assertEqual({"name": "Ni!"}, response.json)
|
||||
|
||||
@mock.patch.object(nova.api, 'nova')
|
||||
def test_server_list(self, nc):
|
||||
request = self.mock_rest_request()
|
||||
|
Loading…
Reference in New Issue
Block a user