Statistics
| Branch: | Tag: | Revision:

root / qa / qa_tags.py @ a4c589d2

History | View | Annotate | Download (2.1 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
  constants.TAG_NETWORK: "gnt-network",
42
  }
43

    
44

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

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

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

    
55
    return cmd
56

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

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

    
68

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

    
73

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

    
78

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

    
83

    
84
def TestInstanceTags(instance):
85
  """gnt-instance tags"""
86
  _TestTags(constants.TAG_INSTANCE, instance.name)
87

    
88

    
89
def TestNetworkTags(network):
90
  """gnt-network tags"""
91
  _TestTags(constants.TAG_NETWORK, network)