diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index 1c99f7f10..eb11837f9 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -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): diff --git a/openstack_dashboard/test/api_tests/nova_rest_tests.py b/openstack_dashboard/test/api_tests/nova_rest_tests.py index 572b95d3f..539f62009 100644 --- a/openstack_dashboard/test/api_tests/nova_rest_tests.py +++ b/openstack_dashboard/test/api_tests/nova_rest_tests.py @@ -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()