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 19"""This module has the global key values that are used across framework 20modules. 21""" 22 23 24class Config(enum.Enum): 25 """Enum values for test config related lookups. 26 """ 27 # Keys used to look up values from test config files. 28 # These keys define the wording of test configs and their internal 29 # references. 30 key_log_path = 'logpath' 31 key_testbeds_under_test = 'testbeds_under_test' 32 key_testbed = 'testbed' 33 key_testbed_name = 'name' 34 # configpath is the directory. key_config_full_path is the file path. 35 key_config_path = 'configpath' 36 key_config_full_path = 'config_full_path' 37 key_test_paths = 'testpaths' 38 key_port = 'Port' 39 key_address = 'Address' 40 key_test_case_iterations = 'test_case_iterations' 41 key_test_failure_tracebacks = 'test_failure_tracebacks' 42 # Config names for controllers packaged in ACTS. 43 key_android_device = 'AndroidDevice' 44 key_bits = 'Bits' 45 key_bluetooth_pts_device = 'BluetoothPtsDevice' 46 key_fuchsia_device = 'FuchsiaDevice' 47 key_buds_device = 'BudsDevice' 48 key_chameleon_device = 'ChameleonDevice' 49 key_native_android_device = 'NativeAndroidDevice' 50 key_relay_device = 'RelayDevice' 51 key_access_point = 'AccessPoint' 52 key_attenuator = 'Attenuator' 53 key_iperf_server = 'IPerfServer' 54 key_iperf_client = 'IPerfClient' 55 key_packet_sender = 'PacketSender' 56 key_monsoon = 'Monsoon' 57 key_sniffer = 'Sniffer' 58 key_arduino_wifi_dongle = 'ArduinoWifiDongle' 59 key_packet_capture = 'PacketCapture' 60 key_pdu = 'PduDevice' 61 key_openwrt_ap = 'OpenWrtAP' 62 key_tigertail = 'Tigertail' 63 key_asus_axe11000_ap = 'AsusAXE11000AP' 64 # Internal keys, used internally, not exposed to user's config files. 65 ikey_user_param = 'user_params' 66 ikey_testbed_name = 'testbed_name' 67 ikey_logger = 'log' 68 ikey_logpath = 'log_path' 69 ikey_summary_writer = 'summary_writer' 70 # module name of controllers packaged in ACTS. 71 m_key_bits = 'bits' 72 m_key_monsoon = 'monsoon' 73 m_key_android_device = 'android_device' 74 m_key_fuchsia_device = 'fuchsia_device' 75 m_key_bluetooth_pts_device = 'bluetooth_pts_device' 76 m_key_buds_device = 'buds_controller' 77 m_key_chameleon_device = 'chameleon_controller' 78 m_key_native_android_device = 'native_android_device' 79 m_key_relay_device = 'relay_device_controller' 80 m_key_access_point = 'access_point' 81 m_key_attenuator = 'attenuator' 82 m_key_iperf_server = 'iperf_server' 83 m_key_iperf_client = 'iperf_client' 84 m_key_packet_sender = 'packet_sender' 85 m_key_sniffer = 'sniffer' 86 m_key_arduino_wifi_dongle = 'arduino_wifi_dongle' 87 m_key_packet_capture = 'packet_capture' 88 m_key_pdu = 'pdu' 89 m_key_openwrt_ap = 'openwrt_ap' 90 m_key_tigertail = 'tigertail' 91 m_key_asus_axe11000_ap = 'asus_axe11000_ap' 92 93 # A list of keys whose values in configs should not be passed to test 94 # classes without unpacking first. 95 reserved_keys = (key_testbed, key_log_path, key_test_paths) 96 97 # Controller names packaged with ACTS. 98 builtin_controller_names = [ 99 key_android_device, 100 key_bits, 101 key_bluetooth_pts_device, 102 key_fuchsia_device, 103 key_buds_device, 104 key_native_android_device, 105 key_relay_device, 106 key_access_point, 107 key_attenuator, 108 key_iperf_server, 109 key_iperf_client, 110 key_packet_sender, 111 key_monsoon, 112 key_sniffer, 113 key_chameleon_device, 114 key_arduino_wifi_dongle, 115 key_packet_capture, 116 key_pdu, 117 key_openwrt_ap, 118 key_tigertail, 119 key_asus_axe11000_ap, 120 ] 121 122 # Keys that are file or folder paths. 123 file_path_keys = [key_relay_device] 124 125 126def get_name_by_value(value): 127 for name, member in Config.__members__.items(): 128 if member.value == value: 129 return name 130 return None 131 132 133def get_module_name(name_in_config): 134 """Translates the name of a controller in config file to its module name. 135 """ 136 return value_to_value(name_in_config, 'm_%s') 137 138 139def value_to_value(ref_value, pattern): 140 """Translates the value of a key to the value of its corresponding key. The 141 corresponding key is chosen based on the variable name pattern. 142 """ 143 ref_key_name = get_name_by_value(ref_value) 144 if not ref_key_name: 145 return None 146 target_key_name = pattern % ref_key_name 147 try: 148 return getattr(Config, target_key_name).value 149 except AttributeError: 150 return None 151