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 5import common 6from autotest_lib.client.common_lib import error 7from autotest_lib.server import site_utils 8 9 10_AVAILABLE_AUDIO_CLIENTS = set(('loop', 'interactive')) 11 12 13def _get_client(fb_client_name, available_clients, test_name, machine, 14 args_str): 15 """Instantiates a feedback client. 16 17 @param fb_client_name: Name of the desired client. 18 @param available_clients: Set of available client names to choose from. 19 @param test_name: The name of the test. 20 @param machine: A dictionary describing the test host and DUT. 21 @param args_str: String containing comma-separate, implementation-specific 22 arguments. 23 24 @return An instance of client.common_lib.feedback.client.Client. 25 26 @raise error.TestError: Requested client is invalid/unavailable/unknown. 27 """ 28 if not fb_client_name: 29 raise error.TestError('Feedback client name is empty') 30 if fb_client_name not in available_clients: 31 raise error.TestError( 32 'Feedback client (%s) is unknown or unavailble for this test' % 33 fb_client_name) 34 35 hostname = site_utils.get_hostname_from_machine(machine) 36 afe_host = site_utils.get_afe_host_from_machine(machine) 37 serials = afe_host.attributes.get('serials') 38 dut_name = '%s-%s' % (hostname, serials) 39 args = args_str.split(',') if args_str else [] 40 41 if fb_client_name == 'loop': 42 from autotest_lib.server.brillo.feedback import closed_loop_audio_client 43 return closed_loop_audio_client.Client(*args) 44 elif fb_client_name == 'interactive': 45 from autotest_lib.client.common_lib.feedback import tester_feedback_client 46 return tester_feedback_client.Client(test_name, dut_name, *args) 47 else: 48 raise error.TestError( 49 'Feedback client (%s) unknown despite being listed as ' 50 'available for this test' % fb_client_name) 51 52 53def get_audio_client(fb_client_name, test_name, machine, args_str): 54 """Instantiates an audio feedback client.""" 55 return _get_client(fb_client_name, _AVAILABLE_AUDIO_CLIENTS, test_name, 56 machine, args_str) 57