Statistics
| Branch: | Tag: | Revision:

root / qa / qa_tags.py @ c54784d9

History | View | Annotate | Download (2.4 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 utils
24
from ganeti import constants
25

    
26
import qa_config
27
import qa_utils
28
import qa_rapi
29

    
30
from qa_utils import AssertEqual, StartSSH
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
  }
41

    
42

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

46
  """
47
  master = qa_config.GetMasterNode()
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
  cmd = cmdfn('add-tags') + _TEMP_TAG_NAMES
58
  AssertEqual(StartSSH(master['primary'],
59
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
60

    
61
  cmd = cmdfn('list-tags')
62
  AssertEqual(StartSSH(master['primary'],
63
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
64

    
65
  cmd = ['gnt-cluster', 'search-tags', _TEMP_TAG_RE]
66
  AssertEqual(StartSSH(master['primary'],
67
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
68

    
69
  if qa_rapi.Enabled():
70
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
71

    
72
  cmd = cmdfn('remove-tags') + _TEMP_TAG_NAMES
73
  AssertEqual(StartSSH(master['primary'],
74
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
75

    
76

    
77
@qa_utils.DefineHook('tags-cluster')
78
def TestClusterTags():
79
  """gnt-cluster tags"""
80
  _TestTags(constants.TAG_CLUSTER, "")
81

    
82

    
83
@qa_utils.DefineHook('tags-node')
84
def TestNodeTags(node):
85
  """gnt-node tags"""
86
  _TestTags(constants.TAG_NODE, node["primary"])
87

    
88

    
89
@qa_utils.DefineHook('tags-instance')
90
def TestInstanceTags(instance):
91
  """gnt-instance tags"""
92
  _TestTags(constants.TAG_INSTANCE, instance["name"])