Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ fa84c8a4

History | View | Annotate | Download (23.3 kB)

1 f89d59b9 Iustin Pop
#!/usr/bin/python -u
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 50ef6a41 Bernardo Dal Seno
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 cec9845c Michael Hanselmann
"""Script for doing QA on Ganeti.
23 94508060 Michael Hanselmann

24 94508060 Michael Hanselmann
"""
25 a8083063 Iustin Pop
26 b459a848 Andrea Spadaccini
# pylint: disable=C0103
27 3582eef6 Iustin Pop
# due to invalid name
28 3582eef6 Iustin Pop
29 a8083063 Iustin Pop
import sys
30 c68d1f43 Michael Hanselmann
import datetime
31 c68d1f43 Michael Hanselmann
import optparse
32 a8083063 Iustin Pop
33 cec9845c Michael Hanselmann
import qa_cluster
34 cec9845c Michael Hanselmann
import qa_config
35 cec9845c Michael Hanselmann
import qa_daemon
36 cec9845c Michael Hanselmann
import qa_env
37 83180411 Bernardo Dal Seno
import qa_error
38 30131294 Adeodato Simo
import qa_group
39 cec9845c Michael Hanselmann
import qa_instance
40 cec9845c Michael Hanselmann
import qa_node
41 8947cf2b Michael Hanselmann
import qa_os
42 09470dd8 Michael Hanselmann
import qa_job
43 a47f574c Oleksiy Mishchenko
import qa_rapi
44 d74c2ca1 Michael Hanselmann
import qa_tags
45 1672a0d1 Michael Hanselmann
import qa_utils
46 a8083063 Iustin Pop
47 725ec2f1 René Nussbaumer
from ganeti import utils
48 8ad0da1e Iustin Pop
from ganeti import rapi # pylint: disable=W0611
49 f3fd2c9d Adeodato Simo
from ganeti import constants
50 2a7c3583 Michael Hanselmann
51 b459a848 Andrea Spadaccini
import ganeti.rapi.client # pylint: disable=W0611
52 fc3f75dd Iustin Pop
from ganeti.rapi.client import UsesRapiClient
53 725ec2f1 René Nussbaumer
54 a8083063 Iustin Pop
55 7d88f255 Iustin Pop
def _FormatHeader(line, end=72):
56 f89d59b9 Iustin Pop
  """Fill a line up to the end column.
57 f89d59b9 Iustin Pop

58 f89d59b9 Iustin Pop
  """
59 f89d59b9 Iustin Pop
  line = "---- " + line + " "
60 21bf2e2e Andrea Spadaccini
  line += "-" * (end - len(line))
61 f89d59b9 Iustin Pop
  line = line.rstrip()
62 f89d59b9 Iustin Pop
  return line
63 f89d59b9 Iustin Pop
64 f89d59b9 Iustin Pop
65 7d88f255 Iustin Pop
def _DescriptionOf(fn):
66 7d88f255 Iustin Pop
  """Computes the description of an item.
67 a8083063 Iustin Pop

68 a8083063 Iustin Pop
  """
69 cec9845c Michael Hanselmann
  if fn.__doc__:
70 cec9845c Michael Hanselmann
    desc = fn.__doc__.splitlines()[0].strip()
71 a8083063 Iustin Pop
  else:
72 f89d59b9 Iustin Pop
    desc = "%r" % fn
73 a8083063 Iustin Pop
74 7d88f255 Iustin Pop
  return desc.rstrip(".")
75 7d88f255 Iustin Pop
76 2932dc44 Michael Hanselmann
77 741c6d91 Michael Hanselmann
def RunTest(fn, *args, **kwargs):
78 7d88f255 Iustin Pop
  """Runs a test after printing a header.
79 7d88f255 Iustin Pop

80 7d88f255 Iustin Pop
  """
81 a8083063 Iustin Pop
82 f89d59b9 Iustin Pop
  tstart = datetime.datetime.now()
83 a8083063 Iustin Pop
84 7d88f255 Iustin Pop
  desc = _DescriptionOf(fn)
85 7d88f255 Iustin Pop
86 f89d59b9 Iustin Pop
  print
87 f89d59b9 Iustin Pop
  print _FormatHeader("%s start %s" % (tstart, desc))
88 f89d59b9 Iustin Pop
89 f89d59b9 Iustin Pop
  try:
90 741c6d91 Michael Hanselmann
    retval = fn(*args, **kwargs)
91 f89d59b9 Iustin Pop
    return retval
92 f89d59b9 Iustin Pop
  finally:
93 f89d59b9 Iustin Pop
    tstop = datetime.datetime.now()
94 f89d59b9 Iustin Pop
    tdelta = tstop - tstart
95 f89d59b9 Iustin Pop
    print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
96 a8083063 Iustin Pop
97 a8083063 Iustin Pop
98 741c6d91 Michael Hanselmann
def RunTestIf(testnames, fn, *args, **kwargs):
99 7d88f255 Iustin Pop
  """Runs a test conditionally.
100 7d88f255 Iustin Pop

101 7d88f255 Iustin Pop
  @param testnames: either a single test name in the configuration
102 7d88f255 Iustin Pop
      file, or a list of testnames (which will be AND-ed together)
103 7d88f255 Iustin Pop

104 7d88f255 Iustin Pop
  """
105 7d88f255 Iustin Pop
  if qa_config.TestEnabled(testnames):
106 741c6d91 Michael Hanselmann
    RunTest(fn, *args, **kwargs)
107 7d88f255 Iustin Pop
  else:
108 7d88f255 Iustin Pop
    tstart = datetime.datetime.now()
109 7d88f255 Iustin Pop
    desc = _DescriptionOf(fn)
110 7d88f255 Iustin Pop
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
111 7d88f255 Iustin Pop
                        (tstart, desc, testnames))
112 7d88f255 Iustin Pop
113 7d88f255 Iustin Pop
114 b1ffe1eb Michael Hanselmann
def RunEnvTests():
115 b1ffe1eb Michael Hanselmann
  """Run several environment tests.
116 a8083063 Iustin Pop

117 a8083063 Iustin Pop
  """
