How to use find_free_ports method in avocado

Best Python code snippet using avocado_python

vnc.py

Source:vnc.py Github

copy

Full Screen

...26 sock.connect((VNC_ADDR, port))27 except ConnectionRefusedError:28 return False29 return True30def find_free_ports(count: int) -> List[int]:31 result = []32 for port in range(VNC_PORT_START, VNC_PORT_END):33 if check_bind(port):34 result.append(port)35 if len(result) >= count:36 break37 assert len(result) == count38 return result39class Vnc(QemuSystemTest):40 """41 :avocado: tags=vnc,quick42 """43 def test_no_vnc(self):44 self.vm.add_args('-nodefaults', '-S')45 self.vm.launch()46 self.assertFalse(self.vm.qmp('query-vnc')['return']['enabled'])47 def test_no_vnc_change_password(self):48 self.vm.add_args('-nodefaults', '-S')49 self.vm.launch()50 self.assertFalse(self.vm.qmp('query-vnc')['return']['enabled'])51 set_password_response = self.vm.qmp('change-vnc-password',52 password='new_password')53 self.assertIn('error', set_password_response)54 self.assertEqual(set_password_response['error']['class'],55 'GenericError')56 self.assertEqual(set_password_response['error']['desc'],57 'Could not set password')58 def test_change_password_requires_a_password(self):59 self.vm.add_args('-nodefaults', '-S', '-vnc', ':0')60 self.vm.launch()61 self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])62 set_password_response = self.vm.qmp('change-vnc-password',63 password='new_password')64 self.assertIn('error', set_password_response)65 self.assertEqual(set_password_response['error']['class'],66 'GenericError')67 self.assertEqual(set_password_response['error']['desc'],68 'Could not set password')69 def test_change_password(self):70 self.vm.add_args('-nodefaults', '-S', '-vnc', ':0,password=on')71 self.vm.launch()72 self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])73 set_password_response = self.vm.qmp('change-vnc-password',74 password='new_password')75 self.assertEqual(set_password_response['return'], {})76 def test_change_listen(self):77 a, b, c = find_free_ports(3)78 self.assertFalse(check_connect(a))79 self.assertFalse(check_connect(b))80 self.assertFalse(check_connect(c))81 self.vm.add_args('-nodefaults', '-S', '-vnc', f'{VNC_ADDR}:{a - 5900}')82 self.vm.launch()83 self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(a))84 self.assertTrue(check_connect(a))85 self.assertFalse(check_connect(b))86 self.assertFalse(check_connect(c))87 res = self.vm.qmp('display-update', type='vnc',88 addresses=[{'type': 'inet', 'host': VNC_ADDR,89 'port': str(b)},90 {'type': 'inet', 'host': VNC_ADDR,91 'port': str(c)}])...

Full Screen

Full Screen

dockers.py

Source:dockers.py Github

copy

Full Screen

...10 return 'wolfpack'11def killall(client):12 for container in client.containers.list():13 container.kill()14def find_free_ports():15 bolt = 7687 16 http = 7474 17 #find first free port for bolt listener18# with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:19# s.bind(('', 0))20# s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)21# bolt = s.getsockname()[1]22# #find second free port for http listener while bolt listener is still up23# with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as x:24# x.bind(('', 0))25# x.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)26# http = x.getsockname()[1]27 return bolt,http28def list_db(client):29 container_info = []30 for container in client.containers.list():31 container_info.append({"id" :container.id, "status": container.status, "name": container.name})32 return container_info33def delete_db(client, id):34 container = client.containers.get(id)35 container.kill()36def create_db(client):37 38 (bolt,http) = find_free_ports()39 bindip = '127.0.0.1'40 newpass = pw_gen(15)41 enviro = ['JAVA_OPTS=-Xmx1g','NEO4J_AUTH=neo4j/' + newpass]42 porto = {'7687/tcp':(bindip,bolt),'7474/tcp':(bindip,http)}43 #if we need persistence. Which we don't right now44 volumeo = {'/logs': {'bind': '/logs', 'mode': 'rw'},'/data': {'bind': '/data','mode':'rw'}}45 containero = 'neo4j:3.0'46 c = client.containers.run(containero,environment=enviro,ports=porto,detach=True)47 while(True):48 time.sleep(2)49 c.reload()50 if(c.status == 'running'):51 break 52 containerstats = {"bolt": bolt, "http": http, "ip": bindip, "id": c.id, "password": newpass}...

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 avocado 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