Statistics
| Branch: | Tag: | Revision:

root / qa / qa_tags.py @ dbdb0594

History | View | Annotate | Download (2 kB)

1
#
2
#
3

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

    
21

    
22
"""Tags related QA tests.
23

24
"""
25

    
26
from ganeti import constants
27

    
28
import qa_rapi
29

    
30
from qa_utils import AssertCommand
31

    
32

    
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+$'
35

    
36
_KIND_TO_COMMAND = {
37
  constants.TAG_CLUSTER: "gnt-cluster",
38
  constants.TAG_NODE: "gnt-node",
39
  constants.TAG_INSTANCE: "gnt-instance",
40
  constants.TAG_NODEGROUP: "gnt-group",
41
  }
42

    
43

    
44
def _TestTags(kind, name):
45
  """Generic function for add-tags.
46

47
  """
48
  def cmdfn(subcmd):
49
    cmd = [_KIND_TO_COMMAND[kind], subcmd]
50

    
51
    if kind != constants.TAG_CLUSTER:
52
      cmd.append(name)
53

    
54
    return cmd
55

    
56
  for cmd in [
57
    cmdfn("add-tags") + _TEMP_TAG_NAMES,
58
    cmdfn("list-tags"),
59
    ["gnt-cluster", "search-tags", _TEMP_TAG_RE],
60
    cmdfn("remove-tags") + _TEMP_TAG_NAMES,
61
    ]:
62
    AssertCommand(cmd)
63

    
64
  if qa_rapi.Enabled():
65
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
66

    
67

    
68
def TestClusterTags():
69
  """gnt-cluster tags"""
70
  _TestTags(constants.TAG_CLUSTER, "")
71

    
72

    
73
def TestNodeTags(node):
74
  """gnt-node tags"""
75
  _TestTags(constants.TAG_NODE, node["primary"])
76

    
77

    
78
def TestGroupTags(group):
79
  """gnt-group tags"""
80
  _TestTags(constants.TAG_NODEGROUP, group)
81

    
82

    
83
def TestInstanceTags(instance):
84
  """gnt-instance tags"""
85
  _TestTags(constants.TAG_INSTANCE, instance["name"])