Best Python code snippet using tempest_python
base.py
Source:base.py
...32 cls.network = cls.create_network()33 cls.subnet = cls.create_subnet(cls.network)34 cls.host_id = socket.gethostname()35 @classmethod36 def resource_cleanup(cls):37 if not test.is_extension_enabled('flow_classifier', 'network'):38 msg = "FlowClassifier Extension not enabled."39 raise cls.skipException(msg)40 super(BaseFlowClassifierTest, cls).resource_cleanup()41 @classmethod42 def _create_port(cls, network, **kwargs):43 body = cls.admin_ports_client.create_port(44 network_id=network['id'],45 **kwargs)46 port = body['port']47 return port48 def _try_create_flowclassifier(self, **kwargs):49 if 'logical_source_port' not in kwargs:50 port_kwargs = {"binding:host_id": self.host_id}51 port = self._create_port(network=self.network, **port_kwargs)52 self.addCleanup(self._try_delete_port, port['id'])53 kwargs['logical_source_port'] = port['id']54 if 'source_ip_prefix' not in kwargs:55 port_ip_prefix = str(netaddr.IPNetwork(56 port['fixed_ips'][0]['ip_address']))57 kwargs['source_ip_prefix'] = port_ip_prefix58 fc = self.create_flowclassifier(**kwargs)59 self.addCleanup(self._try_delete_flowclassifier, fc['id'])60 return fc61 def _try_delete_port(self, port_id):62 try:63 self.admin_ports_client.delete_port(port_id)64 except lib_exc.NotFound:65 pass66 body = self.admin_ports_client.list_ports()67 ports_list = body['ports']68 self.assertNotIn(port_id, [n['id'] for n in ports_list])69 def _try_delete_flowclassifier(self, fc_id):70 # delete flowclassifier, if it exists71 try:72 self.flowclassifier_client.delete_flowclassifier(fc_id)73 # if flowclassifier is not found, this means it was deleted74 except lib_exc.NotFound:75 pass76 body = self.flowclassifier_client.list_flowclassifiers()77 fc_list = body['flow_classifiers']78 self.assertNotIn(fc_id, [n['id'] for n in fc_list])79class BaseSfcTest(80 sfc_client.SfcClientMixin, BaseFlowClassifierTest81):82 @classmethod83 def resource_setup(cls):84 super(BaseSfcTest, cls).resource_setup()85 if not test.is_extension_enabled('sfc', 'network'):86 msg = "Sfc Extension not enabled."87 raise cls.skipException(msg)88 @classmethod89 def resource_cleanup(cls):90 if not test.is_extension_enabled('sfc', 'network'):91 msg = "Sfc Extension not enabled."92 raise cls.skipException(msg)93 super(BaseSfcTest, cls).resource_cleanup()94 def _try_create_port_pair(self, **kwargs):95 if 'ingress' not in kwargs or 'egress' not in 'kwargs':96 router = self.admin_routers_client.create_router(97 name=data_utils.rand_name('router-'))['router']98 self.addCleanup(99 self.admin_routers_client.delete_router, router['id'])100 port_kwargs = {"binding:host_id": self.host_id}101 port = self._create_port(102 network=self.network, **port_kwargs)103 self.addCleanup(self._try_delete_port, port['id'])104 self.admin_routers_client.add_router_interface(105 router['id'], port_id=port['id'])106 self.addCleanup(self.admin_routers_client.remove_router_interface,107 router['id'],...
test_users.py
Source:test_users.py
...5 @classmethod6 def resource_setup(cls):7 super(StacktaskProjectAdminTestUsers, cls).resource_setup()8 @classmethod9 def resource_cleanup(cls):10 super(StacktaskProjectAdminTestUsers, cls).resource_cleanup()11 @decorators.idempotent_id('90fd103c-e071-11e5-893b-74d4358b0331')12 def test_get_users(self):13 users = self.stacktask_client.user_list()...
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!!