118 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestSshConnection)
119 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestIcmpPing)
120 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestGanetiCommands)
121 a8083063 Iustin Pop
122 94508060 Michael Hanselmann
123 725ec2f1 René Nussbaumer
def SetupCluster(rapi_user, rapi_secret):
124 b1ffe1eb Michael Hanselmann
  """Initializes the cluster.
125 a8083063 Iustin Pop

126 725ec2f1 René Nussbaumer
  @param rapi_user: Login user for RAPI
127 725ec2f1 René Nussbaumer
  @param rapi_secret: Login secret for RAPI
128 725ec2f1 René Nussbaumer

129 b1ffe1eb Michael Hanselmann
  """
130 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
131 7d88f255 Iustin Pop
            rapi_user, rapi_secret)
132 6a0f22e1 Bernardo Dal Seno
  if not qa_config.TestEnabled("create-cluster"):
133 6a0f22e1 Bernardo Dal Seno
    # If the cluster is already in place, we assume that exclusive-storage is
134 6a0f22e1 Bernardo Dal Seno
    # already set according to the configuration
135 6a0f22e1 Bernardo Dal Seno
    qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
136 288d6440 Michael Hanselmann
137 288d6440 Michael Hanselmann
  # Test on empty cluster
138 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
139 288d6440 Michael Hanselmann
  RunTestIf("instance-list", qa_instance.TestInstanceList)
140 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobList)
141 288d6440 Michael Hanselmann
142 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
143 7d88f255 Iustin Pop
  if not qa_config.TestEnabled("create-cluster"):
144 8e671b7c Iustin Pop
    # consider the nodes are already there
145 8e671b7c Iustin Pop
    qa_node.MarkNodeAddedAll()
146 8201b996 Iustin Pop
147 7d88f255 Iustin Pop
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
148 cd04f8c2 Michael Hanselmann
149 8201b996 Iustin Pop
  # enable the watcher (unconditionally)
150 8201b996 Iustin Pop
  RunTest(qa_daemon.TestResumeWatcher)
151 8201b996 Iustin Pop
152 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
153 288d6440 Michael Hanselmann
154 2214cf14 Michael Hanselmann
  # Test listing fields
155 2214cf14 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeListFields)
156 2214cf14 Michael Hanselmann
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)
157 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobListFields)
158 0fdf247d Michael Hanselmann
  RunTestIf("instance-export", qa_instance.TestBackupListFields)
159 2214cf14 Michael Hanselmann
160 7d88f255 Iustin Pop
  RunTestIf("node-info", qa_node.TestNodeInfo)
161 b1ffe1eb Michael Hanselmann
162 b1ffe1eb Michael Hanselmann
163 b1ffe1eb Michael Hanselmann
def RunClusterTests():
164 b1ffe1eb Michael Hanselmann
  """Runs tests related to gnt-cluster.
165 180bdd1f Michael Hanselmann

166 b1ffe1eb Michael Hanselmann
  """
167 7d88f255 Iustin Pop
  for test, fn in [
168 92cb4940 Andrea Spadaccini
    ("create-cluster", qa_cluster.TestClusterInitDisk),
169 7d88f255 Iustin Pop
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
170 7d88f255 Iustin Pop
    ("cluster-verify", qa_cluster.TestClusterVerify),
171 7d88f255 Iustin Pop
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
172 9738ca94 Iustin Pop
    # TODO: add more cluster modify tests
173 1e7acc3b Iustin Pop
    ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
174 b3f3aa3d Bernardo Dal Seno
    ("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
175 b3f3aa3d Bernardo Dal Seno
    ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
176 7d88f255 Iustin Pop
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
177 92cb4940 Andrea Spadaccini
    ("cluster-modify", qa_cluster.TestClusterModifyDisk),
178 7d88f255 Iustin Pop
    ("cluster-rename", qa_cluster.TestClusterRename),
179 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterVersion),
180 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterInfo),
181 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterGetmaster),
182 3e8b5a9c Iustin Pop
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
183 7d88f255 Iustin Pop
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
184 7d88f255 Iustin Pop
    ("cluster-command", qa_cluster.TestClusterCommand),
185 7d88f255 Iustin Pop
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
186 7d88f255 Iustin Pop
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
187 ff699aa9 Michael Hanselmann
    ("cluster-master-failover",
188 ff699aa9 Michael Hanselmann
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
189 69df9d2b Iustin Pop
    ("cluster-oob", qa_cluster.TestClusterOob),
190 7d88f255 Iustin Pop
    ("rapi", qa_rapi.TestVersion),
191 7d88f255 Iustin Pop
    ("rapi", qa_rapi.TestEmptyCluster),
192 4fab7cab Michael Hanselmann
    ("rapi", qa_rapi.TestRapiQuery),
193 7d88f255 Iustin Pop
    ]:
194 7d88f255 Iustin Pop
    RunTestIf(test, fn)
195 8947cf2b Michael Hanselmann
196 6d4a1656 Michael Hanselmann
197 65a884ef Iustin Pop
def RunRepairDiskSizes():
198 65a884ef Iustin Pop
  """Run the repair disk-sizes test.
199 65a884ef Iustin Pop

200 65a884ef Iustin Pop
  """
201 65a884ef Iustin Pop
  RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
202 65a884ef Iustin Pop
203 65a884ef Iustin Pop
204 b1ffe1eb Michael Hanselmann
def RunOsTests():
205 b1ffe1eb Michael Hanselmann
  """Runs all tests related to gnt-os.
206 5d640672 Michael Hanselmann

207 b1ffe1eb Michael Hanselmann
  """
208 2932dc44 Michael Hanselmann
  if qa_config.TestEnabled("rapi"):
209 2932dc44 Michael Hanselmann
    rapi_getos = qa_rapi.GetOperatingSystems
210 2932dc44 Michael Hanselmann
  else:
211 2932dc44 Michael Hanselmann
    rapi_getos = None
212 2932dc44 Michael Hanselmann
213 7d88f255 Iustin Pop
  for fn in [
214 7d88f255 Iustin Pop
    qa_os.TestOsList,
215 7d88f255 Iustin Pop
    qa_os.TestOsDiagnose,
216 2932dc44 Michael Hanselmann
    ]:
217 2932dc44 Michael Hanselmann
    RunTestIf("os", fn)
