How to use create_router method in tempest

Best Python code snippet using tempest_python

test_routers_rbac.py

Source:test_routers_rbac.py Github

copy

Full Screen

...40 cls.subnet = cls.create_subnet(cls.network)41 cls.ip_range = netaddr.IPRange(42 cls.subnet['allocation_pools'][0]['start'],43 cls.subnet['allocation_pools'][0]['end'])44 cls.router = cls.create_router()45 @rbac_rule_validation.action(service="neutron",46 rule="create_router")47 @decorators.idempotent_id('acc5005c-bdb6-4192-bc9f-ece9035bb488')48 def test_create_router(self):49 """Create Router50 RBAC test for the neutron create_router policy51 """52 self.rbac_utils.switch_role(self, toggle_rbac_role=True)53 router = self.routers_client.create_router()54 self.addCleanup(self.routers_client.delete_router,55 router['router']['id'])56 @rbac_rule_validation.action(57 service="neutron",58 rule="create_router:external_gateway_info:enable_snat")59 @decorators.idempotent_id('3c5acd49-0ec7-4109-ab51-640557b48ebc')60 def test_create_router_enable_snat(self):61 """Create Router Snat62 RBAC test for the neutron63 create_router:external_gateway_info:enable_snat policy64 """65 name = data_utils.rand_name(self.__class__.__name__ + '-snat-router')66 external_gateway_info = {'network_id': self.network['id'],67 'enable_snat': True}68 self.rbac_utils.switch_role(self, toggle_rbac_role=True)69 router = self.routers_client.create_router(70 name=name, external_gateway_info=external_gateway_info)71 self.addCleanup(self.routers_client.delete_router,72 router['router']['id'])73 @rbac_rule_validation.action(74 service="neutron",75 rule="create_router:external_gateway_info:external_fixed_ips")76 @decorators.idempotent_id('d0354369-a040-4349-b869-645c8aed13cd')77 def test_create_router_external_fixed_ips(self):78 """Create Router Fixed IPs79 RBAC test for the neutron80 create_router:external_gateway_info:external_fixed_ips policy81 """82 name = data_utils.rand_name(self.__class__.__name__ + '-snat-router')83 # Pick an unused IP address.84 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,85 self.subnets_client,86 self.network['id'],87 self.subnet['id'],88 1)89 external_fixed_ips = {'subnet_id': self.subnet['id'],90 'ip_address': ip_list[0]}91 external_gateway_info = {'network_id': self.network['id'],92 'enable_snat': False,93 'external_fixed_ips': [external_fixed_ips]}94 self.rbac_utils.switch_role(self, toggle_rbac_role=True)95 router = self.routers_client.create_router(96 name=name, external_gateway_info=external_gateway_info)97 self.addCleanup(self.routers_client.delete_router,98 router['router']['id'])99 @rbac_rule_validation.action(service="neutron",100 rule="get_router",101 expected_error_code=404)102 @decorators.idempotent_id('bfbdbcff-f115-4d3e-8cd5-6ada33fd0e21')103 def test_show_router(self):104 """Get Router105 RBAC test for the neutron get_router policy106 """107 self.rbac_utils.switch_role(self, toggle_rbac_role=True)108 self.routers_client.show_router(self.router['id'])109 @rbac_rule_validation.action(110 service="neutron", rule="update_router")111 @decorators.idempotent_id('3d182f4e-0023-4218-9aa0-ea2b0ae0bd7a')112 def test_update_router(self):113 """Update Router114 RBAC test for the neutron update_router policy115 """116 new_name = data_utils.rand_name(self.__class__.__name__ +117 '-new-router-name')118 self.rbac_utils.switch_role(self, toggle_rbac_role=True)119 self.routers_client.update_router(self.router['id'],120 name=new_name)121 @rbac_rule_validation.action(122 service="neutron", rule="update_router:external_gateway_info")123 @decorators.idempotent_id('5a6ae104-a9c3-4b56-8622-e1a0a0194474')124 def test_update_router_external_gateway_info(self):125 """Update Router External Gateway Info126 RBAC test for the neutron127 update_router:external_gateway_info policy128 """129 self.rbac_utils.switch_role(self, toggle_rbac_role=True)130 self.routers_client.update_router(self.router['id'],131 external_gateway_info={})132 @rbac_rule_validation.action(133 service="neutron",134 rule="update_router:external_gateway_info:network_id")135 @decorators.idempotent_id('f1fc5a23-e3d8-44f0-b7bc-47006ad9d3d4')136 def test_update_router_external_gateway_info_network_id(self):137 """Update Router External Gateway Info Network Id138 RBAC test for the neutron139 update_router:external_gateway_info:network_id policy140 """141 self.rbac_utils.switch_role(self, toggle_rbac_role=True)142 self.routers_client.update_router(143 self.router['id'],144 external_gateway_info={'network_id': self.network['id']})145 self.addCleanup(146 self.routers_client.update_router,147 self.router['id'],148 external_gateway_info=None)149 @rbac_rule_validation.action(150 service="neutron",151 rule="update_router:external_gateway_info:enable_snat")152 @decorators.idempotent_id('515a2954-3d79-4695-aeb9-d1c222765840')153 def test_update_router_enable_snat(self):154 """Update Router External Gateway Info Enable Snat155 RBAC test for the neutron156 update_router:external_gateway_info:enable_snat policy157 """158 self.rbac_utils.switch_role(self, toggle_rbac_role=True)159 self.routers_client.update_router(160 self.router['id'],161 external_gateway_info={'network_id': self.network['id'],162 'enable_snat': True})163 self.addCleanup(164 self.routers_client.update_router,165 self.router['id'],166 external_gateway_info=None)167 @rbac_rule_validation.action(168 service="neutron",169 rule="update_router:external_gateway_info:external_fixed_ips")170 @decorators.idempotent_id('f429e5ee-8f0a-4667-963e-72dd95d5adee')171 def test_update_router_external_fixed_ips(self):172 """Update Router External Gateway Info External Fixed Ips173 RBAC test for the neutron174 update_router:external_gateway_info:external_fixed_ips policy175 """176 # Pick an unused IP address.177 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,178 self.subnets_client,179 self.network['id'],180 self.subnet['id'],181 1)182 external_fixed_ips = {'subnet_id': self.subnet['id'],183 'ip_address': ip_list[0]}184 external_gateway_info = {'network_id': self.network['id'],185 'external_fixed_ips': [external_fixed_ips]}186 self.rbac_utils.switch_role(self, toggle_rbac_role=True)187 self.routers_client.update_router(188 self.router['id'],189 external_gateway_info=external_gateway_info)190 self.addCleanup(191 self.routers_client.update_router,192 self.router['id'],193 external_gateway_info=None)194 @rbac_rule_validation.action(service="neutron",195 rule="delete_router",196 expected_error_code=404)197 @decorators.idempotent_id('c0634dd5-0467-48f7-a4ae-1014d8edb2a7')198 def test_delete_router(self):199 """Delete Router200 RBAC test for the neutron delete_router policy201 """202 router = self.create_router()203 self.rbac_utils.switch_role(self, toggle_rbac_role=True)204 self.routers_client.delete_router(router['id'])205 @rbac_rule_validation.action(service="neutron",206 rule="add_router_interface",207 expected_error_code=404)208 @decorators.idempotent_id('a0627778-d68d-4913-881b-e345360cca19')209 def test_add_router_interfaces(self):210 """Add Router Interface211 RBAC test for the neutron add_router_interface policy212 """213 network = self.create_network()214 subnet = self.create_subnet(network)215 router = self.create_router()216 self.rbac_utils.switch_role(self, toggle_rbac_role=True)217 self.routers_client.add_router_interface(218 router['id'], subnet_id=subnet['id'])219 self.addCleanup(220 test_utils.call_and_ignore_notfound_exc,221 self.routers_client.remove_router_interface,222 router['id'],223 subnet_id=subnet['id'])224 @rbac_rule_validation.action(service="neutron",225 rule="remove_router_interface",226 expected_error_code=404)227 @decorators.idempotent_id('ff2593a4-2bff-4c27-97d3-dd3702b27dfb')228 def test_remove_router_interfaces(self):229 """Remove Router Interface230 RBAC test for the neutron remove_router_interface policy231 """232 network = self.create_network()233 subnet = self.create_subnet(network)234 router = self.create_router()235 self.routers_client.add_router_interface(236 router['id'], subnet_id=subnet['id'])237 self.addCleanup(test_utils.call_and_ignore_notfound_exc,238 self.routers_client.remove_router_interface,239 router['id'],240 subnet_id=subnet['id'])241 self.rbac_utils.switch_role(self, toggle_rbac_role=True)242 self.routers_client.remove_router_interface(243 router['id'],...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

1# Test file2# Jakkawan Intaratchaiyakij 610700233import pytest4from Router import *5def create_router():6 r1 = Router("Huawei", "Special X", "R1")7 r2 = Router("Cisco", "R7777", "R2")8 r1.add_interface("G0/0")9 r2.add_interface("G0/1")10 return r1,r211def test_add_interface():12 r1,r2 = create_router()13 assert r1.interfaces == {"G0/0": {'ip': 'unassigned', 'status': 'shutdown', 'connect': ['none', 'none']}}14 assert r2.interfaces == {"G0/1": {'ip': 'unassigned', 'status': 'shutdown', 'connect': ['none', 'none']}}15def test_connect_to():16 r1,r2 = create_router()17 r1.connect_to("G0/0", r2, "G0/1")18 assert r1.interfaces["G0/0"]['connect'] == ["R2", "G0/1"]19def test_add_ip():20 r1,r2 = create_router()21 r1.add_ip("G0/0", "192.168.1.1/24")22 assert r1.interfaces['G0/0']['ip'] == "192.168.1.1/24"23def test_change_status():24 r1,r2 = create_router()25 r1.change_status("G0/0", "no-shutdown")26 assert r1.interfaces["G0/0"]["status"] == "no-shutdown"27def test_show_interfaces():28 r1,r2 = create_router()29 r1.add_interface("G0/1")30 r1.add_interface("G0/2")31 assert r1.show_interfaces() == "Show Interfaces of R1\nR1 has 3 interfaces\nG0/0 IP-Address: unassigned \"shutdown\"\nG0/1 IP-Address: unassigned \"shutdown\"\nG0/2 IP-Address: unassigned \"shutdown\"\n"32 assert r2.show_interfaces() == "Show Interfaces of R2\nR2 has 1 interfaces\nG0/1 IP-Address: unassigned \"shutdown\"\n"33def test_show_cdp():34 r1,r2 = create_router()35 r3 = Router("Amazon", "RX9898", "R3")36 r1.add_interface("G0/1")37 r3.add_interface("G0/0")38 r1.connect_to("G0/0", r2, "G0/1")39 r1.connect_to("G0/1", r3, "G0/0")40 assert r1.show_cdp() == "R1 interface G0/0 connect to R2 on interface G0/1\nR1 interface G0/1 connect to R3 on interface G0/0\n"41def test_show_info():42 r1,r2 = create_router()43 assert r1.show_info() == "Brand: Huawei\nModel: Special X\nHostname: R1\n"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful