1#!/usr/bin/env python3.4 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_testbed = "testbed" 31 key_testbed_name = "name" 32 key_config_path = "configpath" 33 key_test_paths = "testpaths" 34 key_port = "Port" 35 key_address = "Address" 36 key_random = "random" 37 key_test_case_iterations = "test_case_iterations" 38 key_test_failure_tracebacks = "test_failure_tracebacks" 39 # Config names for controllers packaged in ACTS. 40 key_android_device = "AndroidDevice" 41 key_chameleon_device = "ChameleonDevice" 42 key_native_android_device = "NativeAndroidDevice" 43 key_relay_device = "RelayDevice" 44 key_access_point = "AccessPoint" 45 key_attenuator = "Attenuator" 46 key_iperf_server = "IPerfServer" 47 key_packet_sender = "PacketSender" 48 key_monsoon = "Monsoon" 49 key_sniffer = "Sniffer" 50 key_arduino_wifi_dongle = "ArduinoWifiDongle" 51 # Internal keys, used internally, not exposed to user's config files. 52 ikey_user_param = "user_params" 53 ikey_testbed_name = "testbed_name" 54 ikey_logger = "log" 55 ikey_logpath = "log_path" 56 ikey_cli_args = "cli_args" 57 # module name of controllers packaged in ACTS. 58 m_key_monsoon = "monsoon" 59 m_key_android_device = "android_device" 60 m_key_chameleon_device = "chameleon_controller" 61 m_key_native_android_device = "native_android_device" 62 m_key_relay_device = "relay_device_controller" 63 m_key_access_point = "access_point" 64 m_key_attenuator = "attenuator" 65 m_key_iperf_server = "iperf_server" 66 m_key_packet_sender = "packet_sender" 67 m_key_sniffer = "sniffer" 68 m_key_arduino_wifi_dongle = "arduino_wifi_dongle" 69 70 # A list of keys whose values in configs should not be passed to test 71 # classes without unpacking first. 72 reserved_keys = (key_testbed, key_log_path, key_test_paths) 73 74 # Controller names packaged with ACTS. 75 builtin_controller_names = [ 76 key_android_device, 77 key_native_android_device, 78 key_relay_device, 79 key_access_point, 80 key_attenuator, 81 key_iperf_server, 82 key_packet_sender, 83 key_monsoon, 84 key_sniffer, 85 key_chameleon_device, 86 key_arduino_wifi_dongle, 87 ] 88 89 # Keys that are file or folder paths. 90 file_path_keys = [key_relay_device] 91 92 93def get_name_by_value(value): 94 for name, member in Config.__members__.items(): 95 if member.value == value: 96 return name 97 return None 98 99 100def get_internal_value(external_value): 101 """Translates the value of an external key to the value of its 102 corresponding internal key. 103 """ 104 return value_to_value(external_value, "i%s") 105 106 107def get_module_name(name_in_config): 108 """Translates the name of a controller in config file to its module name. 109 """ 110 return value_to_value(name_in_config, "m_%s") 111 112 113def value_to_value(ref_value, pattern): 114 """Translates the value of a key to the value of its corresponding key. The 115 corresponding key is chosen based on the variable name pattern. 116 """ 117 ref_key_name = get_name_by_value(ref_value) 118 if not ref_key_name: 119 return None 120 target_key_name = pattern % ref_key_name 121 try: 122 return getattr(Config, target_key_name).value 123 except AttributeError: 124 return None 125