218 2932dc44 Michael Hanselmann
219 2932dc44 Michael Hanselmann
  for fn in [
220 7d88f255 Iustin Pop
    qa_os.TestOsValid,
221 7d88f255 Iustin Pop
    qa_os.TestOsInvalid,
222 7d88f255 Iustin Pop
    qa_os.TestOsPartiallyValid,
223 2932dc44 Michael Hanselmann
    ]:
224 2932dc44 Michael Hanselmann
    RunTestIf("os", fn, rapi_getos)
225 2932dc44 Michael Hanselmann
226 2932dc44 Michael Hanselmann
  for fn in [
227 7d88f255 Iustin Pop
    qa_os.TestOsModifyValid,
228 7d88f255 Iustin Pop
    qa_os.TestOsModifyInvalid,
229 074e139f Michael Hanselmann
    qa_os.TestOsStatesNonExisting,
230 7d88f255 Iustin Pop
    ]:
231 7d88f255 Iustin Pop
    RunTestIf("os", fn)
232 b1ffe1eb Michael Hanselmann
233 b1ffe1eb Michael Hanselmann
234 b1ffe1eb Michael Hanselmann
def RunCommonInstanceTests(instance):
235 b1ffe1eb Michael Hanselmann
  """Runs a few tests that are common to all disk types.
236 b1ffe1eb Michael Hanselmann

237 b1ffe1eb Michael Hanselmann
  """
238 7d88f255 Iustin Pop
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
239 b82d4c5e Michael Hanselmann
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
240 b82d4c5e Michael Hanselmann
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
241 3016bc1f Michael Hanselmann
  RunTestIf(["instance-shutdown", "instance-modify"],
242 3016bc1f Michael Hanselmann
            qa_instance.TestInstanceStoppedModify, instance)
243 7d88f255 Iustin Pop
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
244 a8083063 Iustin Pop
245 a7418448 Michael Hanselmann
  # Test shutdown/start via RAPI
246 a7418448 Michael Hanselmann
  RunTestIf(["instance-shutdown", "rapi"],
247 a7418448 Michael Hanselmann
            qa_rapi.TestRapiInstanceShutdown, instance)
248 a7418448 Michael Hanselmann
  RunTestIf(["instance-shutdown", "rapi"],
249 a7418448 Michael Hanselmann
            qa_rapi.TestRapiInstanceStartup, instance)
250 a7418448 Michael Hanselmann
251 7d88f255 Iustin Pop
  RunTestIf("instance-list", qa_instance.TestInstanceList)
252 283f9d4c Michael Hanselmann
253 7d88f255 Iustin Pop
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
254 e9e35aaa Michael Hanselmann
255 7d88f255 Iustin Pop
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
256 7d88f255 Iustin Pop
  RunTestIf(["instance-modify", "rapi"],
257 7d88f255 Iustin Pop
            qa_rapi.TestRapiInstanceModify, instance)
258 c0f74c55 Iustin Pop
259 7d88f255 Iustin Pop
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
260 b82d4c5e Michael Hanselmann
  RunTestIf(["instance-console", "rapi"],
261 b82d4c5e Michael Hanselmann
            qa_rapi.TestRapiInstanceConsole, instance)
262 4379b1fa Michael Hanselmann
263 1be35bef Michael Hanselmann
  DOWN_TESTS = qa_config.Either([
264 1be35bef Michael Hanselmann
    "instance-reinstall",
265 1be35bef Michael Hanselmann
    "instance-rename",
266 1be35bef Michael Hanselmann
    "instance-grow-disk",
267 1be35bef Michael Hanselmann
    ])
268 1be35bef Michael Hanselmann
269 4c1a464b Iustin Pop
  # shutdown instance for any 'down' tests
270 4c1a464b Iustin Pop
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
271 4c1a464b Iustin Pop
272 4c1a464b Iustin Pop
  # now run the 'down' state tests
273 7d88f255 Iustin Pop
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
274 0220d2cf Guido Trotter
  RunTestIf(["instance-reinstall", "rapi"],
275 0220d2cf Guido Trotter
            qa_rapi.TestRapiInstanceReinstall, instance)
276 8a4e8898 Michael Hanselmann
277 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-rename"):
278 69bc7a38 Michael Hanselmann
    tgt_instance = qa_config.AcquireInstance()
279 69bc7a38 Michael Hanselmann
    try:
280 69bc7a38 Michael Hanselmann
      rename_source = instance["name"]
281 69bc7a38 Michael Hanselmann
      rename_target = tgt_instance["name"]
282 69bc7a38 Michael Hanselmann
      # perform instance rename to the same name
283 4c1a464b Iustin Pop
      RunTest(qa_instance.TestInstanceRenameAndBack,
284 69bc7a38 Michael Hanselmann
              rename_source, rename_source)
285 4c1a464b Iustin Pop
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
286 69bc7a38 Michael Hanselmann
                rename_source, rename_source)
287 69bc7a38 Michael Hanselmann
      if rename_target is not None:
288 69bc7a38 Michael Hanselmann
        # perform instance rename to a different name, if we have one configured
289 69bc7a38 Michael Hanselmann
        RunTest(qa_instance.TestInstanceRenameAndBack,
290 930e77d1 Michael Hanselmann
                rename_source, rename_target)
291 69bc7a38 Michael Hanselmann
        RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
292 69bc7a38 Michael Hanselmann
                  rename_source, rename_target)
293 69bc7a38 Michael Hanselmann
    finally:
294 69bc7a38 Michael Hanselmann
      qa_config.ReleaseInstance(tgt_instance)
295 4c1a464b Iustin Pop
296 26a5056d Iustin Pop
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
297 26a5056d Iustin Pop
298 4c1a464b Iustin Pop
  # and now start the instance again
299 4c1a464b Iustin Pop
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
300 4c1a464b Iustin Pop
301 4c1a464b Iustin Pop
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
302 18337ca9 Iustin Pop
303 7d88f255 Iustin Pop
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
304 d74c2ca1 Michael Hanselmann
305 1ef6e776 Michael Hanselmann
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
306 d74c2ca1 Michael Hanselmann
307 7d88f255 Iustin Pop
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
308 729c4377 Iustin Pop
309 288d6440 Michael Hanselmann
  # Lists instances, too
310 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
311 288d6440 Michael Hanselmann
312 09470dd8 Michael Hanselmann
  # Some jobs have been run, let's test listing them
