How to use router_server method in localstack

Best Python code snippet using localstack_python

test_proxy.py

Source:test_proxy.py Github

copy

Full Screen

...8from localstack.http.dispatcher import handler_dispatcher9from localstack.http.hypercorn import HypercornServer10from localstack.http.proxy import ProxyHandler, forward11@pytest.fixture12def router_server(serve_asgi_adapter) -> Tuple[Router, HypercornServer]:13 """Creates a new Router with a handler dispatcher, serves it through a newly created ASGI server, and returns14 both the router and the server.15 """16 router = Router(dispatcher=handler_dispatcher())17 app = Request.application(router.dispatch)18 return router, serve_asgi_adapter(app)19class TestPathForwarder:20 def test_get_with_path_rule(self, router_server, httpserver: HTTPServer):21 router, proxy = router_server22 backend = httpserver23 backend.expect_request("/").respond_with_data("ok/")24 backend.expect_request("/bar").respond_with_data("ok/bar")25 backend.expect_request("/bar/ed").respond_with_data("ok/bar/ed")26 router.add("/foo/<path:path>", ProxyHandler(backend.url_for("/")))...

Full Screen

Full Screen

mongoDB-mesh.py

Source:mongoDB-mesh.py Github

copy

Full Screen

1from cmd3.shell import command2from cloudmesh_common.logger import LOGGER3import cloudmesh4import time5from pprint import pprint6import os7# Hello World8print ("Hello, World!")9#Activate user on cloudmesh10mesh = cloudmesh.mesh("mongo")11username = cloudmesh.load().username()12mesh.activate(username)13print (username)14#Set the default flavor and image for VM creation15cloud = 'india'16flavor = mesh.flavor('india', 'm1.medium')17image=mesh.image('india','fg452/rsinghania-001/my-ubuntu-01')18defaults = mesh.default('india', 'image', image)19defaults = mesh.default('india', 'flavor', flavor)20#start 9 VMs : For setting sharding in MongoDB21# 3 Config Server, 2 Query Routers, 4 Shard Servers22print ("Firing 9 VMs for setting up sharded MongoDB")23Server_IPs = []24for x in range(9):25 result = mesh.start(cloud='india', cm_user_id=username, flavor=flavor, image=image)26 pprint (result)27 server = result['server']['id']28 pprint (result['name'])29 ip=mesh.assign_public_ip('india', server, username)30 Server_IPs.append(ip)31#print all IPs 32Config_Server = []33Router_Server = []34Shard_Server = []35counter = 036for ip in Server_IPs: 37 command = 'ssh-keygen -R ' + ip38 os.system(command)39 if counter <= 2:40 Config_Server.append(ip)41 elif counter > 2 and counter <=4:42 Router_Server.append(ip)43 else:44 Shard_Server.append(ip) 45 counter = counter + 146 47print ("==============Printing IPs for Config Servers============")48for ip in Config_Server:49 print ip50print ("==============Printing IPs for Query Router==============")51for ip in Router_Server:52 print ip53print ("==============Printing IPs for Shard Server==============")54for ip in Shard_Server:55 print ip56# Wait for a minute for all the Vms to build and start57print "Waiting for a minute to let VMs build and start"58time.sleep(60)59# Install mongoDB on all the servers60print("=====Installing MongoDB on all the VMs and enable ubuntu firewall for connection to mongoDB instance=====")61script = """62sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB1063echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list64sudo apt-get update65sudo apt-get install -y mongodb-org"""66commands = script.split("\n")[1:]67for ip in Server_IPs:68 result = mesh.wait(ipaddr=ip, interval=10, retry=10)69 print (result)70 for command in commands:71 print ('>execute', command) 72 mesh.ssh_execute(ipaddr=ip, command=command)73# Setup Config server74print("=====Setting up Config Server=====")75script = """76sudo mkdir ~/mongo-metadata77sudo mkdir ~/mongo-log78sudo mongod --fork --configsvr --dbpath ~/mongo-metadata --logpath ~/mongo-log/log.data --port 27019"""79commands = script.split("\n")[1:]80for ip in Config_Server:81 result = mesh.wait(ipaddr=ip, interval=10, retry=10)82 print (result)83 for command in commands:84 print ('>execute', command) 85 mesh.ssh_execute(ipaddr=ip, command=command)86# Setup Router Server87print("=====Setting up Query Router=====")88port = ":27019"89ip_list = Shard_Server[0] + "," + Shard_Server[1] + "," + Shard_Server[2] + "," + Shard_Server[3]90config_command = "sudo mongos --fork --logpath ~/mongo-log/log.data --bind_ip " + ip_list + " --configdb " + Config_Server[0] + port + "," + Config_Server[1] + port + "," + Config_Server[2] + port91for ip in Router_Server:92 result = mesh.wait(ipaddr=ip, interval=10, retry=10)93 print (result)94 print ('>execute', 'sudo mkdir ~/mongo-log') 95 mesh.ssh_execute(ipaddr=ip, command='sudo mkdir ~/mongo-log')96 print ('>execute', config_command) ...

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