-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcancel.py
73 lines (57 loc) · 2.71 KB
/
cancel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Cancels tests as prescribed by the user."""
import errno
import time
from argparse import Namespace
from pavilion import cancel_utils
from pavilion import cmd_utils
from pavilion import filters
from pavilion import output
from pavilion import series
from pavilion.errors import TestSeriesError
from pavilion.test_run import TestRun
from pavilion.config import PavConfig
from pavilion.test_ids import TestID, SeriesID
from pavilion.micro import partition, listmap
from .base_classes import Command
from ..errors import TestRunError
class CancelCommand(Command):
"""Cancel a set of commands using the appropriate scheduler."""
def __init__(self):
super().__init__(
'cancel',
'Cancel a test, tests, or all tests in a test series. To cancel a series '
'itself, use `pav series cancel`. Tests can only be cancelled on the system '
'where they were started.',
short_help="Cancel a test, tests, or all tests in a test series."
)
def _setup_arguments(self, parser):
parser.add_argument(
'-s', '--status', action='store_true', default=False,
help='Prints status of cancelled jobs.'
)
parser.add_argument(
'tests', nargs='*', action='store',
help='The name(s) of the tests to cancel. These may be any mix of '
'test IDs and series IDs. If no value is provided, all test '
'in the most recent series submitted by the user is cancelled.')
filters.add_test_filter_args(parser, sort_keys=[], disable_opts=['sys-name'])
def run(self, pav_cfg: PavConfig, args: Namespace) -> int:
"""Cancel the given tests or series."""
if len(args.tests) == 0:
# Get the last series ran by this user.
series_id = series.load_user_series_id(pav_cfg)
if series_id is not None:
args.tests.append(series_id)
# Separate out into tests and series
series_ids, test_ids = partition(SeriesID.is_valid_id, args.tests)
args.tests = list(test_ids)
args.series = list(series_ids)
# Get TestRun and TestSeries objects
test_paths = cmd_utils.arg_filtered_tests(pav_cfg, args, verbose=self.errfile).paths
tests = cmd_utils.get_tests_by_paths(pav_cfg, test_paths, errfile=self.errfile)
sinfos = cmd_utils.arg_filtered_series(pav_cfg, args, verbose=self.errfile)
test_series = map(lambda x: series.TestSeries.load(pav_cfg, x.sid), sinfos)
# Cancel TestRuns and TestSeries
test_ret = cancel_utils.cancel_tests(pav_cfg, tests, self.outfile)
sers_ret = cancel_utils.cancel_series(test_series, self.outfile)
return test_ret or sers_ret