313 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobList)
314 09470dd8 Michael Hanselmann
315 729c4377 Iustin Pop
316 729c4377 Iustin Pop
def RunCommonNodeTests():
317 729c4377 Iustin Pop
  """Run a few common node tests.
318 729c4377 Iustin Pop

319 729c4377 Iustin Pop
  """
320 7d88f255 Iustin Pop
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
321 7d88f255 Iustin Pop
  RunTestIf("node-storage", qa_node.TestNodeStorage)
322 a1de4b18 René Nussbaumer
  RunTestIf("node-oob", qa_node.TestOutOfBand)
323 8e1db003 Michael Hanselmann
324 8d8d650c Michael Hanselmann
325 30131294 Adeodato Simo
def RunGroupListTests():
326 30131294 Adeodato Simo
  """Run tests for listing node groups.
327 30131294 Adeodato Simo

328 30131294 Adeodato Simo
  """
329 7ab8b7d7 Adeodato Simo
  RunTestIf("group-list", qa_group.TestGroupList)
330 7ab8b7d7 Adeodato Simo
  RunTestIf("group-list", qa_group.TestGroupListFields)
331 30131294 Adeodato Simo
332 30131294 Adeodato Simo
333 66787da5 Adeodato Simo
def RunGroupRwTests():
334 66787da5 Adeodato Simo
  """Run tests for adding/removing/renaming groups.
335 66787da5 Adeodato Simo

336 66787da5 Adeodato Simo
  """
337 66787da5 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
338 4b10fb65 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
339 4b10fb65 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupModify)
340 b9e478fe Michael Hanselmann
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
341 fe508a9d Michael Hanselmann
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
342 fe508a9d Michael Hanselmann
            qa_group.GetDefaultGroup())
343 4b10fb65 Adeodato Simo
344 66787da5 Adeodato Simo
345 c99200a3 Bernardo Dal Seno
def RunExportImportTests(instance, inodes):
346 b1ffe1eb Michael Hanselmann
  """Tries to export and import the instance.
347 a8083063 Iustin Pop

348 c99200a3 Bernardo Dal Seno
  @type inodes: list of nodes
349 c99200a3 Bernardo Dal Seno
  @param inodes: current nodes of the instance
350 638a7266 Iustin Pop

351 b1ffe1eb Michael Hanselmann
  """
352 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-export"):
353 bc696589 Michael Hanselmann
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
354 bc696589 Michael Hanselmann
355 c99200a3 Bernardo Dal Seno
    pnode = inodes[0]
356 b1ffe1eb Michael Hanselmann
    expnode = qa_config.AcquireNode(exclude=pnode)
357 b1ffe1eb Michael Hanselmann
    try:
358 b1ffe1eb Michael Hanselmann
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
359 b1ffe1eb Michael Hanselmann
360 b1ffe1eb Michael Hanselmann
      RunTest(qa_instance.TestBackupList, expnode)
361 b1ffe1eb Michael Hanselmann
362 d0c8c01d Iustin Pop
      if qa_config.TestEnabled("instance-import"):
363 b1ffe1eb Michael Hanselmann
        newinst = qa_config.AcquireInstance()
364 5d640672 Michael Hanselmann
        try:
365 5fa0375e Michael Hanselmann
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
366 b1ffe1eb Michael Hanselmann
                  expnode, name)
367 51131cad Michael Hanselmann
          # Check if starting the instance works
368 51131cad Michael Hanselmann
          RunTest(qa_instance.TestInstanceStartup, newinst)
369 b1ffe1eb Michael Hanselmann
          RunTest(qa_instance.TestInstanceRemove, newinst)
370 5d640672 Michael Hanselmann
        finally:
371 b1ffe1eb Michael Hanselmann
          qa_config.ReleaseInstance(newinst)
372 b1ffe1eb Michael Hanselmann
    finally:
373 b1ffe1eb Michael Hanselmann
      qa_config.ReleaseNode(expnode)
374 5d640672 Michael Hanselmann
375 7d88f255 Iustin Pop
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
376 5d831182 Michael Hanselmann
    newinst = qa_config.AcquireInstance()
377 5d831182 Michael Hanselmann
    try:
378 c99200a3 Bernardo Dal Seno
      tnode = qa_config.AcquireNode(exclude=inodes)
379 5d831182 Michael Hanselmann
      try:
380 5d831182 Michael Hanselmann
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
381 c99200a3 Bernardo Dal Seno
                inodes, tnode)
382 5d831182 Michael Hanselmann
      finally:
383 638a7266 Iustin Pop
        qa_config.ReleaseNode(tnode)
384 5d831182 Michael Hanselmann
    finally:
385 5d831182 Michael Hanselmann
      qa_config.ReleaseInstance(newinst)
386 5d831182 Michael Hanselmann
387 283f9d4c Michael Hanselmann
388 b998270c Iustin Pop
def RunDaemonTests(instance):
389 b1ffe1eb Michael Hanselmann
  """Test the ganeti-watcher script.
390 9df6d173 Michael Hanselmann

391 b1ffe1eb Michael Hanselmann
  """
392 8201b996 Iustin Pop
  RunTest(qa_daemon.TestPauseWatcher)
393 e9e35aaa Michael Hanselmann
394 7d88f255 Iustin Pop
  RunTestIf("instance-automatic-restart",
395 b998270c Iustin Pop
            qa_daemon.TestInstanceAutomaticRestart, instance)
396 7d88f255 Iustin Pop
  RunTestIf("instance-consecutive-failures",
397 b998270c Iustin Pop
            qa_daemon.TestInstanceConsecutiveFailures, instance)
398 e9e35aaa Michael Hanselmann
399 8201b996 Iustin Pop
  RunTest(qa_daemon.TestResumeWatcher)
400 8201b996 Iustin Pop
401 9df6d173 Michael Hanselmann
402 c99200a3 Bernardo Dal Seno
def RunHardwareFailureTests(instance, inodes):
403 b1ffe1eb Michael Hanselmann
  """Test cluster internal hardware failure recovery.
404 a8083063 Iustin Pop

405 b1ffe1eb Michael Hanselmann
  """
406 7d88f255 Iustin Pop
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
407 c0a146a1 Michael Hanselmann
  RunTestIf(["instance-failover", "rapi"],
408 c0a146a1 Michael Hanselmann
            qa_rapi.TestRapiInstanceFailover, instance)
