Statistics
| Branch: | Tag: | Revision:

root / qa / qa_tags.py @ dbdb0594

History | View | Annotate | Download (2 kB)

1 fd7b69c0 Michael Hanselmann
#
2 fd7b69c0 Michael Hanselmann
#
3 fd7b69c0 Michael Hanselmann
4 d74c2ca1 Michael Hanselmann
# Copyright (C) 2007 Google Inc.
5 d74c2ca1 Michael Hanselmann
#
6 d74c2ca1 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 d74c2ca1 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 d74c2ca1 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 d74c2ca1 Michael Hanselmann
# (at your option) any later version.
10 d74c2ca1 Michael Hanselmann
#
11 d74c2ca1 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 d74c2ca1 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 d74c2ca1 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 d74c2ca1 Michael Hanselmann
# General Public License for more details.
15 d74c2ca1 Michael Hanselmann
#
16 d74c2ca1 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 d74c2ca1 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 d74c2ca1 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 d74c2ca1 Michael Hanselmann
# 02110-1301, USA.
20 d74c2ca1 Michael Hanselmann
21 d74c2ca1 Michael Hanselmann
22 d74c2ca1 Michael Hanselmann
"""Tags related QA tests.
23 d74c2ca1 Michael Hanselmann

24 d74c2ca1 Michael Hanselmann
"""
25 d74c2ca1 Michael Hanselmann
26 a47f574c Oleksiy Mishchenko
from ganeti import constants
27 d74c2ca1 Michael Hanselmann
28 a47f574c Oleksiy Mishchenko
import qa_rapi
29 d74c2ca1 Michael Hanselmann
30 2f4b4f78 Iustin Pop
from qa_utils import AssertCommand
31 d74c2ca1 Michael Hanselmann
32 d74c2ca1 Michael Hanselmann
33 d74c2ca1 Michael Hanselmann
_TEMP_TAG_NAMES = ["TEMP-Ganeti-QA-Tag%d" % i for i in range(3)]
34 d74c2ca1 Michael Hanselmann
_TEMP_TAG_RE = r'^TEMP-Ganeti-QA-Tag\d+$'
35 d74c2ca1 Michael Hanselmann
36 a47f574c Oleksiy Mishchenko
_KIND_TO_COMMAND = {
37 a47f574c Oleksiy Mishchenko
  constants.TAG_CLUSTER: "gnt-cluster",
38 a47f574c Oleksiy Mishchenko
  constants.TAG_NODE: "gnt-node",
39 a47f574c Oleksiy Mishchenko
  constants.TAG_INSTANCE: "gnt-instance",
40 fe508a9d Michael Hanselmann
  constants.TAG_NODEGROUP: "gnt-group",
41 a47f574c Oleksiy Mishchenko
  }
42 a47f574c Oleksiy Mishchenko
43 d74c2ca1 Michael Hanselmann
44 a47f574c Oleksiy Mishchenko
def _TestTags(kind, name):
45 d74c2ca1 Michael Hanselmann
  """Generic function for add-tags.
46 d74c2ca1 Michael Hanselmann

47 d74c2ca1 Michael Hanselmann
  """
48 a47f574c Oleksiy Mishchenko
  def cmdfn(subcmd):
49 a47f574c Oleksiy Mishchenko
    cmd = [_KIND_TO_COMMAND[kind], subcmd]
50 a47f574c Oleksiy Mishchenko
51 a47f574c Oleksiy Mishchenko
    if kind != constants.TAG_CLUSTER:
52 a47f574c Oleksiy Mishchenko
      cmd.append(name)
53 a47f574c Oleksiy Mishchenko
54 a47f574c Oleksiy Mishchenko
    return cmd
55 a47f574c Oleksiy Mishchenko
56 2f4b4f78 Iustin Pop
  for cmd in [
57 2f4b4f78 Iustin Pop
    cmdfn("add-tags") + _TEMP_TAG_NAMES,
58 2f4b4f78 Iustin Pop
    cmdfn("list-tags"),
59 2f4b4f78 Iustin Pop
    ["gnt-cluster", "search-tags", _TEMP_TAG_RE],
60 2f4b4f78 Iustin Pop
    cmdfn("remove-tags") + _TEMP_TAG_NAMES,
61 2f4b4f78 Iustin Pop
    ]:
62 2f4b4f78 Iustin Pop
    AssertCommand(cmd)
63 d74c2ca1 Michael Hanselmann
64 c326b4ef Michael Hanselmann
  if qa_rapi.Enabled():
65 c326b4ef Michael Hanselmann
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
66 c326b4ef Michael Hanselmann
67 d74c2ca1 Michael Hanselmann
68 d74c2ca1 Michael Hanselmann
def TestClusterTags():
69 d74c2ca1 Michael Hanselmann
  """gnt-cluster tags"""
70 a47f574c Oleksiy Mishchenko
  _TestTags(constants.TAG_CLUSTER, "")
71 d74c2ca1 Michael Hanselmann
72 d74c2ca1 Michael Hanselmann
73 d74c2ca1 Michael Hanselmann
def TestNodeTags(node):
74 d74c2ca1 Michael Hanselmann
  """gnt-node tags"""
75 a47f574c Oleksiy Mishchenko
  _TestTags(constants.TAG_NODE, node["primary"])
76 d74c2ca1 Michael Hanselmann
77 d74c2ca1 Michael Hanselmann
78 fe508a9d Michael Hanselmann
def TestGroupTags(group):
79 fe508a9d Michael Hanselmann
  """gnt-group tags"""
80 fe508a9d Michael Hanselmann
  _TestTags(constants.TAG_NODEGROUP, group)
81 fe508a9d Michael Hanselmann
82 fe508a9d Michael Hanselmann
83 d74c2ca1 Michael Hanselmann
def TestInstanceTags(instance):
84 d74c2ca1 Michael Hanselmann
  """gnt-instance tags"""
85 a47f574c Oleksiy Mishchenko
  _TestTags(constants.TAG_INSTANCE, instance["name"])