Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 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 | import splinter |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 17 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 18 | from time import sleep |
| 19 | |
| 20 | BROWSER_WAIT_SHORT = 1 |
| 21 | BROWSER_WAIT_MED = 3 |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 22 | BROWSER_WAIT_LONG = 30 |
| 23 | BROWSER_WAIT_EXTRA_LONG = 60 |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def create(configs): |
| 27 | """ Factory method for retail AP class. |
| 28 | |
| 29 | Args: |
| 30 | configs: list of dicts containing ap settings. ap settings must contain |
| 31 | the following: brand, model, ip_address, username and password |
| 32 | """ |
| 33 | SUPPORTED_APS = { |
| 34 | ("Netgear", "R7000"): "NetgearR7000AP", |
| 35 | ("Netgear", "R7500"): "NetgearR7500AP", |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 36 | ("Netgear", "R7800"): "NetgearR7800AP", |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 37 | ("Netgear", "R8000"): "NetgearR8000AP" |
| 38 | } |
| 39 | objs = [] |
| 40 | for config in configs: |
| 41 | try: |
| 42 | ap_class_name = SUPPORTED_APS[(config["brand"], config["model"])] |
| 43 | ap_class = globals()[ap_class_name] |
| 44 | except KeyError: |
| 45 | raise KeyError("Invalid retail AP brand and model combination.") |
| 46 | objs.append(ap_class(config)) |
| 47 | return objs |
| 48 | |
| 49 | |
| 50 | def detroy(objs): |
| 51 | return |
| 52 | |
| 53 | |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 54 | def visit_config_page(browser, url, page_load_timeout, num_tries): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 55 | """ Method to visit Netgear AP webpages. |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 56 | |
| 57 | This function visits a web page and checks the the resulting URL matches |
| 58 | the intended URL, i.e. no redirects have happened |
| 59 | |
| 60 | Args: |
| 61 | browser: the splinter browser object that will visit the URL |
| 62 | url: the intended url |
| 63 | num_tries: number of tries before url is declared unreachable |
| 64 | """ |
| 65 | browser.driver.set_page_load_timeout(page_load_timeout) |
| 66 | for idx in range(num_tries): |
| 67 | try: |
| 68 | browser.visit(url) |
| 69 | except: |
| 70 | raise TimeoutError( |
| 71 | "Page load timout. Could be due to connectivity or alerts.") |
| 72 | if browser.url.split("/")[-1] == url.split("/")[-1]: |
| 73 | break |
| 74 | if idx == num_tries - 1: |
| 75 | print(browser.url) |
| 76 | print(url) |
| 77 | raise RuntimeError("URL was unreachable.") |
| 78 | |
| 79 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 80 | class WifiRetailAP(object): |
| 81 | """ Base class implementation for retail ap. |
| 82 | |
| 83 | Base class provides functions whose implementation is shared by all aps. |
| 84 | If some functions such as set_power not supported by ap, checks will raise |
| 85 | exceptions. |
| 86 | """ |
| 87 | |
| 88 | def __init__(self, ap_settings): |
| 89 | raise NotImplementedError |
| 90 | |
| 91 | def read_ap_settings(self): |
| 92 | """ Function that reads current ap settings. |
| 93 | |
| 94 | Function implementation is AP dependent and thus base class raises exception |
| 95 | if function not implemented in child class. |
| 96 | """ |
| 97 | raise NotImplementedError |
| 98 | |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 99 | def validate_ap_settings(self): |
| 100 | """ Function to validate ap settings. |
| 101 | |
| 102 | This function compares the actual ap settings read from the web GUI |
| 103 | with the assumed settings saved in the AP object. When called after AP |
| 104 | configuration, this method helps ensure that our configuration was |
| 105 | successful. |
| 106 | |
| 107 | Raises: |
| 108 | ValueError: If read AP settings do not match stored settings. |
| 109 | """ |
| 110 | assumed_ap_settings = self.ap_settings.copy() |
| 111 | actual_ap_settings = self.read_ap_settings() |
| 112 | if assumed_ap_settings != actual_ap_settings: |
| 113 | raise ValueError( |
| 114 | "Discrepancy in AP settings. Potential configuration error.") |
| 115 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 116 | def configure_ap(self): |
| 117 | """ Function that configures ap based on values of ap_settings. |
| 118 | |
| 119 | Function implementation is AP dependent and thus base class raises exception |
| 120 | if function not implemented in child class. |
| 121 | """ |
| 122 | raise NotImplementedError |
| 123 | |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 124 | def set_radio_on_off(self, network, status): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 125 | """ Function that turns the radio on or off. |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 126 | |
| 127 | Args: |
| 128 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 129 | status: boolean indicating on or off (0: off, 1: on) |
| 130 | """ |
| 131 | setting_to_update = {"status_{}".format(network): int(status)} |
| 132 | self.update_ap_settings(setting_to_update) |
| 133 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 134 | def set_ssid(self, network, ssid): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 135 | """ Function that sets network SSID. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 136 | |
| 137 | Args: |
| 138 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 139 | ssid: string containing ssid |
| 140 | """ |
| 141 | setting_to_update = {"ssid_{}".format(network): str(ssid)} |
| 142 | self.update_ap_settings(setting_to_update) |
| 143 | |
| 144 | def set_channel(self, network, channel): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 145 | """ Function that sets network channel. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 146 | |
| 147 | Args: |
| 148 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 149 | channel: string or int containing channel |
| 150 | """ |
| 151 | setting_to_update = {"channel_{}".format(network): str(channel)} |
| 152 | self.update_ap_settings(setting_to_update) |
| 153 | |
| 154 | def set_bandwidth(self, network, bandwidth): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 155 | """ Function that sets network bandwidth/mode. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 156 | |
| 157 | Args: |
| 158 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 159 | bandwidth: string containing mode, e.g. 11g, VHT20, VHT40, VHT80. |
| 160 | """ |
| 161 | setting_to_update = {"bandwidth_{}".format(network): str(bandwidth)} |
| 162 | self.update_ap_settings(setting_to_update) |
| 163 | |
| 164 | def set_power(self, network, power): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 165 | """ Function that sets network transmit power. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 166 | |
| 167 | Args: |
| 168 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 169 | power: string containing power level, e.g., 25%, 100% |
| 170 | """ |
| 171 | setting_to_update = {"power_{}".format(network): str(power)} |
| 172 | self.update_ap_settings(setting_to_update) |
| 173 | |
| 174 | def set_security(self, network, security_type, *password): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 175 | """ Function that sets network security setting and password. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 176 | |
| 177 | Args: |
| 178 | network: string containing network identifier (2G, 5G_1, 5G_2) |
| 179 | security: string containing security setting, e.g., WPA2-PSK |
| 180 | password: optional argument containing password |
| 181 | """ |
| 182 | if (len(password) == 1) and (type(password[0]) == str): |
| 183 | setting_to_update = { |
| 184 | "security_type_{}".format(network): str(security_type), |
| 185 | "password_{}".format(network): str(password[0]) |
| 186 | } |
| 187 | else: |
| 188 | setting_to_update = { |
| 189 | "security_type_{}".format(network): str(security_type) |
| 190 | } |
| 191 | self.update_ap_settings(setting_to_update) |
| 192 | |
| 193 | def update_ap_settings(self, *dict_settings, **named_settings): |
| 194 | """ Function to update settings of existing AP. |
| 195 | |
| 196 | Function copies arguments into ap_settings and calls configure_retail_ap |
| 197 | to apply them. |
| 198 | |
| 199 | Args: |
| 200 | *dict_settings accepts single dictionary of settings to update |
| 201 | **named_settings accepts named settings to update |
| 202 | Note: dict and named_settings cannot contain the same settings. |
| 203 | """ |
| 204 | settings_to_update = {} |
| 205 | if (len(dict_settings) == 1) and (type(dict_settings[0]) == dict): |
| 206 | for key, value in dict_settings[0].items(): |
| 207 | if key in named_settings: |
| 208 | raise KeyError("{} was passed twice.".format(key)) |
| 209 | else: |
| 210 | settings_to_update[key] = value |
| 211 | elif len(dict_settings) > 1: |
| 212 | raise TypeError("Wrong number of positional arguments given") |
| 213 | return |
| 214 | |
| 215 | for key, value in named_settings.items(): |
| 216 | settings_to_update[key] = value |
| 217 | |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 218 | updates_requested = False |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 219 | for key, value in settings_to_update.items(): |
| 220 | if (key in self.ap_settings): |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 221 | if self.ap_settings[key] != value: |
| 222 | self.ap_settings[key] = value |
| 223 | updates_requested = True |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 224 | else: |
| 225 | raise KeyError("Invalid setting passed to AP configuration.") |
| 226 | |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 227 | if updates_requested: |
| 228 | self.configure_ap() |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 229 | |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 230 | def band_lookup_by_channel(self, channel): |
| 231 | """ Function that gives band name by channel number. |
| 232 | |
| 233 | Args: |
| 234 | channel: channel number to lookup |
| 235 | Returns: |
| 236 | band: name of band which this channel belongs to on this ap |
| 237 | """ |
| 238 | for key, value in self.CHANNEL_BAND_MAP.items(): |
| 239 | if channel in value: |
| 240 | return key |
| 241 | raise ValueError("Invalid channel passed in argument.") |
| 242 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 243 | |
| 244 | class NetgearR7000AP(WifiRetailAP): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 245 | """ Class that implements Netgear R7500 AP.""" |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 246 | |
| 247 | def __init__(self, ap_settings): |
| 248 | self.ap_settings = ap_settings.copy() |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 249 | self.CONFIG_PAGE = "{}://{}:{}@{}:{}/WLG_wireless_dual_band_r10.htm".format( |
| 250 | self.ap_settings["protocol"], self.ap_settings["admin_username"], |
| 251 | self.ap_settings["admin_password"], self.ap_settings["ip_address"], |
| 252 | self.ap_settings["port"]) |
| 253 | self.CONFIG_PAGE_NOLOGIN = "{}://{}:{}/WLG_wireless_dual_band_r10.htm".format( |
| 254 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 255 | self.ap_settings["port"]) |
| 256 | self.CONFIG_PAGE_ADVANCED = "{}://{}:{}/WLG_adv_dual_band2.htm".format( |
| 257 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 258 | self.ap_settings["port"]) |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 259 | self.CHROME_OPTIONS = splinter.driver.webdriver.chrome.Options() |
| 260 | self.CHROME_OPTIONS.add_argument("--no-proxy-server") |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 261 | self.CHROME_OPTIONS.add_argument("--no-sandbox") |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 262 | self.CHROME_OPTIONS.add_argument("--allow-running-insecure-content") |
| 263 | self.CHROME_OPTIONS.add_argument("--ignore-certificate-errors") |
| 264 | self.CHROME_CAPABILITIES = DesiredCapabilities.CHROME.copy() |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 265 | self.CHROME_CAPABILITIES["acceptSslCerts"] = True |
| 266 | self.CHROME_CAPABILITIES["acceptInsecureCerts"] = True |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 267 | if self.ap_settings["headless_browser"]: |
| 268 | self.CHROME_OPTIONS.add_argument("--headless") |
| 269 | self.CHROME_OPTIONS.add_argument("--disable-gpu") |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 270 | self.NETWORKS = ["2G", "5G_1"] |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 271 | self.CHANNEL_BAND_MAP = { |
| 272 | "2G": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 273 | "5G_1": [ |
| 274 | 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, |
| 275 | 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 |
| 276 | ] |
| 277 | } |
| 278 | self.REGION_MAP = { |
| 279 | "1": "Africa", |
| 280 | "2": "Asia", |
| 281 | "3": "Australia", |
| 282 | "4": "Canada", |
| 283 | "5": "Europe", |
| 284 | "6": "Israel", |
| 285 | "7": "Japan", |
| 286 | "8": "Korea", |
| 287 | "9": "Mexico", |
| 288 | "10": "South America", |
| 289 | "11": "United States", |
| 290 | "12": "Middle East(Algeria/Syria/Yemen)", |
| 291 | "14": "Russia", |
| 292 | "16": "China", |
| 293 | "17": "India", |
| 294 | "18": "Malaysia", |
| 295 | "19": "Middle East(Iran/Labanon/Qatar)", |
| 296 | "20": "Middle East(Turkey/Egypt/Tunisia/Kuwait)", |
| 297 | "21": "Middle East(Saudi Arabia)", |
| 298 | "22": "Middle East(United Arab Emirates)", |
| 299 | "23": "Singapore", |
| 300 | "24": "Taiwan" |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 301 | } |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 302 | self.CONFIG_PAGE_FIELDS = { |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 303 | "region": "WRegion", |
| 304 | ("2G", "status"): "enable_ap", |
| 305 | ("5G_1", "status"): "enable_ap_an", |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 306 | ("2G", "ssid"): "ssid", |
| 307 | ("5G_1", "ssid"): "ssid_an", |
| 308 | ("2G", "channel"): "w_channel", |
| 309 | ("5G_1", "channel"): "w_channel_an", |
| 310 | ("2G", "bandwidth"): "opmode", |
| 311 | ("5G_1", "bandwidth"): "opmode_an", |
| 312 | ("2G", "power"): "enable_tpc", |
| 313 | ("5G_1", "power"): "enable_tpc_an", |
| 314 | ("2G", "security_type"): "security_type", |
| 315 | ("5G_1", "security_type"): "security_type_an", |
| 316 | ("2G", "password"): "passphrase", |
| 317 | ("5G_1", "password"): "passphrase_an" |
| 318 | } |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 319 | self.BW_MODE_VALUES = { |
| 320 | "g and b": "11g", |
| 321 | "145Mbps": "VHT20", |
| 322 | "300Mbps": "VHT40", |
| 323 | "HT80": "VHT80" |
| 324 | } |
| 325 | self.POWER_MODE_VALUES = { |
| 326 | "1": "100%", |
| 327 | "2": "75%", |
| 328 | "3": "50%", |
| 329 | "4": "25%" |
| 330 | } |
| 331 | self.BW_MODE_TEXT = { |
| 332 | "11g": "Up to 54 Mbps", |
| 333 | "VHT20": "Up to 289 Mbps", |
| 334 | "VHT40": "Up to 600 Mbps", |
| 335 | "VHT80": "Up to 1300 Mbps" |
| 336 | } |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 337 | self.read_ap_settings() |
| 338 | if ap_settings.items() <= self.ap_settings.items(): |
| 339 | return |
| 340 | else: |
| 341 | self.update_ap_settings(ap_settings) |
| 342 | |
| 343 | def read_ap_settings(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 344 | """ Function to read ap settings.""" |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 345 | with splinter.Browser( |
| 346 | "chrome", |
| 347 | options=self.CHROME_OPTIONS, |
| 348 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 349 | # Visit URL |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 350 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 351 | visit_config_page(browser, self.CONFIG_PAGE_NOLOGIN, |
| 352 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 353 | |
| 354 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 355 | if "status" in key: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 356 | visit_config_page(browser, self.CONFIG_PAGE_ADVANCED, |
| 357 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 358 | config_item = browser.find_by_name(value) |
| 359 | self.ap_settings["{}_{}".format(key[1], key[0])] = int( |
| 360 | config_item.first.checked) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 361 | visit_config_page(browser, self.CONFIG_PAGE_NOLOGIN, |
| 362 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 363 | else: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 364 | config_item = browser.find_by_name(value) |
| 365 | if "bandwidth" in key: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 366 | self.ap_settings["{}_{}".format(key[1], key[ |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 367 | 0])] = self.BW_MODE_VALUES[config_item.first.value] |
| 368 | elif "power" in key: |
| 369 | self.ap_settings["{}_{}".format( |
| 370 | key[1], key[0])] = self.POWER_MODE_VALUES[ |
| 371 | config_item.first.value] |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 372 | elif "region" in key: |
| 373 | self.ap_settings["region"] = self.REGION_MAP[ |
| 374 | config_item.first.value] |
| 375 | elif "security_type" in key: |
| 376 | for item in config_item: |
| 377 | if item.checked: |
| 378 | self.ap_settings["{}_{}".format( |
| 379 | key[1], key[0])] = item.value |
| 380 | else: |
| 381 | config_item = browser.find_by_name(value) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 382 | self.ap_settings["{}_{}".format( |
| 383 | key[1], key[0])] = config_item.first.value |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 384 | return self.ap_settings.copy() |
| 385 | |
| 386 | def configure_ap(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 387 | """ Function to configure ap wireless settings.""" |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 388 | # Turn radios on or off |
| 389 | self.configure_radio_on_off() |
| 390 | # Configure radios |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 391 | with splinter.Browser( |
| 392 | "chrome", |
| 393 | options=self.CHROME_OPTIONS, |
| 394 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 395 | # Visit URL |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 396 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 397 | visit_config_page(browser, self.CONFIG_PAGE_NOLOGIN, |
| 398 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 399 | |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 400 | # Update region, and power/bandwidth for each network |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 401 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 402 | if "power" in key: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 403 | config_item = browser.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 404 | config_item.select_by_text(self.ap_settings["{}_{}".format( |
| 405 | key[1], key[0])]) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 406 | elif "region" in key: |
| 407 | config_item = browser.find_by_name(value).first |
| 408 | config_item.select_by_text(self.ap_settings["region"]) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 409 | elif "bandwidth" in key: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 410 | config_item = browser.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 411 | config_item.select_by_text( |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 412 | self.BW_MODE_TEXT[self.ap_settings["{}_{}".format( |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 413 | key[1], key[0])]]) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 414 | |
| 415 | # Update security settings (passwords updated only if applicable) |
| 416 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 417 | if "security_type" in key: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 418 | browser.choose(value, self.ap_settings["{}_{}".format( |
| 419 | key[1], key[0])]) |
| 420 | if self.ap_settings["{}_{}".format(key[1], |
| 421 | key[0])] == "WPA2-PSK": |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 422 | config_item = browser.find_by_name( |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 423 | self.CONFIG_PAGE_FIELDS[(key[0], |
| 424 | "password")]).first |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 425 | config_item.fill(self.ap_settings["{}_{}".format( |
| 426 | "password", key[0])]) |
| 427 | |
| 428 | # Update SSID and channel for each network |
| 429 | # NOTE: Update ordering done as such as workaround for R8000 |
| 430 | # wherein channel and SSID get overwritten when some other |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 431 | # variables are changed. However, region does have to be set before |
| 432 | # channel in all cases. |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 433 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 434 | if "ssid" in key: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 435 | config_item = browser.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 436 | config_item.fill(self.ap_settings["{}_{}".format( |
| 437 | key[1], key[0])]) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 438 | elif "channel" in key: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 439 | config_item = browser.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 440 | config_item.select(self.ap_settings["{}_{}".format( |
| 441 | key[1], key[0])]) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 442 | sleep(BROWSER_WAIT_SHORT) |
| 443 | try: |
| 444 | alert = browser.get_alert() |
| 445 | alert.accept() |
| 446 | except: |
| 447 | pass |
| 448 | |
| 449 | sleep(BROWSER_WAIT_SHORT) |
| 450 | browser.find_by_name("Apply").first.click() |
| 451 | sleep(BROWSER_WAIT_SHORT) |
| 452 | try: |
| 453 | alert = browser.get_alert() |
| 454 | alert.accept() |
| 455 | sleep(BROWSER_WAIT_SHORT) |
| 456 | except: |
| 457 | sleep(BROWSER_WAIT_SHORT) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 458 | visit_config_page(browser, self.CONFIG_PAGE, |
| 459 | BROWSER_WAIT_EXTRA_LONG, 10) |
| 460 | self.validate_ap_settings() |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 461 | |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 462 | def configure_radio_on_off(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 463 | """ Helper configuration function to turn radios on/off.""" |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 464 | with splinter.Browser( |
| 465 | "chrome", |
| 466 | options=self.CHROME_OPTIONS, |
| 467 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 468 | # Visit URL |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 469 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 470 | visit_config_page(browser, self.CONFIG_PAGE_ADVANCED, |
| 471 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 472 | |
| 473 | # Turn radios on or off |
| 474 | status_toggled = False |
| 475 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 476 | if "status" in key: |
| 477 | config_item = browser.find_by_name(value).first |
| 478 | current_status = int(config_item.checked) |
| 479 | if current_status != self.ap_settings["{}_{}".format( |
| 480 | key[1], key[0])]: |
| 481 | status_toggled = True |
| 482 | if self.ap_settings["{}_{}".format(key[1], key[0])]: |
| 483 | config_item.check() |
| 484 | else: |
| 485 | config_item.uncheck() |
| 486 | |
| 487 | if status_toggled: |
| 488 | sleep(BROWSER_WAIT_SHORT) |
| 489 | browser.find_by_name("Apply").first.click() |
| 490 | sleep(BROWSER_WAIT_EXTRA_LONG) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 491 | visit_config_page(browser, self.CONFIG_PAGE, |
| 492 | BROWSER_WAIT_EXTRA_LONG, 10) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 493 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 494 | |
| 495 | class NetgearR7500AP(WifiRetailAP): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 496 | """ Class that implements Netgear R7500 AP.""" |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 497 | |
| 498 | def __init__(self, ap_settings): |
| 499 | self.ap_settings = ap_settings.copy() |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 500 | self.CONFIG_PAGE = "{}://{}:{}@{}:{}/index.htm".format( |
| 501 | self.ap_settings["protocol"], self.ap_settings["admin_username"], |
| 502 | self.ap_settings["admin_password"], self.ap_settings["ip_address"], |
| 503 | self.ap_settings["port"]) |
| 504 | self.CONFIG_PAGE_NOLOGIN = "{}://{}:{}/index.htm".format( |
| 505 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 506 | self.ap_settings["port"]) |
| 507 | self.CONFIG_PAGE_ADVANCED = "{}://{}:{}/adv_index.htm".format( |
| 508 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 509 | self.ap_settings["port"]) |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 510 | self.CHROME_OPTIONS = splinter.driver.webdriver.chrome.Options() |
| 511 | self.CHROME_OPTIONS.add_argument("--no-proxy-server") |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 512 | self.CHROME_OPTIONS.add_argument("--no-sandbox") |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 513 | self.CHROME_OPTIONS.add_argument("--allow-running-insecure-content") |
| 514 | self.CHROME_OPTIONS.add_argument("--ignore-certificate-errors") |
| 515 | self.CHROME_CAPABILITIES = DesiredCapabilities.CHROME.copy() |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 516 | self.CHROME_CAPABILITIES["acceptSslCerts"] = True |
| 517 | self.CHROME_CAPABILITIES["acceptInsecureCerts"] = True |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 518 | if self.ap_settings["headless_browser"]: |
| 519 | self.CHROME_OPTIONS.add_argument("--headless") |
| 520 | self.CHROME_OPTIONS.add_argument("--disable-gpu") |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 521 | self.NETWORKS = ["2G", "5G_1"] |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 522 | self.CHANNEL_BAND_MAP = { |
| 523 | "2G": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 524 | "5G_1": [ |
| 525 | 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, |
| 526 | 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 |
| 527 | ] |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 528 | } |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 529 | self.CONFIG_PAGE_FIELDS = { |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 530 | "region": "WRegion", |
| 531 | ("2G", "status"): "enable_ap", |
| 532 | ("5G_1", "status"): "enable_ap_an", |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 533 | ("2G", "ssid"): "ssid", |
| 534 | ("5G_1", "ssid"): "ssid_an", |
| 535 | ("2G", "channel"): "w_channel", |
| 536 | ("5G_1", "channel"): "w_channel_an", |
| 537 | ("2G", "bandwidth"): "opmode", |
| 538 | ("5G_1", "bandwidth"): "opmode_an", |
| 539 | ("2G", "security_type"): "security_type", |
| 540 | ("5G_1", "security_type"): "security_type_an", |
| 541 | ("2G", "password"): "passphrase", |
| 542 | ("5G_1", "password"): "passphrase_an" |
| 543 | } |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 544 | self.REGION_MAP = { |
| 545 | "0": "Africa", |
| 546 | "1": "Asia", |
| 547 | "2": "Australia", |
| 548 | "3": "Canada", |
| 549 | "4": "Europe", |
| 550 | "5": "Israel", |
| 551 | "6": "Japan", |
| 552 | "7": "Korea", |
| 553 | "8": "Mexico", |
| 554 | "9": "South America", |
| 555 | "10": "United States", |
| 556 | "11": "China", |
| 557 | "12": "India", |
| 558 | "13": "Malaysia", |
| 559 | "14": "Middle East(Algeria/Syria/Yemen)", |
| 560 | "15": "Middle East(Iran/Labanon/Qatar)", |
| 561 | "16": "Middle East(Turkey/Egypt/Tunisia/Kuwait)", |
| 562 | "17": "Middle East(Saudi Arabia)", |
| 563 | "18": "Middle East(United Arab Emirates)", |
| 564 | "19": "Russia", |
| 565 | "20": "Singapore", |
| 566 | "21": "Taiwan" |
| 567 | } |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 568 | self.BW_MODE_TEXT_2G = { |
| 569 | "11g": "Up to 54 Mbps", |
| 570 | "VHT20": "Up to 289 Mbps", |
| 571 | "VHT40": "Up to 600 Mbps" |
| 572 | } |
| 573 | self.BW_MODE_TEXT_5G = { |
| 574 | "VHT20": "Up to 347 Mbps", |
| 575 | "VHT40": "Up to 800 Mbps", |
| 576 | "VHT80": "Up to 1733 Mbps" |
| 577 | } |
| 578 | self.BW_MODE_VALUES = { |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 579 | "1": "11g", |
| 580 | "2": "VHT20", |
| 581 | "3": "VHT40", |
| 582 | "7": "VHT20", |
| 583 | "8": "VHT40", |
| 584 | "9": "VHT80" |
| 585 | } |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 586 | self.read_ap_settings() |
| 587 | if ap_settings.items() <= self.ap_settings.items(): |
| 588 | return |
| 589 | else: |
| 590 | self.update_ap_settings(ap_settings) |
| 591 | |
| 592 | def read_ap_settings(self): |
| 593 | """ Function to read ap wireless settings.""" |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 594 | # Get radio status (on/off) |
| 595 | self.read_radio_on_off() |
| 596 | # Get radio configuration. Note that if both radios are off, the below |
| 597 | # code will result in an error |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 598 | with splinter.Browser( |
| 599 | "chrome", |
| 600 | options=self.CHROME_OPTIONS, |
| 601 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 602 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 603 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 604 | sleep(BROWSER_WAIT_SHORT) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 605 | wireless_button = browser.find_by_id("wireless").first |
| 606 | wireless_button.click() |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 607 | sleep(BROWSER_WAIT_MED) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 608 | |
| 609 | with browser.get_iframe("formframe") as iframe: |
| 610 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 611 | if "bandwidth" in key: |
| 612 | config_item = iframe.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 613 | self.ap_settings["{}_{}".format( |
| 614 | key[1], |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 615 | key[0])] = self.BW_MODE_VALUES[config_item.value] |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 616 | elif "region" in key: |
| 617 | config_item = iframe.find_by_name(value).first |
| 618 | self.ap_settings["region"] = self.REGION_MAP[ |
| 619 | config_item.value] |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 620 | elif "password" in key: |
| 621 | try: |
| 622 | config_item = iframe.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 623 | self.ap_settings["{}_{}".format( |
| 624 | key[1], key[0])] = config_item.value |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 625 | self.ap_settings["{}_{}".format( |
| 626 | "security_type", key[0])] = "WPA2-PSK" |
| 627 | except: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 628 | self.ap_settings["{}_{}".format( |
| 629 | key[1], key[0])] = "defaultpassword" |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 630 | self.ap_settings["{}_{}".format( |
| 631 | "security_type", key[0])] = "Disable" |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 632 | elif ("channel" in key) or ("ssid" in key): |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 633 | config_item = iframe.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 634 | self.ap_settings["{}_{}".format( |
| 635 | key[1], key[0])] = config_item.value |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 636 | else: |
| 637 | pass |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 638 | return self.ap_settings.copy() |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 639 | |
| 640 | def configure_ap(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 641 | """ Function to configure ap wireless settings.""" |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 642 | # Turn radios on or off |
| 643 | self.configure_radio_on_off() |
| 644 | # Configure radios |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 645 | with splinter.Browser( |
| 646 | "chrome", |
| 647 | options=self.CHROME_OPTIONS, |
| 648 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 649 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 650 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 651 | sleep(BROWSER_WAIT_SHORT) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 652 | wireless_button = browser.find_by_id("wireless").first |
| 653 | wireless_button.click() |
| 654 | sleep(BROWSER_WAIT_MED) |
| 655 | |
| 656 | with browser.get_iframe("formframe") as iframe: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 657 | # Update AP region. Must be done before channel setting |
| 658 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 659 | if "region" in key: |
| 660 | config_item = iframe.find_by_name(value).first |
| 661 | config_item.select_by_text(self.ap_settings["region"]) |
| 662 | # Update wireless settings for each network |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 663 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 664 | if "ssid" in key: |
| 665 | config_item = iframe.find_by_name(value).first |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 666 | config_item.fill(self.ap_settings["{}_{}".format( |
| 667 | key[1], key[0])]) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 668 | elif "channel" in key: |
| 669 | channel_string = "0" * (int( |
| 670 | self.ap_settings["{}_{}".format(key[1], key[0])] |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 671 | ) < 10) + str(self.ap_settings["{}_{}".format( |
| 672 | key[1], key[0])]) + "(DFS)" * ( |
| 673 | 48 < int(self.ap_settings["{}_{}".format( |
| 674 | key[1], key[0])]) < 149) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 675 | config_item = iframe.find_by_name(value).first |
| 676 | config_item.select_by_text(channel_string) |
| 677 | elif key == ("2G", "bandwidth"): |
| 678 | config_item = iframe.find_by_name(value).first |
| 679 | config_item.select_by_text( |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 680 | str(self.BW_MODE_TEXT_2G[self.ap_settings[ |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 681 | "{}_{}".format(key[1], key[0])]])) |
| 682 | elif key == ("5G_1", "bandwidth"): |
| 683 | config_item = iframe.find_by_name(value).first |
| 684 | config_item.select_by_text( |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 685 | str(self.BW_MODE_TEXT_5G[self.ap_settings[ |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 686 | "{}_{}".format(key[1], key[0])]])) |
| 687 | |
| 688 | # Update passwords for WPA2-PSK protected networks |
| 689 | # (Must be done after security type is selected) |
| 690 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 691 | if "security_type" in key: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 692 | iframe.choose(value, self.ap_settings["{}_{}".format( |
| 693 | key[1], key[0])]) |
| 694 | if self.ap_settings["{}_{}".format( |
| 695 | key[1], key[0])] == "WPA2-PSK": |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 696 | config_item = iframe.find_by_name( |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 697 | self.CONFIG_PAGE_FIELDS[(key[0], |
| 698 | "password")]).first |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 699 | config_item.fill(self.ap_settings["{}_{}".format( |
| 700 | "password", key[0])]) |
| 701 | |
| 702 | apply_button = iframe.find_by_name("Apply") |
| 703 | apply_button[0].click() |
| 704 | sleep(BROWSER_WAIT_SHORT) |
| 705 | try: |
| 706 | alert = browser.get_alert() |
| 707 | alert.accept() |
| 708 | except: |
| 709 | pass |
| 710 | sleep(BROWSER_WAIT_SHORT) |
| 711 | try: |
| 712 | alert = browser.get_alert() |
| 713 | alert.accept() |
| 714 | except: |
| 715 | pass |
| 716 | sleep(BROWSER_WAIT_SHORT) |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 717 | sleep(BROWSER_WAIT_EXTRA_LONG) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 718 | visit_config_page(browser, self.CONFIG_PAGE, |
| 719 | BROWSER_WAIT_EXTRA_LONG, 10) |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 720 | self.validate_ap_settings() |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 721 | |
| 722 | def configure_radio_on_off(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 723 | """ Helper configuration function to turn radios on/off.""" |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 724 | with splinter.Browser( |
| 725 | "chrome", |
| 726 | options=self.CHROME_OPTIONS, |
| 727 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 728 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 729 | visit_config_page(browser, self.CONFIG_PAGE_ADVANCED, |
| 730 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 731 | sleep(BROWSER_WAIT_SHORT) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 732 | wireless_button = browser.find_by_id("advanced_bt").first |
| 733 | wireless_button.click() |
| 734 | sleep(BROWSER_WAIT_SHORT) |
| 735 | wireless_button = browser.find_by_id("wladv").first |
| 736 | wireless_button.click() |
| 737 | sleep(BROWSER_WAIT_MED) |
| 738 | |
| 739 | with browser.get_iframe("formframe") as iframe: |
| 740 | # Turn radios on or off |
| 741 | status_toggled = False |
| 742 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 743 | if "status" in key: |
| 744 | config_item = iframe.find_by_name(value).first |
| 745 | current_status = int(config_item.checked) |
| 746 | if current_status != self.ap_settings["{}_{}".format( |
| 747 | key[1], key[0])]: |
| 748 | status_toggled = True |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 749 | if self.ap_settings["{}_{}".format(key[1], |
| 750 | key[0])]: |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 751 | config_item.check() |
| 752 | else: |
| 753 | config_item.uncheck() |
| 754 | |
| 755 | if status_toggled: |
| 756 | sleep(BROWSER_WAIT_SHORT) |
| 757 | browser.find_by_name("Apply").first.click() |
| 758 | sleep(BROWSER_WAIT_EXTRA_LONG) |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 759 | visit_config_page(browser, self.CONFIG_PAGE, |
| 760 | BROWSER_WAIT_EXTRA_LONG, 10) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 761 | |
| 762 | def read_radio_on_off(self): |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 763 | """ Helper configuration function to read radio status.""" |
android-build-prod (mdb) | dd7347e | 2018-05-03 23:13:56 -0700 | [diff] [blame] | 764 | with splinter.Browser( |
| 765 | "chrome", |
| 766 | options=self.CHROME_OPTIONS, |
| 767 | desired_capabilities=self.CHROME_CAPABILITIES) as browser: |
android-build-prod (mdb) | 70753e8 | 2018-05-02 17:54:37 -0700 | [diff] [blame] | 768 | visit_config_page(browser, self.CONFIG_PAGE, BROWSER_WAIT_MED, 10) |
| 769 | visit_config_page(browser, self.CONFIG_PAGE_ADVANCED, |
| 770 | BROWSER_WAIT_MED, 10) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 771 | wireless_button = browser.find_by_id("advanced_bt").first |
| 772 | wireless_button.click() |
| 773 | sleep(BROWSER_WAIT_SHORT) |
| 774 | wireless_button = browser.find_by_id("wladv").first |
| 775 | wireless_button.click() |
| 776 | sleep(BROWSER_WAIT_MED) |
| 777 | |
| 778 | with browser.get_iframe("formframe") as iframe: |
| 779 | # Turn radios on or off |
| 780 | for key, value in self.CONFIG_PAGE_FIELDS.items(): |
| 781 | if "status" in key: |
| 782 | config_item = iframe.find_by_name(value).first |
| 783 | self.ap_settings["{}_{}".format(key[1], key[0])] = int( |
| 784 | config_item.checked) |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 785 | |
| 786 | |
Omar El Ayach | d4bc7ac | 2018-05-09 19:47:26 -0700 | [diff] [blame^] | 787 | class NetgearR7800AP(NetgearR7500AP): |
| 788 | """ Class that implements Netgear R7800 AP.""" |
| 789 | |
| 790 | def __init__(self, ap_settings): |
| 791 | self.ap_settings = ap_settings.copy() |
| 792 | self.CONFIG_PAGE = "{}://{}:{}@{}:{}/index.htm".format( |
| 793 | self.ap_settings["protocol"], self.ap_settings["admin_username"], |
| 794 | self.ap_settings["admin_password"], self.ap_settings["ip_address"], |
| 795 | self.ap_settings["port"]) |
| 796 | self.CONFIG_PAGE_NOLOGIN = "{}://{}:{}/index.htm".format( |
| 797 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 798 | self.ap_settings["port"]) |
| 799 | self.CONFIG_PAGE_ADVANCED = "{}://{}:{}/adv_index.htm".format( |
| 800 | self.ap_settings["protocol"], self.ap_settings["ip_address"], |
| 801 | self.ap_settings["port"]) |
| 802 | self.CHROME_OPTIONS = splinter.driver.webdriver.chrome.Options() |
| 803 | self.CHROME_OPTIONS.add_argument("--no-proxy-server") |
| 804 | self.CHROME_OPTIONS.add_argument("--no-sandbox") |
| 805 | self.CHROME_OPTIONS.add_argument("--allow-running-insecure-content") |
| 806 | self.CHROME_OPTIONS.add_argument("--ignore-certificate-errors") |
| 807 | self.CHROME_CAPABILITIES = DesiredCapabilities.CHROME.copy() |
| 808 | self.CHROME_CAPABILITIES["acceptSslCerts"] = True |
| 809 | self.CHROME_CAPABILITIES["acceptInsecureCerts"] = True |
| 810 | if self.ap_settings["headless_browser"]: |
| 811 | self.CHROME_OPTIONS.add_argument("--headless") |
| 812 | self.CHROME_OPTIONS.add_argument("--disable-gpu") |
| 813 | self.NETWORKS = ["2G", "5G_1"] |
| 814 | self.CHANNEL_BAND_MAP = { |
| 815 | "2G": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
| 816 | "5G_1": [ |
| 817 | 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, |
| 818 | 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 |
| 819 | ] |
| 820 | } |
| 821 | self.CONFIG_PAGE_FIELDS = { |
| 822 | "region": "WRegion", |
| 823 | ("2G", "status"): "enable_ap", |
| 824 | ("5G_1", "status"): "enable_ap_an", |
| 825 | ("2G", "ssid"): "ssid", |
| 826 | ("5G_1", "ssid"): "ssid_an", |
| 827 | ("2G", "channel"): "w_channel", |
| 828 | ("5G_1", "channel"): "w_channel_an", |
| 829 | ("2G", "bandwidth"): "opmode", |
| 830 | ("5G_1", "bandwidth"): "opmode_an", |
| 831 | ("2G", "security_type"): "security_type", |
| 832 | ("5G_1", "security_type"): "security_type_an", |
| 833 | ("2G", "password"): "passphrase", |
| 834 | ("5G_1", "password"): "passphrase_an" |
| 835 | } |
| 836 | self.REGION_MAP = { |
| 837 | "0": "Africa", |
| 838 | "1": "Asia", |
| 839 | "2": "Australia", |
| 840 | "3": "Canada", |
| 841 | "4": "Europe", |
| 842 | "5": "Israel", |
| 843 | "6": "Japan", |
| 844 | "7": "Korea", |
| 845 | "8": "Mexico", |
| 846 | "9": "South America", |
| 847 | "10": "United States", |
| 848 | "11": "China", |
| 849 | "12": "India", |
| 850 | "13": "Malaysia", |
| 851 | "14": "Middle East(Algeria/Syria/Yemen)", |
| 852 | "15": "Middle East(Iran/Labanon/Qatar)", |
| 853 | "16": "Middle East(Turkey/Egypt/Tunisia/Kuwait)", |
| 854 | "17": "Middle East(Saudi Arabia)", |
| 855 | "18": "Middle East(United Arab Emirates)", |
| 856 | "19": "Russia", |
| 857 | "20": "Singapore", |
| 858 | "21": "Taiwan" |
| 859 | } |
| 860 | self.BW_MODE_TEXT_2G = { |
| 861 | "11g": "Up to 54 Mbps", |
| 862 | "VHT20": "Up to 347 Mbps", |
| 863 | "VHT40": "Up to 600 Mbps" |
| 864 | } |
| 865 | self.BW_MODE_TEXT_5G = { |
| 866 | "VHT20": "Up to 347 Mbps", |
| 867 | "VHT40": "Up to 800 Mbps", |
| 868 | "VHT80": "Up to 1733 Mbps" |
| 869 | } |
| 870 | self.BW_MODE_VALUES = { |
| 871 | "1": "11g", |
| 872 | "2": "VHT20", |
| 873 | "3": "VHT40", |
| 874 | "7": "VHT20", |
| 875 | "8": "VHT40", |
| 876 | "9": "VHT80" |
| 877 | } |
| 878 | self.read_ap_settings() |
| 879 | if ap_settings.items() <= self.ap_settings.items(): |
| 880 | return |
| 881 | else: |
| 882 | self.update_ap_settings(ap_settings) |
| 883 | |
| 884 | |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 885 | class NetgearR8000AP(NetgearR7000AP): |
| 886 | """ Class that implements Netgear R8000 AP. |
| 887 | |
| 888 | Since most of the class' implementation is shared with the R7000, this |
| 889 | class inherits from NetgearR7000AP and simply redifines config parameters |
| 890 | """ |
| 891 | |
| 892 | def __init__(self, ap_settings): |
| 893 | self.ap_settings = ap_settings.copy() |
| 894 | self.CONFIG_PAGE = "http://{}:{}@{}/WLG_wireless_dual_band_r8000.htm".format( |
| 895 | self.ap_settings["admin_username"], |
| 896 | self.ap_settings["admin_password"], self.ap_settings["ip_address"]) |
| 897 | self.CONFIG_PAGE_NOLOGIN = "http://{}/WLG_wireless_dual_band_r8000.htm".format( |
| 898 | self.ap_settings["ip_address"]) |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 899 | self.CONFIG_PAGE_ADVANCED = "http://{}/WLG_adv_dual_band2_r8000.htm".format( |
| 900 | self.ap_settings["ip_address"]) |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 901 | self.CHROME_OPTIONS = splinter.driver.webdriver.chrome.Options() |
| 902 | self.CHROME_OPTIONS.add_argument("--no-proxy-server") |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 903 | self.CHROME_OPTIONS.add_argument("--no-sandbox") |
Omar El Ayach | 7331ba8 | 2018-01-03 22:52:34 +0000 | [diff] [blame] | 904 | if self.ap_settings["headless_browser"]: |
| 905 | self.CHROME_OPTIONS.add_argument("--headless") |
| 906 | self.CHROME_OPTIONS.add_argument("--disable-gpu") |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 907 | self.NETWORKS = ["2G", "5G_1", "5G_2"] |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 908 | self.CHANNEL_BAND_MAP = { |
| 909 | "2G": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
| 910 | "5G_1": [36, 40, 44, 48], |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 911 | "5G_2": [149, 153, 157, 161, 165] |
| 912 | } |
| 913 | self.REGION_MAP = { |
| 914 | "1": "Africa", |
| 915 | "2": "Asia", |
| 916 | "3": "Australia", |
| 917 | "4": "Canada", |
| 918 | "5": "Europe", |
| 919 | "6": "Israel", |
| 920 | "7": "Japan", |
| 921 | "8": "Korea", |
| 922 | "9": "Mexico", |
| 923 | "10": "South America", |
| 924 | "11": "United States", |
| 925 | "12": "Middle East(Algeria/Syria/Yemen)", |
| 926 | "14": "Russia", |
| 927 | "16": "China", |
| 928 | "17": "India", |
| 929 | "18": "Malaysia", |
| 930 | "19": "Middle East(Iran/Labanon/Qatar)", |
| 931 | "20": "Middle East(Turkey/Egypt/Tunisia/Kuwait)", |
| 932 | "21": "Middle East(Saudi Arabia)", |
| 933 | "22": "Middle East(United Arab Emirates)", |
| 934 | "23": "Singapore", |
| 935 | "24": "Taiwan" |
Omar El Ayach | 9be1c3c | 2017-12-27 19:20:56 +0000 | [diff] [blame] | 936 | } |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 937 | self.CONFIG_PAGE_FIELDS = { |
Omar El Ayach | d0c4b94 | 2018-01-30 06:02:14 +0000 | [diff] [blame] | 938 | "region": "WRegion", |
| 939 | ("2G", "status"): "enable_ap", |
| 940 | ("5G_1", "status"): "enable_ap_an", |
| 941 | ("5G_2", "status"): "enable_ap_an_2", |
Omar El Ayach | 32b3afa | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 942 | ("2G", "ssid"): "ssid", |
| 943 | ("5G_1", "ssid"): "ssid_an", |
| 944 | ("5G_2", "ssid"): "ssid_an_2", |
| 945 | ("2G", "channel"): "w_channel", |
| 946 | ("5G_1", "channel"): "w_channel_an", |
| 947 | ("5G_2", "channel"): "w_channel_an_2", |
| 948 | ("2G", "bandwidth"): "opmode", |
| 949 | ("5G_1", "bandwidth"): "opmode_an", |
| 950 | ("5G_2", "bandwidth"): "opmode_an_2", |
| 951 | ("2G", "security_type"): "security_type", |
| 952 | ("5G_1", "security_type"): "security_type_an", |
| 953 | ("5G_2", "security_type"): "security_type_an_2", |
| 954 | ("2G", "password"): "passphrase", |
| 955 | ("5G_1", "password"): "passphrase_an", |
| 956 | ("5G_2", "password"): "passphrase_an_2" |
| 957 | } |
| 958 | self.read_ap_settings() |
| 959 | if ap_settings.items() <= self.ap_settings.items(): |
| 960 | return |
| 961 | else: |
| 962 | self.update_ap_settings(ap_settings) |