409 b1ffe1eb Michael Hanselmann
410 7d88f255 Iustin Pop
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
411 7d88f255 Iustin Pop
  RunTestIf(["instance-migrate", "rapi"],
412 7d88f255 Iustin Pop
            qa_rapi.TestRapiInstanceMigrate, instance)
413 938bde86 Michael Hanselmann
414 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-replace-disks"):
415 c99200a3 Bernardo Dal Seno
    # We just need alternative secondary nodes, hence "- 1"
416 c99200a3 Bernardo Dal Seno
    othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
417 7910e7a5 Michael Hanselmann
    try:
418 539d65ba Michael Hanselmann
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
419 7910e7a5 Michael Hanselmann
      RunTest(qa_instance.TestReplaceDisks,
420 c99200a3 Bernardo Dal Seno
              instance, inodes, othernodes)
421 7910e7a5 Michael Hanselmann
    finally:
422 c99200a3 Bernardo Dal Seno
      qa_config.ReleaseManyNodes(othernodes)
423 c99200a3 Bernardo Dal Seno
    del othernodes
424 7910e7a5 Michael Hanselmann
425 83180411 Bernardo Dal Seno
  if qa_config.TestEnabled("instance-recreate-disks"):
426 83180411 Bernardo Dal Seno
    try:
427 c99200a3 Bernardo Dal Seno
      acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
428 c99200a3 Bernardo Dal Seno
      othernodes = acquirednodes
429 83180411 Bernardo Dal Seno
    except qa_error.OutOfNodesError:
430 c99200a3 Bernardo Dal Seno
      if len(inodes) > 1:
431 c99200a3 Bernardo Dal Seno
        # If the cluster is not big enough, let's reuse some of the nodes, but
432 c99200a3 Bernardo Dal Seno
        # with different roles. In this way, we can test a DRBD instance even on
433 c99200a3 Bernardo Dal Seno
        # a 3-node cluster.
434 c99200a3 Bernardo Dal Seno
        acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
435 c99200a3 Bernardo Dal Seno
        othernodes = acquirednodes + inodes[:-1]
436 c99200a3 Bernardo Dal Seno
      else:
437 c99200a3 Bernardo Dal Seno
        raise
438 83180411 Bernardo Dal Seno
    try:
439 83180411 Bernardo Dal Seno
      RunTest(qa_instance.TestRecreateDisks,
440 c99200a3 Bernardo Dal Seno
              instance, inodes, othernodes)
441 83180411 Bernardo Dal Seno
    finally:
442 c99200a3 Bernardo Dal Seno
      qa_config.ReleaseManyNodes(acquirednodes)
443 b1ffe1eb Michael Hanselmann
444 c99200a3 Bernardo Dal Seno
  if len(inodes) >= 2:
445 c99200a3 Bernardo Dal Seno
    RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
446 c99200a3 Bernardo Dal Seno
    RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
447 b1ffe1eb Michael Hanselmann
448 b1ffe1eb Michael Hanselmann
449 50ef6a41 Bernardo Dal Seno
def RunExclusiveStorageTests():
450 50ef6a41 Bernardo Dal Seno
  """Test exclusive storage."""
451 50ef6a41 Bernardo Dal Seno
  if not qa_config.TestEnabled("cluster-exclusive-storage"):
452 50ef6a41 Bernardo Dal Seno
    return
453 50ef6a41 Bernardo Dal Seno
454 50ef6a41 Bernardo Dal Seno
  node = qa_config.AcquireNode()
455 50ef6a41 Bernardo Dal Seno
  try:
456 e8b919a1 Bernardo Dal Seno
    old_es = qa_cluster.TestSetExclStorCluster(False)
457 250a9404 Bernardo Dal Seno
    qa_node.TestExclStorSingleNode(node)
458 e8b919a1 Bernardo Dal Seno
459 e8b919a1 Bernardo Dal Seno
    qa_cluster.TestSetExclStorCluster(True)
460 21e2734f Bernardo Dal Seno
    qa_cluster.TestExclStorSharedPv(node)
461 21e2734f Bernardo Dal Seno
462 50ef6a41 Bernardo Dal Seno
    if qa_config.TestEnabled("instance-add-plain-disk"):
463 50ef6a41 Bernardo Dal Seno
      # Make sure that the cluster doesn't have any pre-existing problem
464 50ef6a41 Bernardo Dal Seno
      qa_cluster.AssertClusterVerify()
465 c99200a3 Bernardo Dal Seno
      instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
466 c99200a3 Bernardo Dal Seno
      instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
467 50ef6a41 Bernardo Dal Seno
      # cluster-verify checks that disks are allocated correctly
468 50ef6a41 Bernardo Dal Seno
      qa_cluster.AssertClusterVerify()
469 50ef6a41 Bernardo Dal Seno
      qa_instance.TestInstanceRemove(instance1)
470 50ef6a41 Bernardo Dal Seno
      qa_instance.TestInstanceRemove(instance2)
471 efd58d99 Bernardo Dal Seno
    if qa_config.TestEnabled("instance-add-drbd-disk"):
472 efd58d99 Bernardo Dal Seno
      snode = qa_config.AcquireNode()
473 efd58d99 Bernardo Dal Seno
      try:
474 efd58d99 Bernardo Dal Seno
        qa_cluster.TestSetExclStorCluster(False)
475 c99200a3 Bernardo Dal Seno
        instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
476 efd58d99 Bernardo Dal Seno
        qa_cluster.TestSetExclStorCluster(True)
477 efd58d99 Bernardo Dal Seno
        exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
478 efd58d99 Bernardo Dal Seno
        qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
479 efd58d99 Bernardo Dal Seno
        qa_instance.TestInstanceRemove(instance)
480 efd58d99 Bernardo Dal Seno
      finally:
481 efd58d99 Bernardo Dal Seno
        qa_config.ReleaseNode(snode)
482 50ef6a41 Bernardo Dal Seno
    qa_cluster.TestSetExclStorCluster(old_es)
483 50ef6a41 Bernardo Dal Seno
  finally:
484 50ef6a41 Bernardo Dal Seno
    qa_config.ReleaseNode(node)
