root / qa / qa_tags.py @ 16e0b9c9
History | View | Annotate | Download (2 kB)
1 |
# Copyright (C) 2007 Google Inc.
|
---|---|
2 |
#
|
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.
|
7 |
#
|
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.
|
12 |
#
|
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
|
16 |
# 02110-1301, USA.
|
17 |
|
18 |
|
19 |
"""Tags related QA tests.
|
20 |
|
21 |
"""
|
22 |
|
23 |
from ganeti import constants |
24 |
|
25 |
import qa_rapi |
26 |
|
27 |
from qa_utils import AssertCommand |
28 |
|
29 |
|
30 |
_TEMP_TAG_NAMES = ["TEMP-Ganeti-QA-Tag%d" % i for i in range(3)] |
31 |
_TEMP_TAG_RE = r'^TEMP-Ganeti-QA-Tag\d+$'
|
32 |
|
33 |
_KIND_TO_COMMAND = { |
34 |
constants.TAG_CLUSTER: "gnt-cluster",
|
35 |
constants.TAG_NODE: "gnt-node",
|
36 |
constants.TAG_INSTANCE: "gnt-instance",
|
37 |
constants.TAG_NODEGROUP: "gnt-group",
|
38 |
} |
39 |
|
40 |
|
41 |
def _TestTags(kind, name): |
42 |
"""Generic function for add-tags.
|
43 |
|
44 |
"""
|
45 |
def cmdfn(subcmd): |
46 |
cmd = [_KIND_TO_COMMAND[kind], subcmd] |
47 |
|
48 |
if kind != constants.TAG_CLUSTER:
|
49 |
cmd.append(name) |
50 |
|
51 |
return cmd
|
52 |
|
53 |
for cmd in [ |
54 |
cmdfn("add-tags") + _TEMP_TAG_NAMES,
|
55 |
cmdfn("list-tags"),
|
56 |
["gnt-cluster", "search-tags", _TEMP_TAG_RE], |
57 |
cmdfn("remove-tags") + _TEMP_TAG_NAMES,
|
58 |
]: |
59 |
AssertCommand(cmd) |
60 |
|
61 |
if qa_rapi.Enabled():
|
62 |
qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES) |
63 |
|
64 |
|
65 |
def TestClusterTags(): |
66 |
"""gnt-cluster tags"""
|
67 |
_TestTags(constants.TAG_CLUSTER, "")
|
68 |
|
69 |
|
70 |
def TestNodeTags(node): |
71 |
"""gnt-node tags"""
|
72 |
_TestTags(constants.TAG_NODE, node["primary"])
|
73 |
|
74 |
|
75 |
def TestGroupTags(group): |
76 |
"""gnt-group tags"""
|
77 |
_TestTags(constants.TAG_NODEGROUP, group) |
78 |
|
79 |
|
80 |
def TestInstanceTags(instance): |
81 |
"""gnt-instance tags"""
|
82 |
_TestTags(constants.TAG_INSTANCE, instance["name"])
|