Statistics
| Branch: | Tag: | Revision:

root / qa / qa_node.py @ 75cf411a

History | View | Annotate | Download (5.9 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

    
25
import qa_config
26
import qa_error
27
import qa_utils
28

    
29
from qa_utils import AssertCommand
30

    
31

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

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

    
45
  AssertCommand(cmd)
46

    
47
  node['_added'] = True
48

    
49

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

    
54

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

    
62

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

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

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

    
74

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

    
82

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

    
87

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

    
92

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

    
97

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

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

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

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

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

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

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

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

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

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

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

    
148

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

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

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

    
162

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

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

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

    
182

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

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