485 50ef6a41 Bernardo Dal Seno
486 50ef6a41 Bernardo Dal Seno
487 ab4832d1 Bernardo Dal Seno
def _BuildSpecDict(par, mn, st, mx):
488 ab4832d1 Bernardo Dal Seno
  return {par: {"min": mn, "std": st, "max": mx}}
489 ab4832d1 Bernardo Dal Seno
490 ab4832d1 Bernardo Dal Seno
491 ab4832d1 Bernardo Dal Seno
def TestIPolicyPlainInstance():
492 ab4832d1 Bernardo Dal Seno
  """Test instance policy interaction with instances"""
493 ab4832d1 Bernardo Dal Seno
  params = ["mem-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
494 ab4832d1 Bernardo Dal Seno
  if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
495 ab4832d1 Bernardo Dal Seno
    print "Template %s not supported" % constants.DT_PLAIN
496 ab4832d1 Bernardo Dal Seno
    return
497 ab4832d1 Bernardo Dal Seno
498 ab4832d1 Bernardo Dal Seno
  # This test assumes that the group policy is empty
499 ab4832d1 Bernardo Dal Seno
  (_, old_specs) = qa_cluster.TestClusterSetISpecs({})
500 ab4832d1 Bernardo Dal Seno
  node = qa_config.AcquireNode()
501 ab4832d1 Bernardo Dal Seno
  try:
502 fa84c8a4 Bernardo Dal Seno
    # Log of policy changes, list of tuples: (change, policy_violated)
503 fa84c8a4 Bernardo Dal Seno
    history = []
504 ab4832d1 Bernardo Dal Seno
    instance = qa_instance.TestInstanceAddWithPlainDisk([node])
505 ab4832d1 Bernardo Dal Seno
    try:
506 ab4832d1 Bernardo Dal Seno
      policyerror = [constants.CV_EINSTANCEPOLICY]
507 ab4832d1 Bernardo Dal Seno
      for par in params:
508 ab4832d1 Bernardo Dal Seno
        qa_cluster.AssertClusterVerify()
509 ab4832d1 Bernardo Dal Seno
        (iminval, imaxval) = qa_instance.GetInstanceSpec(instance["name"], par)
510 ab4832d1 Bernardo Dal Seno
        # Some specs must be multiple of 4
511 ab4832d1 Bernardo Dal Seno
        new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
512 fa84c8a4 Bernardo Dal Seno
        history.append((new_spec, True))
513 ab4832d1 Bernardo Dal Seno
        qa_cluster.TestClusterSetISpecs(new_spec)
514 ab4832d1 Bernardo Dal Seno
        qa_cluster.AssertClusterVerify(warnings=policyerror)
515 ab4832d1 Bernardo Dal Seno
        if iminval > 0:
516 ab4832d1 Bernardo Dal Seno
          # Some specs must be multiple of 4
517 ab4832d1 Bernardo Dal Seno
          if iminval >= 4:
518 ab4832d1 Bernardo Dal Seno
            upper = iminval - 4
519 ab4832d1 Bernardo Dal Seno
          else:
520 ab4832d1 Bernardo Dal Seno
            upper = iminval - 1
521 ab4832d1 Bernardo Dal Seno
          new_spec = _BuildSpecDict(par, 0, upper, upper)
522 fa84c8a4 Bernardo Dal Seno
          history.append((new_spec, True))
523 ab4832d1 Bernardo Dal Seno
          qa_cluster.TestClusterSetISpecs(new_spec)
524 ab4832d1 Bernardo Dal Seno
          qa_cluster.AssertClusterVerify(warnings=policyerror)
525 ab4832d1 Bernardo Dal Seno
        qa_cluster.TestClusterSetISpecs(old_specs)
526 fa84c8a4 Bernardo Dal Seno
        history.append((old_specs, False))
527 ab4832d1 Bernardo Dal Seno
      qa_instance.TestInstanceRemove(instance)
528 ab4832d1 Bernardo Dal Seno
    finally:
529 ab4832d1 Bernardo Dal Seno
      qa_config.ReleaseInstance(instance)
530 fa84c8a4 Bernardo Dal Seno
531 fa84c8a4 Bernardo Dal Seno
    # Now we replay the same policy changes, and we expect that the instance
532 fa84c8a4 Bernardo Dal Seno
    # cannot be created for the cases where we had a policy violation above
533 fa84c8a4 Bernardo Dal Seno
    for (change, failed) in history:
534 fa84c8a4 Bernardo Dal Seno
      qa_cluster.TestClusterSetISpecs(change)
535 fa84c8a4 Bernardo Dal Seno
      if failed:
536 fa84c8a4 Bernardo Dal Seno
        qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
537 fa84c8a4 Bernardo Dal Seno
      # Instance creation with no policy violation has been tested already
538 ab4832d1 Bernardo Dal Seno
  finally:
539 ab4832d1 Bernardo Dal Seno
    qa_config.ReleaseNode(node)
540 ab4832d1 Bernardo Dal Seno
541 ab4832d1 Bernardo Dal Seno
542 deadfa13 Bernardo Dal Seno
def RunInstanceTests():
543 deadfa13 Bernardo Dal Seno
  """Create and exercise instances."""
544 deadfa13 Bernardo Dal Seno
  instance_tests = [
545 deadfa13 Bernardo Dal Seno
    ("instance-add-plain-disk", constants.DT_PLAIN,
546 deadfa13 Bernardo Dal Seno
     qa_instance.TestInstanceAddWithPlainDisk, 1),
547 deadfa13 Bernardo Dal Seno
    ("instance-add-drbd-disk", constants.DT_DRBD8,
548 deadfa13 Bernardo Dal Seno
     qa_instance.TestInstanceAddWithDrbdDisk, 2),
549 deadfa13 Bernardo Dal Seno
  ]
550 deadfa13 Bernardo Dal Seno
551 deadfa13 Bernardo Dal Seno
  for (test_name, templ, create_fun, num_nodes) in instance_tests:
552 deadfa13 Bernardo Dal Seno
    if (qa_config.TestEnabled(test_name) and
553 deadfa13 Bernardo Dal Seno
        qa_config.IsTemplateSupported(templ)):
554 deadfa13 Bernardo Dal Seno
      inodes = qa_config.AcquireManyNodes(num_nodes)
555 deadfa13 Bernardo Dal Seno
      try:
556 deadfa13 Bernardo Dal Seno
        instance = RunTest(create_fun, inodes)
557 deadfa13 Bernardo Dal Seno
558 deadfa13 Bernardo Dal Seno
        RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
559 deadfa13 Bernardo Dal Seno
        RunDaemonTests(instance)
560 deadfa13 Bernardo Dal Seno
        for node in inodes:
561 deadfa13 Bernardo Dal Seno
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
562 deadfa13 Bernardo Dal Seno
        if len(inodes) > 1:
563 deadfa13 Bernardo Dal Seno
          RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
564 deadfa13 Bernardo Dal Seno
                    constants.INITIAL_NODE_GROUP_NAME,
565 deadfa13 Bernardo Dal Seno
                    inodes[0]["primary"], inodes[1]["primary"])
