blob: 377d3df4e4e0f233101bc5d963f34f79a148c483 [file] [log] [blame]
Fang Dengaf30e7c2014-11-15 13:57:03 -08001# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""This file defines tasks to be executed in provision actions."""
6
7import abc
8import logging
9
10import common
11
12
13class BaseActionable(object):
14 """Base class of an actionable item."""
15
16 @abc.abstractmethod
17 def execute(self, job, host, *args, **kwargs):
18 """Execute the action item.
19
20 @param job: A job object from a control file.
21 @param host: A host to run this action against.
22 @param args: arguments to passed to the test.
23 @param kwargs: keyword arguments to passed to the test.
24
25 @returns True if succeeds, False otherwise,
26 subclass should override this method.
27 """
28 raise NotImplementedError('Subclass should override execute.')
29
30
31class TestActionable(BaseActionable):
32 """A test to be executed as an action"""
33
34 def __init__(self, test):
35 """Init method.
36
37 @param test: String, the test to run, e.g. dummy_PassServer
38 """
39 self.test = test
40
41
42 def execute(self, job, host, *args, **kwargs):
43 """Execute the action item.
44
45 @param job: A job object from a control file.
46 @param host: A host to run this action against.
47 @param args: arguments to passed to the test.
48 @param kwargs: keyword arguments to passed to the test.
49
50 @returns True if succeeds, False otherwise.
51 """
52 return job.run_test(self.test, host=host, *args, **kwargs)
53
54
55class RebootActionable(BaseActionable):
56 """Reboot action."""
57
58 def execute(self, job, host, *args, **kwargs):
59 """Execute the action item.
60
61 @param job: A job object from a control file.
62 @param host: A host to run this action against.
63 @param args: arguments to passed to the test.
64 @param kwargs: keyword arguments to passed to the test.
65
66 @returns True if succeeds.
67 """
68 logging.error('Executing RebootActionable ... ')
69 host.reboot()
70 logging.error('RebootActionable execution succeeds. ')
71 return True