Best Python code snippet using tempest_python
test_agents_rbac.py
Source:test_agents_rbac.py  
...147    def _create_and_prepare_network_for_agent(self, agent_id):148        """Create network and ensure it is not hosted by agent_id."""149        network_id = self.create_network()['id']150        if self._check_network_in_dhcp_agent(network_id, agent_id):151            self.agents_client.delete_network_from_dhcp_agent(152                agent_id=agent_id, network_id=network_id)153        return network_id154    def _check_network_in_dhcp_agent(self, network_id, agent_id):155        networks = self.agents_client.list_networks_hosted_by_one_dhcp_agent(156            agent_id)['networks'] or []157        return network_id in [network['id'] for network in networks]158    @decorators.idempotent_id('dc84087b-4c2a-4878-8ed0-40370e19da17')159    @rbac_rule_validation.action(service="neutron",160                                 rule="get_dhcp-networks")161    def test_list_networks_hosted_by_one_dhcp_agent(self):162        """List networks hosted by one DHCP agent test.163        RBAC test for the neutron get_dhcp-networks policy164        """165        self.rbac_utils.switch_role(self, toggle_rbac_role=True)166        self.agents_client.list_networks_hosted_by_one_dhcp_agent(167            self.agent['id'])168    @decorators.idempotent_id('14e014ac-f355-46d3-b6d8-98f2c9ec1610')169    @rbac_rule_validation.action(service="neutron",170                                 rule="create_dhcp-network")171    def test_add_dhcp_agent_to_network(self):172        """Add DHCP agent to network test.173        RBAC test for the neutron create_dhcp-network policy174        """175        network_id = self._create_and_prepare_network_for_agent(176            self.agent['id'])177        self.rbac_utils.switch_role(self, toggle_rbac_role=True)178        self.agents_client.add_dhcp_agent_to_network(179            self.agent['id'], network_id=network_id)180        # Clean up is not necessary and might result in 409 being raised.181    @decorators.idempotent_id('937a4302-4b49-407d-9980-5843d7badc38')182    @rbac_rule_validation.action(service="neutron",183                                 rule="delete_dhcp-network")184    def test_delete_network_from_dhcp_agent(self):185        """Delete DHCP agent from network test.186        RBAC test for the neutron delete_dhcp-network policy187        """188        network_id = self._create_and_prepare_network_for_agent(189            self.agent['id'])190        self.agents_client.add_dhcp_agent_to_network(191            self.agent['id'], network_id=network_id)192        # Clean up is not necessary and might result in 409 being raised.193        self.rbac_utils.switch_role(self, toggle_rbac_role=True)194        self.agents_client.delete_network_from_dhcp_agent(...agents_client.py
Source:agents_client.py  
...42        return self.delete_resource(uri)43    def list_networks_hosted_by_one_dhcp_agent(self, agent_id):44        uri = '/agents/%s/dhcp-networks' % agent_id45        return self.list_resources(uri)46    def delete_network_from_dhcp_agent(self, agent_id, network_id):47        uri = '/agents/%s/dhcp-networks/%s' % (agent_id,48                                               network_id)49        return self.delete_resource(uri)50    def add_dhcp_agent_to_network(self, agent_id, **kwargs):51        # TODO(piyush): Current api-site doesn't contain this API description.52        # After fixing the api-site, we need to fix here also for putting the53        # link to api-site.54        # LP: https://bugs.launchpad.net/openstack-api-site/+bug/152621255        uri = '/agents/%s/dhcp-networks' % agent_id...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!!
