Best Python code snippet using avocado_python
cfgen
Source:cfgen
...601 if not os.path.isfile(path):602 return None603 with open(path) as f:604 return f.readline().strip()605def get_all_local_addrs() -> List[str]:606 interface_details = psutil.net_if_addrs()607 ips = []608 for iface in interface_details.values():609 ips.append(iface[0].address)610 return ips611def is_localhost(hostname: str) -> bool:612 assert hostname613 m_id = minion_id()614 ids = [m_id] if m_id is not None else []615 ids.extend(get_all_local_addrs())616 for item in socket.gethostbyname_ex(hostname):617 if any(x in item for x in ids):618 return True619 return False620@repeat_on_cmd_timeout(max_retries=-1)621def run_command(hostname: str, *args: str) -> str:622 assert hostname623 return subprocess.check_output(args if is_localhost(hostname) else624 ['ssh', hostname, *args],625 timeout=15).decode()626def validate_facter(hostname: str) -> None:627 ver_str = run_command(hostname, 'facter', '--version')628 # The output may contain commit id like this:629 # 3.14.8 (commit 4339472f441868ecdae694ffc71e7c8ed0fc24e3)...
test_utils_network.py
Source:test_utils_network.py
...25 tracker = ports.PortTracker()26 tracker.retained_ports = [22]27 tracker.release_port(22)28 self.assertNotIn(22, tracker.retained_ports)29def get_all_local_addrs():30 """31 Returns all ipv4/ipv6 addresses that are associated with this machine32 """33 ipv4_addrs = []34 ipv6_addrs = []35 for interface in netifaces.interfaces():36 ifaddresses = netifaces.ifaddresses(interface)37 ipv4_addrs += [_['addr']38 for _ in ifaddresses.get(netifaces.AF_INET, [])]39 ipv6_addrs += [_['addr']40 for _ in ifaddresses.get(netifaces.AF_INET6, [])]41 return ipv4_addrs, ipv6_addrs42class FreePort(unittest.TestCase):43 @unittest.skipUnless(HAS_NETIFACES,44 "netifaces library not available")45 def test_is_port_free(self):46 port = ports.find_free_port(sequent=False)47 self.assertTrue(ports.is_port_free(port, "localhost"))48 local_addrs = get_all_local_addrs()49 ipv4_addrs = ["localhost", ""] + list(local_addrs[0])50 ipv6_addrs = ["localhost", ""] + list(local_addrs[1])51 good = []52 bad = []53 skip = []54 sock = None55 for family in ports.FAMILIES:56 if family == socket.AF_INET:57 addrs = ipv4_addrs58 else:59 addrs = ipv6_addrs60 for addr in addrs:61 for protocol in ports.PROTOCOLS:62 try:...
test_network.py
Source:test_network.py
...24 tracker = ports.PortTracker()25 tracker.retained_ports = [22]26 tracker.release_port(22)27 self.assertNotIn(22, tracker.retained_ports)28def get_all_local_addrs():29 """30 Returns all ipv4/ipv6 addresses that are associated with this machine31 """32 ipv4_addrs = []33 ipv6_addrs = []34 for interface in netifaces.interfaces():35 ifaddresses = netifaces.ifaddresses(interface)36 ipv4_addrs += [_["addr"] for _ in ifaddresses.get(netifaces.AF_INET, [])]37 ipv6_addrs += [_["addr"] for _ in ifaddresses.get(netifaces.AF_INET6, [])]38 if ipv4_addrs:39 ipv4_addrs += ["localhost", ""]40 if ipv6_addrs:41 ipv6_addrs += ["localhost", ""]42 return ipv4_addrs, ipv6_addrs...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!