Test tag functionality.
[ganeti-local] / qa / qa_tags.py
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
25 import qa_config
26 import qa_utils
27
28 from qa_utils import AssertEqual, StartSSH
29
30
31 _TEMP_TAG_NAMES = ["TEMP-Ganeti-QA-Tag%d" % i for i in range(3)]
32 _TEMP_TAG_RE = r'^TEMP-Ganeti-QA-Tag\d+$'
33
34
35 def _TestTags(cmdfn):
36   """Generic function for add-tags.
37
38   """
39   master = qa_config.GetMasterNode()
40
41   cmd = cmdfn('add-tags') + _TEMP_TAG_NAMES
42   AssertEqual(StartSSH(master['primary'],
43                        utils.ShellQuoteArgs(cmd)).wait(), 0)
44
45   cmd = cmdfn('list-tags')
46   AssertEqual(StartSSH(master['primary'],
47                        utils.ShellQuoteArgs(cmd)).wait(), 0)
48
49   cmd = ['gnt-cluster', 'search-tags', _TEMP_TAG_RE]
50   AssertEqual(StartSSH(master['primary'],
51                        utils.ShellQuoteArgs(cmd)).wait(), 0)
52
53   cmd = cmdfn('remove-tags') + _TEMP_TAG_NAMES
54   AssertEqual(StartSSH(master['primary'],
55                        utils.ShellQuoteArgs(cmd)).wait(), 0)
56
57
58 def TestClusterTags():
59   """gnt-cluster tags"""
60   _TestTags(lambda subcmd: ['gnt-cluster', subcmd])
61
62
63 def TestNodeTags(node):
64   """gnt-node tags"""
65   _TestTags(lambda subcmd: ['gnt-node', subcmd, node['primary']])
66
67
68 def TestInstanceTags(instance):
69   """gnt-instance tags"""
70   _TestTags(lambda subcmd: ['gnt-instance', subcmd, instance['name']])