1 |
1 |
#
|
2 |
2 |
#
|
3 |
3 |
|
4 |
|
# Copyright (C) 2012 Google Inc.
|
|
4 |
# Copyright (C) 2012, 2014 Google Inc.
|
5 |
5 |
#
|
6 |
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
7 |
# it under the terms of the GNU General Public License as published by
|
... | ... | |
23 |
23 |
|
24 |
24 |
"""
|
25 |
25 |
|
|
26 |
from ganeti import constants
|
26 |
27 |
from ganeti import query
|
27 |
28 |
|
|
29 |
import re
|
|
30 |
import time
|
|
31 |
|
|
32 |
import qa_config
|
|
33 |
import qa_error
|
28 |
34 |
import qa_utils
|
29 |
35 |
|
|
36 |
from qa_utils import AssertCommand, GetCommandOutput
|
|
37 |
|
30 |
38 |
|
31 |
39 |
def TestJobList():
|
32 |
40 |
"""gnt-job list"""
|
... | ... | |
37 |
45 |
def TestJobListFields():
|
38 |
46 |
"""gnt-node list-fields"""
|
39 |
47 |
qa_utils.GenericQueryFieldsTest("gnt-job", query.JOB_FIELDS.keys())
|
|
48 |
|
|
49 |
|
|
50 |
def _GetJobStatuses():
|
|
51 |
""" Invokes gnt-job list and extracts an id to status dictionary.
|
|
52 |
|
|
53 |
@rtype: dict of string to string
|
|
54 |
@return: A dictionary mapping job ids to matching statuses
|
|
55 |
|
|
56 |
"""
|
|
57 |
master = qa_config.GetMasterNode()
|
|
58 |
list_output = GetCommandOutput(
|
|
59 |
master.primary, "gnt-job list --no-headers --output=id,status"
|
|
60 |
)
|
|
61 |
return dict(map(lambda s: s.split(), list_output.splitlines()))
|
|
62 |
|
|
63 |
|
|
64 |
def TestJobCancellation():
|
|
65 |
"""gnt-job cancel"""
|
|
66 |
# The delay used for the first command should be large enough for the next
|
|
67 |
# command and the cancellation command to complete before the first job is
|
|
68 |
# done. The second delay should be small enough that not too much time is
|
|
69 |
# spend waiting in the case of a failed cancel and a running command.
|
|
70 |
FIRST_COMMAND_DELAY = 10.0
|
|
71 |
AssertCommand(["gnt-debug", "delay", "--submit", str(FIRST_COMMAND_DELAY)])
|
|
72 |
|
|
73 |
SECOND_COMMAND_DELAY = 1.0
|
|
74 |
master = qa_config.GetMasterNode()
|
|
75 |
|
|
76 |
# Forcing tty usage does not work on buildbot, so force all output of this
|
|
77 |
# command to be redirected to stdout
|
|
78 |
job_id_output = GetCommandOutput(
|
|
79 |
master.primary, "gnt-debug delay --submit %s 2>&1" % SECOND_COMMAND_DELAY
|
|
80 |
)
|
|
81 |
|
|
82 |
possible_job_ids = re.findall("JobID: ([0-9]+)", job_id_output)
|
|
83 |
if len(possible_job_ids) != 1:
|
|
84 |
raise qa_error.Error("Cannot parse gnt-debug delay output to find job id")
|
|
85 |
|
|
86 |
job_id = possible_job_ids[0]
|
|
87 |
AssertCommand(["gnt-job", "cancel", job_id])
|
|
88 |
|
|
89 |
# Now wait until the second job finishes, and expect the watch to fail due to
|
|
90 |
# job cancellation
|
|
91 |
AssertCommand(["gnt-job", "watch", job_id], fail=True)
|
|
92 |
|
|
93 |
# Then check for job cancellation
|
|
94 |
status_dict = _GetJobStatuses()
|
|
95 |
if status_dict.get(job_id, None) != constants.JOB_STATUS_CANCELED:
|
|
96 |
raise qa_error.Error("Job was not successfully cancelled!")
|