Added functional tests for server tags (microverison 2.26)

Also fixed wrong shell output in 'server-tag-list'
and removes 'server-tag-show' command.

Change-Id: Icfd73e50108c7b1226e51307c0afc3f8f54ff2d6
This commit is contained in:
Sergey Nikitin 2016-06-10 12:54:55 +03:00 committed by Timofey Durakov
parent a70de7e590
commit 19ff19e1b8
6 changed files with 78 additions and 36 deletions

View File

@ -344,6 +344,38 @@ class ClientTestBase(testtools.TestCase):
raise ValueError("Unable to find value for column '%s'." % column)
def _get_list_of_values_from_single_column_table(self, table, column):
"""Get the list of values for the column in the single-column table
Example table:
+------+
| Tags |
+------+
| tag1 |
| tag2 |
+------+
:param table: newline-separated table with |-separated cells
:param column: name of the column to look for
:raises: ValueError if the single column has some other name
"""
lines = table.split("\n")
column_name = None
values = []
for line in lines:
if "|" in line:
if not column_name:
column_name = line.split("|")[1].strip()
if column_name != column:
raise ValueError(
"The table has no column %(expected)s "
"but has column %(actual)s." % {
'expected': column, 'actual': column_name})
else:
values.append(line.split("|")[1].strip())
return values
def _create_server(self, name=None, with_network=True, add_cleanup=True,
**kwargs):
name = name or self.name_generate(prefix='server')

View File

@ -127,3 +127,47 @@ class TestServersDescription(base.ClientTestBase):
self.assertIn("\nERROR (BadRequest): Invalid input for field/attribute"
" description. Value: %s. u\'%s\' is too long (HTTP 400)"
% (descr, descr), output)
class TestServersTagsV226(base.ClientTestBase):
COMPUTE_API_VERSION = "2.26"
def _boot_server_with_tags(self):
uuid = self._create_server().id
self.client.servers.set_tags(uuid, ["t1", "t2"])
return uuid
def test_show(self):
uuid = self._boot_server_with_tags()
output = self.nova("show %s" % uuid)
self.assertEqual('["t1", "t2"]', self._get_value_from_the_table(
output, "tags"))
def test_list(self):
uuid = self._boot_server_with_tags()
output = self.nova("server-tag-list %s" % uuid)
tags = self._get_list_of_values_from_single_column_table(
output, "Tag")
self.assertEqual(["t1", "t2"], tags)
def test_add(self):
uuid = self._boot_server_with_tags()
self.nova("server-tag-add %s t3" % uuid)
self.assertEqual(["t1", "t2", "t3"],
self.client.servers.tag_list(uuid))
def test_set(self):
uuid = self._boot_server_with_tags()
self.nova("server-tag-set %s t3 t4" % uuid)
self.assertEqual(["t3", "t4"], self.client.servers.tag_list(uuid))
def test_delete(self):
uuid = self._boot_server_with_tags()
self.nova("server-tag-delete %s t2" % uuid)
self.assertEqual(["t1"], self.client.servers.tag_list(uuid))
def test_delete_all(self):
uuid = self._boot_server_with_tags()
self.nova("server-tag-delete-all %s" % uuid)
self.assertEqual([], self.client.servers.tag_list(uuid))

View File

@ -1184,9 +1184,3 @@ class ServersV226Test(ServersV225Test):
ret = s.set_tags(['tag1', 'tag2'])
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('PUT', '/servers/1234/tags')
def test_tag_exists(self):
s = self.cs.servers.get(1234)
ret = s.tag_exists('tag')
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('GET', '/servers/1234/tags/tag')

View File

@ -2840,11 +2840,6 @@ class ShellTest(utils.TestCase):
api_version='2.26')
self.assert_called('DELETE', '/servers/1234/tags')
def test_server_tag_exists(self):
self.run_command('server-tag-exists sample-server tag',
api_version='2.26')
self.assert_called('GET', '/servers/1234/tags/tag')
def test_list_v2_26_tags(self):
self.run_command('list --tags tag1,tag2', api_version='2.26')
self.assert_called('GET', '/servers/detail?tags=tag1%2Ctag2')

View File

@ -556,12 +556,6 @@ class Server(base.Resource):
"""
return self.manager.add_tag(self, tag)
def tag_exists(self, tag):
"""
Check if an instance has specified tag.
"""
return self.manager.tag_exists(self, tag)
class NetworkInterface(base.Resource):
@property
@ -1784,12 +1778,3 @@ class ServerManager(base.BootingManagerWithFind):
"""
return self._update(
"/servers/%s/tags/%s" % (base.getid(server), tag), None)
@api_versions.wraps('2.26')
def tag_exists(self, server, tag):
"""
Check if an instance has specified tag.
"""
resp, body = self.api.client.get(
"/servers/%s/tags/%s" % (base.getid(server), tag))
return self.convert_into_with_meta(body, resp)

View File

@ -5029,7 +5029,8 @@ def do_server_tag_list(cs, args):
"""Get list of tags from a server."""
server = _find_server(cs, args.server)
tags = server.tag_list()
utils.print_list(tags, 'name')
formatters = {'Tag': lambda o: o}
utils.print_list(tags, ['Tag'], formatters=formatters)
@api_versions.wraps("2.26")
@ -5065,12 +5066,3 @@ def do_server_tag_delete_all(cs, args):
"""Delete all tags from a server."""
server = _find_server(cs, args.server)
server.delete_all_tags()
@api_versions.wraps("2.26")
@utils.arg('server', metavar='<server>', help=_('Name or ID of server.'))
@utils.arg('tag', metavar='<tag>', help=_('Tag to check if it exists or not.'))
def do_server_tag_exists(cs, args):
"""Check if a server has specified tag."""
server = _find_server(cs, args.server)
server.tag_exists(args.tag)