566 deadfa13 Bernardo Dal Seno
        if qa_config.TestEnabled("instance-convert-disk"):
567 deadfa13 Bernardo Dal Seno
          RunTest(qa_instance.TestInstanceShutdown, instance)
568 deadfa13 Bernardo Dal Seno
          RunTest(qa_instance.TestInstanceConvertDiskToPlain, instance, inodes)
569 deadfa13 Bernardo Dal Seno
          RunTest(qa_instance.TestInstanceStartup, instance)
570 deadfa13 Bernardo Dal Seno
        RunCommonInstanceTests(instance)
571 deadfa13 Bernardo Dal Seno
        RunGroupListTests()
572 deadfa13 Bernardo Dal Seno
        RunExportImportTests(instance, inodes)
573 deadfa13 Bernardo Dal Seno
        RunHardwareFailureTests(instance, inodes)
574 deadfa13 Bernardo Dal Seno
        RunRepairDiskSizes()
575 deadfa13 Bernardo Dal Seno
        RunTest(qa_instance.TestInstanceRemove, instance)
576 deadfa13 Bernardo Dal Seno
        del instance
577 deadfa13 Bernardo Dal Seno
      finally:
578 deadfa13 Bernardo Dal Seno
        qa_config.ReleaseManyNodes(inodes)
579 deadfa13 Bernardo Dal Seno
      qa_cluster.AssertClusterVerify()
580 deadfa13 Bernardo Dal Seno
581 deadfa13 Bernardo Dal Seno
582 f7e6f3c8 Iustin Pop
def RunQa():
583 f7e6f3c8 Iustin Pop
  """Main QA body.
584 b1ffe1eb Michael Hanselmann

585 b1ffe1eb Michael Hanselmann
  """
586 725ec2f1 René Nussbaumer
  rapi_user = "ganeti-qa"
587 725ec2f1 René Nussbaumer
  rapi_secret = utils.GenerateSecret()
588 725ec2f1 René Nussbaumer
589 b1ffe1eb Michael Hanselmann
  RunEnvTests()
590 725ec2f1 René Nussbaumer
  SetupCluster(rapi_user, rapi_secret)
591 2771835c Michael Hanselmann
592 2771835c Michael Hanselmann
  # Load RAPI certificate
593 76917d97 Iustin Pop
  qa_rapi.Setup(rapi_user, rapi_secret)
594 2771835c Michael Hanselmann
595 b1ffe1eb Michael Hanselmann
  RunClusterTests()
596 b1ffe1eb Michael Hanselmann
  RunOsTests()
597 4b62db14 Michael Hanselmann
598 7d88f255 Iustin Pop
  RunTestIf("tags", qa_tags.TestClusterTags)
599 d74c2ca1 Michael Hanselmann
600 729c4377 Iustin Pop
  RunCommonNodeTests()
601 30131294 Adeodato Simo
  RunGroupListTests()
602 66787da5 Adeodato Simo
  RunGroupRwTests()
603 729c4377 Iustin Pop
604 6f058bf2 Bernardo Dal Seno
  # The master shouldn't be readded or put offline; "delay" needs a non-master
605 6f058bf2 Bernardo Dal Seno
  # node to test
606 d0cb68cb Michael Hanselmann
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
607 d0cb68cb Michael Hanselmann
  try:
608 7d88f255 Iustin Pop
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
609 7d88f255 Iustin Pop
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
610 5a85b99e Michael Hanselmann
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
611 d0cb68cb Michael Hanselmann
  finally:
612 d0cb68cb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
613 102b115b Michael Hanselmann
614 a36f690c Bernardo Dal Seno
  # Make sure the cluster is clean before running instance tests
615 a36f690c Bernardo Dal Seno
  qa_cluster.AssertClusterVerify()
616 a36f690c Bernardo Dal Seno
617 b1ffe1eb Michael Hanselmann
  pnode = qa_config.AcquireNode()
618 b1ffe1eb Michael Hanselmann
  try:
619 7d88f255 Iustin Pop
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
620 d74c2ca1 Michael Hanselmann
621 a47f574c Oleksiy Mishchenko
    if qa_rapi.Enabled():
622 a47f574c Oleksiy Mishchenko
      RunTest(qa_rapi.TestNode, pnode)
623 a47f574c Oleksiy Mishchenko
624 8cb70e56 Michael Hanselmann
      if qa_config.TestEnabled("instance-add-plain-disk"):
625 924e95f9 Michael Hanselmann
        for use_client in [True, False]:
626 924e95f9 Michael Hanselmann
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
627 924e95f9 Michael Hanselmann
                                  use_client)
628 b498540e Iustin Pop
          if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
629 b498540e Iustin Pop
            RunCommonInstanceTests(rapi_instance)
630 924e95f9 Michael Hanselmann
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
631 924e95f9 Michael Hanselmann
          del rapi_instance
632 8cb70e56 Michael Hanselmann
633 6f058bf2 Bernardo Dal Seno
  finally:
634 6f058bf2 Bernardo Dal Seno
    qa_config.ReleaseNode(pnode)
635 6f058bf2 Bernardo Dal Seno
636 deadfa13 Bernardo Dal Seno
  config_list = [
637 deadfa13 Bernardo Dal Seno
    ("default-instance-tests", lambda: None, lambda _: None),
638 deadfa13 Bernardo Dal Seno
    ("exclusive-storage-instance-tests",
639 deadfa13 Bernardo Dal Seno
     lambda: qa_cluster.TestSetExclStorCluster(True),
640 deadfa13 Bernardo Dal Seno
     qa_cluster.TestSetExclStorCluster),
641 27eba428 Bernardo Dal Seno
  ]
