From 96fde33630fbf310946ec1a744466df52232e854 Mon Sep 17 00:00:00 2001 From: Anna Babich Date: Wed, 25 May 2016 17:31:06 +0300 Subject: [PATCH] Functional tests for server's description Functional tests for microversion 2.19 have been added. They include several actions with server's description mentioned in Testing section of the appropriate spec [1] for Python nova-client and openstack-client, namely: - Add a description to the tests that create a server - Add a description to the tests that rebuild a server - Set and remove the description on an existing server - Check that the description is returned as part of server details for an individual server and for a server list - [Negative] The description passed to the API is longer than 255 characters - The description passed to the API is an empty string. This is allowed Tests that are not implemented yet: - [Negative] The description passed to the API is not valid printable unicode [1] http://specs.openstack.org/openstack/nova-specs/specs/mitaka/implemented/user-settable-server-description.html Change-Id: Ieab77bf5569871380987769c47e9f4dab2ec9e4b --- .../tests/functional/v2/test_servers.py | 58 +++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/novaclient/tests/functional/v2/test_servers.py b/novaclient/tests/functional/v2/test_servers.py index cf6f45a17..642cfed34 100644 --- a/novaclient/tests/functional/v2/test_servers.py +++ b/novaclient/tests/functional/v2/test_servers.py @@ -10,8 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. +import random +import string + from novaclient.tests.functional import base from novaclient.tests.functional.v2.legacy import test_servers +from novaclient.v2 import shell class TestServersBootNovaClient(test_servers.TestServersBootNovaClient): @@ -62,18 +66,64 @@ class TestServersDescription(base.ClientTestBase): return server, descr def test_create(self): + # Add a description to the tests that create a server server, descr = self._boot_server_with_description() - output = self.nova("show %s" % server.id) self.assertEqual(descr, self._get_value_from_the_table(output, "description")) - def test_update(self): + def test_list_servers_with_description(self): + # Check that the description is returned as part of server details + # for a server list server, descr = self._boot_server_with_description() + output = self.nova("list --fields description") + self.assertEqual(server.id, + self._get_column_value_from_single_row_table( + output, "ID")) + self.assertEqual(descr, + self._get_column_value_from_single_row_table( + output, "Description")) - # remove description + def test_rebuild(self): + # Add a description to the tests that rebuild a server + server, descr = self._boot_server_with_description() + descr = "New description for rebuilt VM." + self.nova("rebuild --description '%s' %s %s" % + (descr, server.id, self.image.name)) + shell._poll_for_status( + self.client.servers.get, server.id, + 'rebuild', ['active']) + output = self.nova("show %s" % server.id) + self.assertEqual(descr, self._get_value_from_the_table(output, + "description")) + + def test_remove_description(self): + # Remove description from server booted with it + server, descr = self._boot_server_with_description() self.nova("update %s --description ''" % server.id) - output = self.nova("show %s" % server.id) self.assertEqual("-", self._get_value_from_the_table(output, "description")) + + def test_add_remove_description_on_existing_server(self): + # Set and remove the description on an existing server + server = self._create_server() + descr = "Add a description for previously-booted VM." + self.nova("update %s --description '%s'" % (server.id, descr)) + output = self.nova("show %s" % server.id) + self.assertEqual(descr, self._get_value_from_the_table(output, + "description")) + self.nova("update %s --description ''" % server.id) + output = self.nova("show %s" % server.id) + self.assertEqual("-", self._get_value_from_the_table(output, + "description")) + + def test_update_with_description_longer_than_255_symbols(self): + # Negative case for description longer than 255 characters + server = self._create_server() + descr = ''.join(random.choice(string.letters) for i in range(256)) + output = self.nova("update %s --description '%s'" % (server.id, descr), + fail_ok=True, merge_stderr=True) + self.assertIn("\nERROR (BadRequest): Invalid input for field/attribute" + " description. Value: %s. u\'%s\' is too long (HTTP 400)" + % (descr, descr), output)