Statistics
| Branch: | Tag: | Revision:

root / qa / qa_node.py @ 288d6440

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

    
26
import qa_config
27
import qa_error
28
import qa_utils
29

    
30
from qa_utils import AssertCommand
31

    
32

    
33
def _NodeAdd(node, readd=False):
34
  if not readd and node.get('_added', False):
35
    raise qa_error.Error("Node %s already in cluster" % node['primary'])
36
  elif readd and not node.get('_added', False):
37
    raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
38

    
39
  cmd = ['gnt-node', 'add', "--no-ssh-key-check"]
40
  if node.get('secondary', None):
41
    cmd.append('--secondary-ip=%s' % node['secondary'])
42
  if readd:
43
    cmd.append('--readd')
44
  cmd.append(node['primary'])
45

    
46
  AssertCommand(cmd)
47

    
48
  node['_added'] = True
49

    
50

    
51
def _NodeRemove(node):
52
  AssertCommand(["gnt-node", "remove", node["primary"]])
53
  node['_added'] = False
54

    
55

    
56
def TestNodeAddAll():
57
  """Adding all nodes to cluster."""
58
  master = qa_config.GetMasterNode()
59
  for node in qa_config.get('nodes'):
60
    if node != master:
61
      _NodeAdd(node, readd=False)
62

    
63

    
64
def MarkNodeAddedAll():
65
  """Mark all nodes as added.
66

67
  This is useful if we don't create the cluster ourselves (in qa).
68

69
  """
70
  master = qa_config.GetMasterNode()
71
  for node in qa_config.get('nodes'):
72
    if node != master:
73
      node['_added'] = True
74

    
75

    
76
def TestNodeRemoveAll():
77
  """Removing all nodes from cluster."""
78
  master = qa_config.GetMasterNode()
79
  for node in qa_config.get('nodes'):
80
    if node != master:
81
      _NodeRemove(node)
82

    
83

    
84
def TestNodeReadd(node):
85
  """gnt-node add --readd"""
86
  _NodeAdd(node, readd=True)
87

    
88

    
89
def TestNodeInfo():
90
  """gnt-node info"""
91
  AssertCommand(["gnt-node", "info"])
92

    
93

    
94
def TestNodeVolumes():
95
  """gnt-node volumes"""
96
  AssertCommand(["gnt-node", "volumes"])
97

    
98

    
99
def TestNodeStorage():
100
  """gnt-node storage"""
101
  master = qa_config.GetMasterNode()
102

    
103
  for storage_type in constants.VALID_STORAGE_TYPES:
104
    # Test simple list
105
    AssertCommand(["gnt-node", "list-storage", "--storage-type", storage_type])
106

    
107
    # Test all storage fields
108
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
109
           "--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) +
110
                                    [constants.SF_NODE, constants.SF_TYPE])]
111
    AssertCommand(cmd)
112

    
113
    # Get list of valid storage devices
114
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
115
           "--output=node,name,allocatable", "--separator=|",
116
           "--no-headers"]
117
    output = qa_utils.GetCommandOutput(master["primary"],
118
                                       utils.ShellQuoteArgs(cmd))
119

    
120
    # Test with up to two devices
121
    testdevcount = 2
122

    
123
    for line in output.splitlines()[:testdevcount]:
124
      (node_name, st_name, st_allocatable) = line.split("|")
125

    
126
      # Dummy modification without any changes
127
      cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name]
128
      AssertCommand(cmd)
129

    
130
      # Make sure we end up with the same value as before
131
      if st_allocatable.lower() == "y":
132
        test_allocatable = ["no", "yes"]
133
      else:
134
        test_allocatable = ["yes", "no"]
135

    
136
      fail = (constants.SF_ALLOCATABLE not in
137
              constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, []))
138

    
139
      for i in test_allocatable:
140
        AssertCommand(["gnt-node", "modify-storage", "--allocatable", i,
141
                       node_name, storage_type, st_name], fail=fail)
142

    
143
      # Test repair functionality
144
      fail = (constants.SO_FIX_CONSISTENCY not in
145
              constants.VALID_STORAGE_OPERATIONS.get(storage_type, []))
146
      AssertCommand(["gnt-node", "repair-storage", node_name,
147
                     storage_type, st_name], fail=fail)
148

    
149

    
150
def TestNodeFailover(node, node2):
151
  """gnt-node failover"""
152
  if qa_utils.GetNodeInstances(node2, secondaries=False):
153
    raise qa_error.UnusableNodeError("Secondary node has at least one"
154
                                     " primary instance. This test requires"
155
                                     " it to have no primary instances.")
156

    
157
  # Fail over to secondary node
158
  AssertCommand(["gnt-node", "failover", "-f", node["primary"]])
159

    
160
  # ... and back again.
161
  AssertCommand(["gnt-node", "failover", "-f", node2["primary"]])
162

    
163

    
164
def TestNodeEvacuate(node, node2):
165
  """gnt-node evacuate"""
166
  node3 = qa_config.AcquireNode(exclude=[node, node2])
167
  try:
168
    if qa_utils.GetNodeInstances(node3, secondaries=True):
169
      raise qa_error.UnusableNodeError("Evacuation node has at least one"
170
                                       " secondary instance. This test requires"
171
                                       " it to have no secondary instances.")
172

    
173
    # Evacuate all secondary instances
174
    AssertCommand(["gnt-node", "evacuate", "-f",
175
                   "--new-secondary=%s" % node3["primary"], node2["primary"]])
176

    
177
    # ... and back again.
178
    AssertCommand(["gnt-node", "evacuate", "-f",
179
                   "--new-secondary=%s" % node2["primary"], node3["primary"]])
180
  finally:
181
    qa_config.ReleaseNode(node3)
182

    
183

    
184
def TestNodeModify(node):
185
  """gnt-node modify"""
186
  for flag in ["master-candidate", "drained", "offline"]:
187
    for value in ["yes", "no"]:
188
      AssertCommand(["gnt-node", "modify", "--force",
189
                     "--%s=%s" % (flag, value), node["primary"]])
190

    
191
  AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
192
                 "--auto-promote", node["primary"]])
193

    
194

    
195
def TestNodeList():
196
  """gnt-node list"""
197
  qa_utils.GenericQueryTest("gnt-node", query.NODE_FIELDS.keys())