Statistics
| Branch: | Tag: | Revision:

root / qa / qa_tags.py @ 2237687b

History | View | Annotate | Download (1.9 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
  }
38

    
39

    
40
def _TestTags(kind, name):
41
  """Generic function for add-tags.
42

43
  """
44
  def cmdfn(subcmd):
45
    cmd = [_KIND_TO_COMMAND[kind], subcmd]
46

    
47
    if kind != constants.TAG_CLUSTER:
48
      cmd.append(name)
49

    
50
    return cmd
51

    
52
  for cmd in [
53
    cmdfn("add-tags") + _TEMP_TAG_NAMES,
54
    cmdfn("list-tags"),
55
    ["gnt-cluster", "search-tags", _TEMP_TAG_RE],
56
    cmdfn("remove-tags") + _TEMP_TAG_NAMES,
57
    ]:
58
    AssertCommand(cmd)
59

    
60
  if qa_rapi.Enabled():
61
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
62

    
63

    
64
def TestClusterTags():
65
  """gnt-cluster tags"""
66
  _TestTags(constants.TAG_CLUSTER, "")
67

    
68

    
69
def TestNodeTags(node):
70
  """gnt-node tags"""
71
  _TestTags(constants.TAG_NODE, node["primary"])
72

    
73

    
74
def TestInstanceTags(instance):
75
  """gnt-instance tags"""
76
  _TestTags(constants.TAG_INSTANCE, instance["name"])