How to use connect_to_service method in localstack

Best Python code snippet using localstack_python

network_RackWiFiConnect.py

Source:network_RackWiFiConnect.py Github

copy

Full Screen

1# Copyright 2015 The Chromium OS Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import dbus5import logging6import tempfile7import time8from autotest_lib.client.bin import test9from autotest_lib.client.bin import utils10from autotest_lib.client.common_lib import error11from autotest_lib.client.common_lib.cros.network \12 import wifi_rack_constants as constants13from autotest_lib.client.cros.networking import wifi_proxy14from autotest_lib.client.cros.networking.chrome_testing \15 import chrome_networking_test_api as cnta16from autotest_lib.client.cros.networking.chrome_testing \17 import chrome_networking_test_context as cntc18class network_RackWiFiConnect(test.test):19 """Client test to connect to various network services on WiFi rack.20 After connection, we assert access to pages only accessible through the21 connected network.22 """23 version = 124 def _assert_access(self, test):25 """Asset user can access page.26 Verification URLs are either pages on WiFi rack's Apache server or27 general Internet.28 @param test string - testname of NetworkServices namedtuple29 @return boolean - True if able to access, False otherwise30 """31 for service_test in constants.NETWORK_SERVICES_TESTS:32 if test == service_test.testname:33 url, pattern = service_test.url, service_test.pattern34 break35 # Since this test runs OTA, allow 15 seconds of leeway36 time.sleep(15)37 wget_cmd = 'wget -O /tmp/wget.log %s' % url38 for retry in range(3):39 exit_status = utils.system(wget_cmd, ignore_status=True)40 if not exit_status:41 logging.debug('Able to wget URL.')42 break43 logging.error('Could not wget URL; trying again.')44 grep_url_cmd = 'cat /tmp/wget.log | grep %s' % pattern45 output_status = utils.system(grep_url_cmd, ignore_status=True)46 if output_status:47 logging.debug('Unable to access correct URL for %s',48 service_test.testname)49 return False50 return True51 def _connect(self, ssid, uname):52 """Connect to particular network and assert access to page.53 @param ssid string - predefined SSID from user's preferred networks54 @param uname string - predefined username of managed user55 @return boolean - True if able to connect, False otherwise56 """57 start_time = time.time()58 with cntc.ChromeNetworkingTestContext(username=uname,59 password=constants.PASSWORD) as testing_context:60 net_provider = cnta.ChromeNetworkProvider(testing_context)61 enabled_devices = net_provider.get_enabled_devices()62 if net_provider.WIFI_DEVICE not in enabled_devices:63 net_provider.enable_network_device(net_provider.WIFI_DEVICE)64 logging.info('Scanning for networks')65 connect_to_service = None66 while time.time() - start_time < constants.SCAN_RETRY_TIMEOUT:67 net_provider.scan_for_networks(timeout=20)68 logging.info('Attempting to connect to %s', ssid)69 networks = net_provider.get_wifi_networks()70 for service in networks:71 if service['Name'] == ssid:72 connect_to_service = service73 if not connect_to_service:74 logging.error('Unable to find %s', ssid)75 continue76 try:77 net_provider.connect_to_network(connect_to_service)78 logging.info('Successfully connected to network %s', ssid)79 return True80 except error.TestFail as e:81 logging.error('Unable to connect to %s', ssid)82 continue83 return False84 def _connect_and_assert(self, test, ssid, user):85 """Verify connect and assert and write results to results/.86 @param test string - testname of NetworkServices namedtuple87 @param ssid string - predefined SSID from user's preferred networks88 @param user string - predefined username of managed user89 """90 tf = tempfile.NamedTemporaryFile(suffix='.txt',91 prefix='connect_%s_' % test,92 dir=self.resultsdir,93 delete=False)94 with tf as results:95 if not self._connect(ssid, user):96 results.write('%s FAILED to connect to SSID\n\n' % test)97 elif not self._assert_access(test):98 results.write('%s FAILED to access\n\n' % test)99 else:100 results.write('%s passed\n\n' % test)101 def _to_wifi(self, proxy):102 """Set service order to WiFi before Ethernet.103 @param proxy WiFi Proxy object104 """105 logging.info('Setting order to WiFi, prioritized over Ethernet.')106 proxy.manager.SetServiceOrder(dbus.String('wifi,ethernet'))107 def _to_ethernet(self, proxy):108 """Set service order to default Ethernet before WiFi109 @param proxy WiFi Proxy object110 """111 logging.info('Setting back to default service order.')112 proxy.manager.SetServiceOrder(dbus.String('ethernet,wifi'))113 def run_once(self, test):114 """Run the test.115 @param test string - Set by the client test control file116 """117 client_proxy = wifi_proxy.WifiProxy()118 if test is not 'all':119 logging.info('Running an individual control file.')120 self._to_wifi(client_proxy)121 for service_test in constants.NETWORK_SERVICES_TESTS:122 if service_test.testname == test:123 self._connect_and_assert(service_test.testname,124 service_test.ssid,125 service_test.user)126 self._to_ethernet(client_proxy)127 return128 for service_test in constants.NETWORK_SERVICES_TESTS:129 logging.info('==== Running current test %s ====',130 service_test.testname)131 self._to_wifi(client_proxy)132 self._connect_and_assert(service_test.testname,133 service_test.ssid,134 service_test.user)135 self._to_ethernet(client_proxy)136 # Ensure DUT returns to normal service state...

Full Screen

Full Screen

authenticate.py

Source:authenticate.py Github

copy

Full Screen

...23 return aws_region24# connect to Route53 service25def connect_route53():26 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials()27 return connect_to_service("route53", aws_region, aws_access_key, aws_secret_key)28# connect to second Route53 service29def connect_route53_alt():30 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials_alt()31 return connect_to_service("route53", aws_region, aws_access_key, aws_secret_key)32# connect to S3 service33def connect_s3():34 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials()35 return connect_to_service("s3", aws_region, aws_access_key, aws_secret_key)36# connect to second S3 service37def connect_s3_alt():38 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials_alt()39 return connect_to_service("s3", aws_region, aws_access_key, aws_secret_key)40# connect to EC2 service41def connect_ec2():42 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials()43 return connect_to_service("ec2", aws_region, aws_access_key, aws_secret_key)44# connect to second EC2 service45def connect_ec2_alt():46 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials_alt()47 return connect_to_service("ec2", aws_region, aws_access_key, aws_secret_key)48# connect to IAM service49def connect_iam():50 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials()51 return connect_to_service("iam", aws_region, aws_access_key, aws_secret_key)52# connect to second IAM service53def connect_iam_alt():54 aws_region, aws_access_key, aws_secret_key = read_AWS_credentials_alt()55 return connect_to_service("iam", aws_region, aws_access_key, aws_secret_key)56# connect to arbitrary service57def connect_to_service(service_name, region, access_key, secret_key):58 try:59 # authenticate60 client = boto3.client(service_name, region_name=region, aws_access_key_id=access_key, aws_secret_access_key=secret_key)61 return client62 except Exception as e:63 print("Error connecting to AWS: " + str(e))64 exit(1)65# compare regions66def compare_regions():67 if read_AWS_credentials()[0] == read_AWS_credentials_alt()[0]:68 return True69 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful