Best Python code snippet using lisa_python
infinibandsuit.py
Source:infinibandsuit.py  
...113            supported_features=[Infiniband],114            min_count=2,115        ),116    )117    def verify_ping_pong(self, environment: Environment, log: Logger) -> None:118        # Constants119        ping_pong_tests = ["ibv_rc_pingpong", "ibv_uc_pingpong", "ibv_ud_pingpong"]120        server_node = environment.nodes[0]121        client_node = environment.nodes[1]122        # Ensure RDMA is setup123        try:124            run_in_parallel(125                [126                    lambda: client_node.features[Infiniband],127                    lambda: server_node.features[Infiniband],128                ]129            )130        except (UnsupportedDistroException, UnsupportedKernelException) as err:131            raise SkippedException(err)...cluster_nodes_service.py
Source:cluster_nodes_service.py  
...33               'status': 'Success',34               'message': 'Cluster node successfuly submitted.'35           }, 20136def verify_machine(machine):37    verify_ping_pong(machine)38    fill_machine_data(machine)39def verify_ping_pong(machine):40    threshold = 1000041    number = random.randrange(threshold)42    url = 'http://' + machine.ip_address + '/verify/' + str(number)43    try:44        response = urlopen(url).read()45    except Exception:46        raise Exception("\nMachine didn't answer for ping pong verification! \nPlease check if machine's IP is correct.")47    if bin(number) != bin(int(response, 2)):48        raise Exception("Wrong answer for verification message.")49def fill_machine_data(machine):50    url = 'http://' + machine.ip_address + '/machine-data'51    try:52        machine_data = json.loads(urlopen(url).read())53    except Exception:...cluster_nodes_service_test.py
Source:cluster_nodes_service_test.py  
...27        self.mock_get.return_value.ok = True28        self.mock_get.return_value = Mock()29        self.mock_get.return_value.read.return_value = "11"30        self.mock_random.return_value = 331        response = verify_ping_pong(self.machine)32        self.assertTrue(self.mock_get.called)33        self.assertTrue(self.mock_random.called)34    def test_fill_machine_data(self):35        self.mock_get.return_value.ok = True36        self.mock_get.return_value = Mock()37        self.mock_get.return_value.read.return_value = '{ "CONTAINER_IP_ADDRESS": "172.18.0.4:5500", "CPU": "Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz", "GPU": "GeForce GTX 680", "IP_ADDRESS": "127.0.0.1:5500" }'38        39        fill_machine_data(self.machine)40        self.assertTrue(self.mock_get.called)41    def test_fill_machine_data_throws_Exception(self):42        self.mock_get.return_value.ok = False43        self.mock_get.return_value.read.return_value = None44        with self.assertRaises(Exception) as context:45            fill_machine_data(self.machine)46        self.assertTrue("\nMachine didn't answer for hardware verification! \nPlease check if machine's IP is correct." in str(context.exception))47        48    def test_verify_ping_pong_throws_answer_Exception(self):49        self.mock_get.return_value.read.return_value = "01"50        self.mock_random.return_value = 351        with self.assertRaises(Exception) as context:52            verify_ping_pong(self.machine)53        self.assertTrue("Wrong answer for verification message." in str(context.exception))54    def test_verify_ping_pong_throws_Exception(self):55        self.mock_get.return_value.ok = False56        self.mock_get.return_value.read.return_value = None57        with self.assertRaises(Exception) as context:...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!!
