Best Python code snippet using tempest_python
test_dhcp_agent_scheduler.py
Source:test_dhcp_agent_scheduler.py
...38 self.network['id'])39 agents = body['agents']40 self.assertIsNotNone(agents)41 agent = agents[0]42 self.assertTrue(self._check_network_in_dhcp_agent(43 self.network['id'], agent))44 def _check_network_in_dhcp_agent(self, network_id, agent):45 network_ids = []46 body = self.admin_client.list_networks_hosted_by_one_dhcp_agent(47 agent['id'])48 networks = body['networks']49 for network in networks:50 network_ids.append(network['id'])51 return network_id in network_ids52 @test.attr(type='smoke')53 @test.idempotent_id('a0856713-6549-470c-a656-e97c8df9a14d')54 def test_add_remove_network_from_dhcp_agent(self):55 # The agent is now bound to the network, we can free the port56 self.client.delete_port(self.port['id'])57 self.ports.remove(self.port)58 agent = dict()59 agent['agent_type'] = None60 body = self.admin_client.list_agents()61 agents = body['agents']62 for a in agents:63 if a['agent_type'] == 'DHCP agent':64 agent = a65 break66 self.assertEqual(agent['agent_type'], 'DHCP agent', 'Could not find '67 'DHCP agent in agent list though dhcp_agent_scheduler'68 ' is enabled.')69 network = self.create_network()70 network_id = network['id']71 if self._check_network_in_dhcp_agent(network_id, agent):72 self._remove_network_from_dhcp_agent(network_id, agent)73 self._add_dhcp_agent_to_network(network_id, agent)74 else:75 self._add_dhcp_agent_to_network(network_id, agent)76 self._remove_network_from_dhcp_agent(network_id, agent)77 def _remove_network_from_dhcp_agent(self, network_id, agent):78 self.admin_client.remove_network_from_dhcp_agent(79 agent_id=agent['id'],80 network_id=network_id)81 self.assertFalse(self._check_network_in_dhcp_agent(82 network_id, agent))83 def _add_dhcp_agent_to_network(self, network_id, agent):84 self.admin_client.add_dhcp_agent_to_network(agent['id'],85 network_id)86 self.assertTrue(self._check_network_in_dhcp_agent(...
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!!