1 # Copyright (C) 2007 Google Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 """Tags related QA tests.
23 from ganeti import utils
24 from ganeti import constants
30 from qa_utils import AssertEqual, StartSSH
33 _TEMP_TAG_NAMES = ["TEMP-Ganeti-QA-Tag%d" % i for i in range(3)]
34 _TEMP_TAG_RE = r'^TEMP-Ganeti-QA-Tag\d+$'
37 constants.TAG_CLUSTER: "gnt-cluster",
38 constants.TAG_NODE: "gnt-node",
39 constants.TAG_INSTANCE: "gnt-instance",
43 def _TestTags(kind, name):
44 """Generic function for add-tags.
47 master = qa_config.GetMasterNode()
50 cmd = [_KIND_TO_COMMAND[kind], subcmd]
52 if kind != constants.TAG_CLUSTER:
57 cmd = cmdfn('add-tags') + _TEMP_TAG_NAMES
58 AssertEqual(StartSSH(master['primary'],
59 utils.ShellQuoteArgs(cmd)).wait(), 0)
61 cmd = cmdfn('list-tags')
62 AssertEqual(StartSSH(master['primary'],
63 utils.ShellQuoteArgs(cmd)).wait(), 0)
65 cmd = ['gnt-cluster', 'search-tags', _TEMP_TAG_RE]
66 AssertEqual(StartSSH(master['primary'],
67 utils.ShellQuoteArgs(cmd)).wait(), 0)
70 qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
72 cmd = cmdfn('remove-tags') + _TEMP_TAG_NAMES
73 AssertEqual(StartSSH(master['primary'],
74 utils.ShellQuoteArgs(cmd)).wait(), 0)
77 def TestClusterTags():
78 """gnt-cluster tags"""
79 _TestTags(constants.TAG_CLUSTER, "")
82 def TestNodeTags(node):
84 _TestTags(constants.TAG_NODE, node["primary"])
87 def TestInstanceTags(instance):
88 """gnt-instance tags"""
89 _TestTags(constants.TAG_INSTANCE, instance["name"])