1# Lint as: python2, python3 2# Copyright 2022 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7 8from autotest_lib.client.common_lib import error 9 10 11def connect_to_wifi(host, ssid, password): 12 """ 13 Performs steps needed to configure a CrOS device for Cross Device tests. 14 15 @param host: Host to run the command on. 16 @param ssid: SSID of the Wifi network to connect to 17 @param password: password to connect to wifi network 18 19 """ 20 host.run( 21 'dbus-send --system --print-reply --dest=org.chromium.flimflam / org.chromium.flimflam.Manager.EnableTechnology string:wifi' 22 ) 23 try: 24 host.run('/usr/local/autotest/cros/scripts/wifi connect %s %s' % 25 (ssid, password)) 26 except error.AutoservRunError as e: 27 if 'already connected' in str(e): 28 logging.debug('Already connected to network. Ignoring error.') 29 else: 30 raise 31