1# Copyright 2016 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"""Feedback request interface."""
6
7
8class FeedbackRequestError(Exception):
9    """An error during feedback request processing."""
10
11
12class FeedbackRequest(object):
13    """A abstract class for managing a single feedback request."""
14
15    _TITLE_TEMPLATE = '%(desc)s request from %(dut)s (%(test)s)'
16
17    def __init__(self, test, dut, desc):
18        """Initializes the request object.
19
20        @param test: The test name.
21        @param dut: The DUT name.
22        @param desc: A one-liner describing the essence of the request.
23        """
24        self.test = test
25        self.dut = dut
26        self.desc = desc
27
28
29    def get_title(self):
30        """Returns the request descriptive title.
31
32        This method is used by the resuest multiplexer to obtain a list of
33        pending request titles.
34
35        @return: A short string describing the request and who made it.
36        """
37        return (self._TITLE_TEMPLATE %
38                {'test': self.test, 'dut': self.dut, 'desc': self.desc})
39
40
41    def execute(self):
42        """Executes the feedback request.
43
44        @return: The result of processing the request. This value varies
45                 depending on the request type and is up to the invoking
46                 delegate to evaluate and act upon.
47
48        @raise FeedbackRequestError: Failed to execute the request.
49        """
50        raise NotImplementedError
51