Split QA script into different modules.
[ganeti-local] / qa / qa_node.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 from ganeti import utils
20
21 import qa_config
22 import qa_error
23
24 from qa_utils import AssertEqual, StartSSH
25
26
27 def _NodeAdd(node):
28   master = qa_config.GetMasterNode()
29
30   if node.get('_added', False):
31     raise qa_error.Error("Node %s already in cluster" % node['primary'])
32
33   cmd = ['gnt-node', 'add']
34   if node.get('secondary', None):
35     cmd.append('--secondary-ip=%s' % node['secondary'])
36   cmd.append(node['primary'])
37   AssertEqual(StartSSH(master['primary'],
38                        utils.ShellQuoteArgs(cmd)).wait(), 0)
39
40   node['_added'] = True
41
42
43 def _NodeRemove(node):
44   master = qa_config.GetMasterNode()
45
46   cmd = ['gnt-node', 'remove', node['primary']]
47   AssertEqual(StartSSH(master['primary'],
48                        utils.ShellQuoteArgs(cmd)).wait(), 0)
49   node['_added'] = False
50
51
52 def TestNodeAddAll():
53   """Adding all nodes to cluster."""
54   master = qa_config.GetMasterNode()
55   for node in qa_config.get('nodes'):
56     if node != master:
57       _NodeAdd(node)
58
59
60 def TestNodeRemoveAll():
61   """Removing all nodes from cluster."""
62   master = qa_config.GetMasterNode()
63   for node in qa_config.get('nodes'):
64     if node != master:
65       _NodeRemove(node)
66
67
68 def TestNodeInfo():
69   """gnt-node info"""
70   master = qa_config.GetMasterNode()
71
72   cmd = ['gnt-node', 'info']
73   AssertEqual(StartSSH(master['primary'],
74                        utils.ShellQuoteArgs(cmd)).wait(), 0)
75
76
77 def TestNodeVolumes():
78   """gnt-node volumes"""
79   master = qa_config.GetMasterNode()
80
81   cmd = ['gnt-node', 'volumes']
82   AssertEqual(StartSSH(master['primary'],
83                        utils.ShellQuoteArgs(cmd)).wait(), 0)