642 deadfa13 Bernardo Dal Seno
  for (conf_name, setup_conf_f, restore_conf_f) in config_list:
643 deadfa13 Bernardo Dal Seno
    if qa_config.TestEnabled(conf_name):
644 deadfa13 Bernardo Dal Seno
      oldconf = setup_conf_f()
645 deadfa13 Bernardo Dal Seno
      RunInstanceTests()
646 deadfa13 Bernardo Dal Seno
      restore_conf_f(oldconf)
647 c7e54e1d Agata Murawska
648 6f058bf2 Bernardo Dal Seno
  pnode = qa_config.AcquireNode()
649 6f058bf2 Bernardo Dal Seno
  try:
650 7d88f255 Iustin Pop
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
651 3b01286e Michael Hanselmann
      for shutdown in [False, True]:
652 c99200a3 Bernardo Dal Seno
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
653 3b01286e Michael Hanselmann
        expnode = qa_config.AcquireNode(exclude=pnode)
654 3b01286e Michael Hanselmann
        try:
655 3b01286e Michael Hanselmann
          if shutdown:
656 3b01286e Michael Hanselmann
            # Stop instance before exporting and removing it
657 3b01286e Michael Hanselmann
            RunTest(qa_instance.TestInstanceShutdown, instance)
658 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
659 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestBackupList, expnode)
660 3b01286e Michael Hanselmann
        finally:
661 3b01286e Michael Hanselmann
          qa_config.ReleaseNode(expnode)
662 3b01286e Michael Hanselmann
        del expnode
663 3b01286e Michael Hanselmann
        del instance
664 a36f690c Bernardo Dal Seno
      qa_cluster.AssertClusterVerify()
665 8d8d650c Michael Hanselmann
666 a8083063 Iustin Pop
  finally:
667 b1ffe1eb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
668 a8083063 Iustin Pop
669 50ef6a41 Bernardo Dal Seno
  RunExclusiveStorageTests()
670 ab4832d1 Bernardo Dal Seno
  RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
671 ab4832d1 Bernardo Dal Seno
            TestIPolicyPlainInstance)
672 50ef6a41 Bernardo Dal Seno
673 a36f690c Bernardo Dal Seno
  # Test removing instance with offline drbd secondary
674 a36f690c Bernardo Dal Seno
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
675 a36f690c Bernardo Dal Seno
    # Make sure the master is not put offline
676 a36f690c Bernardo Dal Seno
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
677 a36f690c Bernardo Dal Seno
    try:
678 a36f690c Bernardo Dal Seno
      pnode = qa_config.AcquireNode(exclude=snode)
679 a36f690c Bernardo Dal Seno
      try:
680 a36f690c Bernardo Dal Seno
        instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
681 f006f110 Bernardo Dal Seno
        set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
682 f006f110 Bernardo Dal Seno
        set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
683 f006f110 Bernardo Dal Seno
        RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
684 f006f110 Bernardo Dal Seno
                set_offline, set_online)
685 a36f690c Bernardo Dal Seno
      finally:
686 a36f690c Bernardo Dal Seno
        qa_config.ReleaseNode(pnode)
687 a36f690c Bernardo Dal Seno
    finally:
688 a36f690c Bernardo Dal Seno
      qa_config.ReleaseNode(snode)
689 f006f110 Bernardo Dal Seno
    qa_cluster.AssertClusterVerify()
690 a36f690c Bernardo Dal Seno
691 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
692 a8083063 Iustin Pop
693 7d88f255 Iustin Pop
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
694 a8083063 Iustin Pop
695 cec9845c Michael Hanselmann
696 fc3f75dd Iustin Pop
@UsesRapiClient
697 f7e6f3c8 Iustin Pop
def main():
698 f7e6f3c8 Iustin Pop
  """Main program.
699 f7e6f3c8 Iustin Pop

700 f7e6f3c8 Iustin Pop
  """
701 f7e6f3c8 Iustin Pop
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
702 d0c8c01d Iustin Pop
  parser.add_option("--yes-do-it", dest="yes_do_it",
703 5ae4945a Iustin Pop
                    action="store_true",
704 5ae4945a Iustin Pop
                    help="Really execute the tests")
705 f7e6f3c8 Iustin Pop
  (qa_config.options, args) = parser.parse_args()
706 f7e6f3c8 Iustin Pop
707 f7e6f3c8 Iustin Pop
  if len(args) == 1:
708 f7e6f3c8 Iustin Pop
    (config_file, ) = args
709 f7e6f3c8 Iustin Pop
  else:
710 f7e6f3c8 Iustin Pop
    parser.error("Wrong number of arguments.")
711 f7e6f3c8 Iustin Pop
712 f7e6f3c8 Iustin Pop
  if not qa_config.options.yes_do_it:
713 f7e6f3c8 Iustin Pop
    print ("Executing this script irreversibly destroys any Ganeti\n"
714 f7e6f3c8 Iustin Pop
           "configuration on all nodes involved. If you really want\n"
715 f7e6f3c8 Iustin Pop
           "to start testing, supply the --yes-do-it option.")
716 f7e6f3c8 Iustin Pop
    sys.exit(1)
717 f7e6f3c8 Iustin Pop
718 f7e6f3c8 Iustin Pop
  qa_config.Load(config_file)
719 f7e6f3c8 Iustin Pop
720 710bc88c Iustin Pop
  primary = qa_config.GetMasterNode()["primary"]
721 710bc88c Iustin Pop
  qa_utils.StartMultiplexer(primary)
722 710bc88c Iustin Pop
  print ("SSH command for primary node: %s" %
723 710bc88c Iustin Pop
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
724 710bc88c Iustin Pop
  print ("SSH command for other nodes: %s" %
725 710bc88c Iustin Pop
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
726 f7e6f3c8 Iustin Pop
  try:
727 f7e6f3c8 Iustin Pop
    RunQa()
728 f7e6f3c8 Iustin Pop
  finally:
729 f7e6f3c8 Iustin Pop
    qa_utils.CloseMultiplexers()
730 f7e6f3c8 Iustin Pop
731 d0c8c01d Iustin Pop
if __name__ == "__main__":
732 cec9845c Michael Hanselmann
  main()