Revision a1de4b18 qa/qa_node.py

b/qa/qa_node.py
22 22
from ganeti import utils
23 23
from ganeti import constants
24 24
from ganeti import query
25
from ganeti import serializer
25 26

  
26 27
import qa_config
27 28
import qa_error
......
192 193
                 "--auto-promote", node["primary"]])
193 194

  
194 195

  
196
def _CreateOobScriptStructure():
197
  """Create a simple OOB handling script and its structure."""
198
  master = qa_config.GetMasterNode()
199

  
200
  data_path = qa_utils.UploadData(master["primary"], "")
201
  verify_path = qa_utils.UploadData(master["primary"], "")
202
  exit_code_path = qa_utils.UploadData(master["primary"], "")
203

  
204
  oob_script = (("#!/bin/bash\n"
205
                 "echo \"$@\" > %s\n"
206
                 "cat %s\n"
207
                 "exit $(< %s)\n") %
208
                (utils.ShellQuote(verify_path), utils.ShellQuote(data_path),
209
                 utils.ShellQuote(exit_code_path)))
210
  oob_path = qa_utils.UploadData(master["primary"], oob_script, mode=0700)
211

  
212
  return [oob_path, verify_path, data_path, exit_code_path]
213

  
214

  
215
def _UpdateOobFile(path, data):
216
  """Updates the data file with data."""
217
  master = qa_config.GetMasterNode()
218
  qa_utils.UploadData(master["primary"], data, filename=path)
219

  
220

  
221
def _AssertOobCall(verify_path, expected_args):
222
  """Assert the OOB call was performed with expetected args."""
223
  master = qa_config.GetMasterNode()
224

  
225
  verify_output_cmd = utils.ShellQuoteArgs(["cat", verify_path])
226
  output = qa_utils.GetCommandOutput(master["primary"], verify_output_cmd)
227

  
228
  qa_utils.AssertEqual(expected_args, output.strip())
229

  
230

  
231
def TestOutOfBand():
232
  """gnt-node power"""
233
  master = qa_config.GetMasterNode()
234

  
235
  (oob_path, verify_path,
236
   data_path, exit_code_path) = _CreateOobScriptStructure()
237

  
238
  try:
239
    AssertCommand(["gnt-cluster", "modify", "--node-parameters",
240
                   "oob_program=%s" % oob_path])
241

  
242
    # No data, exit 0
243
    _UpdateOobFile(exit_code_path, "0")
244

  
245
    AssertCommand(["gnt-node", "power", "on", master["primary"]])
246
    _AssertOobCall(verify_path, "power-on %s" % master["primary"])
247

  
248
    AssertCommand(["gnt-node", "power", "off", master["primary"]])
249
    _AssertOobCall(verify_path, "power-off %s" % master["primary"])
250

  
251
    AssertCommand(["gnt-node", "power", "cycle", master["primary"]])
252
    _AssertOobCall(verify_path, "power-cycle %s" % master["primary"])
253

  
254
    # This command should fail as it expects output which isn't provided yet
255
    # But it should have called the oob helper nevermind
256
    AssertCommand(["gnt-node", "power", "status", master["primary"]],
257
                  fail=True)
258
    _AssertOobCall(verify_path, "power-status %s" % master["primary"])
259

  
260
    # Data, exit 0
261
    _UpdateOobFile(data_path, serializer.DumpJson({ "powered": True }))
262

  
263
    AssertCommand(["gnt-node", "power", "status", master["primary"]])
264
    _AssertOobCall(verify_path, "power-status %s" % master["primary"])
265

  
266
    AssertCommand(["gnt-node", "power", "on", master["primary"]], fail=True)
267
    _AssertOobCall(verify_path, "power-on %s" % master["primary"])
268

  
269
    AssertCommand(["gnt-node", "power", "off", master["primary"]], fail=True)
270
    _AssertOobCall(verify_path, "power-off %s" % master["primary"])
271

  
272
    AssertCommand(["gnt-node", "power", "cycle", master["primary"]], fail=True)
273
    _AssertOobCall(verify_path, "power-cycle %s" % master["primary"])
274

  
275
    # Data, exit 1 (all should fail)
276
    _UpdateOobFile(exit_code_path, "1")
277

  
278
    AssertCommand(["gnt-node", "power", "on", master["primary"]], fail=True)
279
    _AssertOobCall(verify_path, "power-on %s" % master["primary"])
280

  
281
    AssertCommand(["gnt-node", "power", "off", master["primary"]], fail=True)
282
    _AssertOobCall(verify_path, "power-off %s" % master["primary"])
283

  
284
    AssertCommand(["gnt-node", "power", "cycle", master["primary"]], fail=True)
285
    _AssertOobCall(verify_path, "power-cycle %s" % master["primary"])
286

  
287
    AssertCommand(["gnt-node", "power", "status", master["primary"]],
288
                  fail=True)
289
    _AssertOobCall(verify_path, "power-status %s" % master["primary"])
290

  
291
    # No data, exit 1 (all should fail)
292
    _UpdateOobFile(data_path, "")
293
    AssertCommand(["gnt-node", "power", "on", master["primary"]], fail=True)
294
    _AssertOobCall(verify_path, "power-on %s" % master["primary"])
295

  
296
    AssertCommand(["gnt-node", "power", "off", master["primary"]], fail=True)
297
    _AssertOobCall(verify_path, "power-off %s" % master["primary"])
298

  
299
    AssertCommand(["gnt-node", "power", "cycle", master["primary"]], fail=True)
300
    _AssertOobCall(verify_path, "power-cycle %s" % master["primary"])
301

  
302
    AssertCommand(["gnt-node", "power", "status", master["primary"]],
303
                  fail=True)
304
    _AssertOobCall(verify_path, "power-status %s" % master["primary"])
305

  
306
    # Different OOB script for node
307
    verify_path2 = qa_utils.UploadData(master["primary"], "")
308
    oob_script = ("#!/bin/sh\n"
309
                  "echo \"$@\" > %s\n") % verify_path2
310
    oob_path2 = qa_utils.UploadData(master["primary"], oob_script, mode=0700)
311

  
312
    try:
313
      AssertCommand(["gnt-node", "modify", "--node-parameters",
314
                     "oob_program=%s" % oob_path2, master["primary"]])
315
      AssertCommand(["gnt-node", "power", "on", master["primary"]])
316
      _AssertOobCall(verify_path2, "power-on %s" % master["primary"])
317
    finally:
318
      AssertCommand(["gnt-node", "modify", "--node-parameters",
319
                     "oob_program=default", master["primary"]])
320
      AssertCommand(["rm", "-f", oob_path2, verify_path2])
321
  finally:
322
    AssertCommand(["gnt-cluster", "modify", "--node-parameters",
323
                   "oob_program=default"])
324
    AssertCommand(["rm", "-f", oob_path, verify_path, data_path,
325
                   exit_code_path])
326

  
327

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

Also available in: Unified diff