1#!/usr/bin/env python3 2# 3# Copyright 2017 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import enum 18"""This module has the global key values that are used across framework 19modules. 20""" 21 22 23class Config(enum.Enum): 24 """Enum values for test config related lookups. 25 """ 26 # Keys used to look up values from test config files. 27 # These keys define the wording of test configs and their internal 28 # references. 29 key_log_path = 'logpath' 30 key_testbeds_under_test = 'testbeds_under_test' 31 key_testbed = 'testbed' 32 key_testbed_name = 'name' 33 # configpath is the directory. key_config_full_path is the file path. 34 key_config_path = 'configpath' 35 key_config_full_path = 'config_full_path' 36 key_test_paths = 'testpaths' 37 key_port = 'Port' 38 key_address = 'Address' 39 key_test_case_iterations = 'test_case_iterations' 40 key_test_failure_tracebacks = 'test_failure_tracebacks' 41 # Config names for controllers packaged in ACTS. 42 key_android_device = 'AndroidDevice' 43 key_bluetooth_pts_device = 'BluetoothPtsDevice' 44 key_fuchsia_device = 'FuchsiaDevice' 45 key_buds_device = 'BudsDevice' 46 key_chameleon_device = 'ChameleonDevice' 47 key_native_android_device = 'NativeAndroidDevice' 48 key_relay_device = 'RelayDevice' 49 key_access_point = 'AccessPoint' 50 key_attenuator = 'Attenuator' 51 key_iperf_server = 'IPerfServer' 52 key_iperf_client = 'IPerfClient' 53 key_packet_sender = 'PacketSender' 54 key_monsoon = 'Monsoon' 55 key_sniffer = 'Sniffer' 56 key_arduino_wifi_dongle = 'ArduinoWifiDongle' 57 key_packet_capture = 'PacketCapture' 58 key_openwrt_ap = 'OpenWrtAP' 59 # Internal keys, used internally, not exposed to user's config files. 60 ikey_user_param = 'user_params' 61 ikey_testbed_name = 'testbed_name' 62 ikey_logger = 'log' 63 ikey_logpath = 'log_path' 64 ikey_summary_writer = 'summary_writer' 65 # module name of controllers packaged in ACTS. 66 m_key_monsoon = 'monsoon' 67 m_key_android_device = 'android_device' 68 m_key_fuchsia_device = 'fuchsia_device' 69 m_key_bluetooth_pts_device = 'bluetooth_pts_device' 70 m_key_buds_device = 'buds_controller' 71 m_key_chameleon_device = 'chameleon_controller' 72 m_key_native_android_device = 'native_android_device' 73 m_key_relay_device = 'relay_device_controller' 74 m_key_access_point = 'access_point' 75 m_key_attenuator = 'attenuator' 76 m_key_iperf_server = 'iperf_server' 77 m_key_iperf_client = 'iperf_client' 78 m_key_packet_sender = 'packet_sender' 79 m_key_sniffer = 'sniffer' 80 m_key_arduino_wifi_dongle = 'arduino_wifi_dongle' 81 m_key_packet_capture = 'packet_capture' 82 m_key_openwrt_ap = 'openwrt_ap' 83 84 # A list of keys whose values in configs should not be passed to test 85 # classes without unpacking first. 86 reserved_keys = (key_testbed, key_log_path, key_test_paths) 87 88 # Controller names packaged with ACTS. 89 builtin_controller_names = [ 90 key_android_device, 91 key_bluetooth_pts_device, 92 key_fuchsia_device, 93 key_buds_device, 94 key_native_android_device, 95 key_relay_device, 96 key_access_point, 97 key_attenuator, 98 key_iperf_server, 99 key_iperf_client, 100 key_packet_sender, 101 key_monsoon, 102 key_sniffer, 103 key_chameleon_device, 104 key_arduino_wifi_dongle, 105 key_packet_capture, 106 key_openwrt_ap, 107 ] 108 109 # Keys that are file or folder paths. 110 file_path_keys = [key_relay_device] 111 112 113def get_name_by_value(value): 114 for name, member in Config.__members__.items(): 115 if member.value == value: 116 return name 117 return None 118 119 120def get_module_name(name_in_config): 121 """Translates the name of a controller in config file to its module name. 122 """ 123 return value_to_value(name_in_config, 'm_%s') 124 125 126def value_to_value(ref_value, pattern): 127 """Translates the value of a key to the value of its corresponding key. The 128 corresponding key is chosen based on the variable name pattern. 129 """ 130 ref_key_name = get_name_by_value(ref_value) 131 if not ref_key_name: 132 return None 133 target_key_name = pattern % ref_key_name 134 try: 135 return getattr(Config, target_key_name).value 136 except AttributeError: 137 return None 138