How to use _create_port method in tempest

Best Python code snippet using tempest_python

test_ports_rbac.py

Source:test_ports_rbac.py Github

copy

Full Screen

...43 cls.ports.append(cls.port)44 ipaddr = cls.port['fixed_ips'][0]['ip_address']45 cls.port_ip_address = ipaddr46 cls.port_mac_address = cls.port['mac_address']47 def _create_port(self, **post_body):48 body = self.ports_client.create_port(**post_body)49 port = body['port']50 # Schedule port deletion with verification upon test completion51 self.addCleanup(test_utils.call_and_ignore_notfound_exc,52 self.ports_client.delete_port,53 port['id'])54 return port55 @rbac_rule_validation.action(service="neutron",56 rule="create_port")57 @decorators.idempotent_id('0ec8c551-625c-4864-8a52-85baa7c40f22')58 def test_create_port(self):59 self.rbac_utils.switch_role(self, toggle_rbac_role=True)60 post_body = {'network_id': self.network['id']}61 self._create_port(**post_body)62 @rbac_rule_validation.action(service="neutron",63 rule="create_port:binding:host_id")64 @decorators.idempotent_id('a54bd6b8-a7eb-4101-bfe8-093930b0d660')65 def test_create_port_binding_host_id(self):66 post_body = {'network_id': self.network['id'],67 'binding:host_id': "rbac_test_host"}68 self.rbac_utils.switch_role(self, toggle_rbac_role=True)69 self._create_port(**post_body)70 @rbac_rule_validation.action(service="neutron",71 rule="create_port:fixed_ips")72 @decorators.idempotent_id('2551e10d-006a-413c-925a-8c6f834c09ac')73 def test_create_port_fixed_ips(self):74 # Pick an unused ip address.75 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,76 self.subnets_client,77 self.network['id'],78 self.subnet['id'],79 1)80 fixed_ips = [{'ip_address': ip_list[0]},81 {'subnet_id': self.subnet['id']}]82 post_body = {'network_id': self.network['id'],83 'fixed_ips': fixed_ips}84 self.rbac_utils.switch_role(self, toggle_rbac_role=True)85 self._create_port(**post_body)86 @rbac_rule_validation.action(service="neutron",87 rule="create_port:mac_address")88 @decorators.idempotent_id('aee6d0be-a7f3-452f-aefc-796b4eb9c9a8')89 def test_create_port_mac_address(self):90 post_body = {'network_id': self.network['id'],91 'mac_address': data_utils.rand_mac_address()}92 self.rbac_utils.switch_role(self, toggle_rbac_role=True)93 self._create_port(**post_body)94 @rbac_rule_validation.action(service="neutron",95 rule="create_port:binding:profile")96 @decorators.idempotent_id('98fa38ab-c2ed-46a0-99f0-59f18cbd257a')97 def test_create_port_binding_profile(self):98 binding_profile = {"foo": "1"}99 post_body = {'network_id': self.network['id'],100 'binding:profile': binding_profile}101 self.rbac_utils.switch_role(self, toggle_rbac_role=True)102 self._create_port(**post_body)103 @rbac_rule_validation.action(service="neutron",104 rule="create_port:allowed_address_pairs")105 @decorators.idempotent_id('b638d1f4-d903-4ca8-aa2a-6fd603c5ec3a')106 def test_create_port_allowed_address_pairs(self):107 # Create port with allowed address pair attribute108 allowed_address_pairs = [{'ip_address': self.port_ip_address,109 'mac_address': self.port_mac_address}]110 post_body = {'network_id': self.network['id'],111 'allowed_address_pairs': allowed_address_pairs}112 self.rbac_utils.switch_role(self, toggle_rbac_role=True)113 self._create_port(**post_body)114 @rbac_rule_validation.action(service="neutron",115 rule="get_port",116 expected_error_code=404)117 @decorators.idempotent_id('a9d41cb8-78a2-4b97-985c-44e4064416f4')118 def test_show_port(self):119 self.rbac_utils.switch_role(self, toggle_rbac_role=True)120 self.ports_client.show_port(self.port['id'])121 @rbac_rule_validation.action(service="neutron",122 rule="get_port:binding:vif_type")123 @decorators.idempotent_id('125aff0b-8fed-4f8e-8410-338616594b06')124 def test_show_port_binding_vif_type(self):125 # Verify specific fields of a port126 fields = ['binding:vif_type']127 self.rbac_utils.switch_role(self, toggle_rbac_role=True)128 retrieved_port = self.ports_client.show_port(129 self.port['id'], fields=fields)['port']130 # Rather than throwing a 403, the field is not present, so raise exc.131 if fields[0] not in retrieved_port:132 raise rbac_exceptions.RbacActionFailed133 @rbac_rule_validation.action(service="neutron",134 rule="get_port:binding:vif_details")135 @decorators.idempotent_id('e42bfd77-fcce-45ee-9728-3424300f0d6f')136 def test_show_port_binding_vif_details(self):137 # Verify specific fields of a port138 fields = ['binding:vif_details']139 self.rbac_utils.switch_role(self, toggle_rbac_role=True)140 retrieved_port = self.ports_client.show_port(141 self.port['id'], fields=fields)['port']142 # Rather than throwing a 403, the field is not present, so raise exc.143 if fields[0] not in retrieved_port:144 raise rbac_exceptions.RbacActionFailed145 @rbac_rule_validation.action(service="neutron",146 rule="get_port:binding:host_id")147 @decorators.idempotent_id('8e61bcdc-6f81-443c-833e-44410266551e')148 def test_show_port_binding_host_id(self):149 # Verify specific fields of a port150 fields = ['binding:host_id']151 post_body = {'network_id': self.network['id'],152 'binding:host_id': data_utils.rand_name('host-id')}153 port = self._create_port(**post_body)154 self.rbac_utils.switch_role(self, toggle_rbac_role=True)155 retrieved_port = self.ports_client.show_port(156 port['id'], fields=fields)['port']157 # Rather than throwing a 403, the field is not present, so raise exc.158 if fields[0] not in retrieved_port:159 raise rbac_exceptions.RbacActionFailed160 @rbac_rule_validation.action(service="neutron",161 rule="get_port:binding:profile")162 @decorators.idempotent_id('d497cea9-c4ad-42e0-acc9-8d257d6b01fc')163 def test_show_port_binding_profile(self):164 # Verify specific fields of a port165 fields = ['binding:profile']166 binding_profile = {"foo": "1"}167 post_body = {'network_id': self.network['id'],168 'binding:profile': binding_profile}169 port = self._create_port(**post_body)170 self.rbac_utils.switch_role(self, toggle_rbac_role=True)171 retrieved_port = self.ports_client.show_port(172 port['id'], fields=fields)['port']173 # Rather than throwing a 403, the field is not present, so raise exc.174 if fields[0] not in retrieved_port:175 raise rbac_exceptions.RbacActionFailed176 @rbac_rule_validation.action(service="neutron",177 rule="update_port")178 @decorators.idempotent_id('afa80981-3c59-42fd-9531-3bcb2cd03711')179 def test_update_port(self):180 port = self.create_port(self.network)181 self.rbac_utils.switch_role(self, toggle_rbac_role=True)182 self.ports_client.update_port(port['id'], admin_state_up=False)183 @rbac_rule_validation.action(service="neutron",184 rule="update_port:mac_address")185 @decorators.idempotent_id('507140c8-7b14-4d63-b627-2103691d887e')186 def test_update_port_mac_address(self):187 port = self.create_port(self.network)188 self.rbac_utils.switch_role(self, toggle_rbac_role=True)189 self.ports_client.update_port(190 port['id'],191 mac_address=data_utils.rand_mac_address())192 @rbac_rule_validation.action(service="neutron",193 rule="update_port:fixed_ips")194 @decorators.idempotent_id('c091c825-532b-4c6f-a14f-affd3259c1c3')195 def test_update_port_fixed_ips(self):196 # Pick an ip address within the allocation_pools range.197 post_body = {'network_id': self.network['id']}198 port = self._create_port(**post_body)199 # Pick an unused ip address.200 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,201 self.subnets_client,202 self.network['id'],203 self.subnet['id'],204 1)205 fixed_ips = [{'ip_address': ip_list[0]}]206 self.rbac_utils.switch_role(self, toggle_rbac_role=True)207 self.ports_client.update_port(port['id'],208 fixed_ips=fixed_ips)209 @rbac_rule_validation.action(service="neutron",210 rule="update_port:port_security_enabled")211 @decorators.idempotent_id('795541af-6652-4e35-9581-fd58224f7545')212 def test_update_port_security_enabled(self):213 port = self.create_port(self.network)214 self.rbac_utils.switch_role(self, toggle_rbac_role=True)215 self.ports_client.update_port(port['id'],216 security_groups=[])217 @rbac_rule_validation.action(service="neutron",218 rule="update_port:binding:host_id")219 @decorators.idempotent_id('24206a72-0d90-4712-918c-5c9a1ebef64d')220 def test_update_port_binding_host_id(self):221 post_body = {'network_id': self.network['id'],222 'binding:host_id': 'rbac_test_host'}223 port = self._create_port(**post_body)224 updated_body = {'port_id': port['id'],225 'binding:host_id': 'rbac_test_host_updated'}226 self.rbac_utils.switch_role(self, toggle_rbac_role=True)227 self.ports_client.update_port(**updated_body)228 @rbac_rule_validation.action(service="neutron",229 rule="update_port:binding:profile")230 @decorators.idempotent_id('990ea8d1-9257-4f71-a3bf-d6d0914625c5')231 def test_update_port_binding_profile(self):232 binding_profile = {"foo": "1"}233 post_body = {'network_id': self.network['id'],234 'binding:profile': binding_profile}235 port = self._create_port(**post_body)236 new_binding_profile = {"foo": "2"}237 updated_body = {'port_id': port['id'],238 'binding:profile': new_binding_profile}239 self.rbac_utils.switch_role(self, toggle_rbac_role=True)240 self.ports_client.update_port(**updated_body)241 @rbac_rule_validation.action(service="neutron",242 rule="update_port:allowed_address_pairs")243 @decorators.idempotent_id('729c2151-bb49-4f4f-9d58-3ed8819b7582')244 def test_update_port_allowed_address_pairs(self):245 # Pick an unused ip address.246 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,247 self.subnets_client,248 self.network['id'],249 self.subnet['id'],250 1)251 # Update allowed address pair attribute of port252 address_pairs = [{'ip_address': ip_list[0],253 'mac_address': data_utils.rand_mac_address()}]254 post_body = {'network_id': self.network['id']}255 port = self._create_port(**post_body)256 self.rbac_utils.switch_role(self, toggle_rbac_role=True)257 self.ports_client.update_port(port['id'],258 allowed_address_pairs=address_pairs)259 @rbac_rule_validation.action(service="neutron",260 rule="delete_port",261 expected_error_code=404)262 @decorators.idempotent_id('1cf8e582-bc09-46cb-b32a-82bf991ad56f')263 def test_delete_port(self):264 port = self._create_port(network_id=self.network['id'])265 self.rbac_utils.switch_role(self, toggle_rbac_role=True)...

Full Screen

Full Screen

test_ovn_vtep.py

Source:test_ovn_vtep.py Github

copy

Full Screen

...20 binding = {OVN_PROFILE: {"vtep-physical-switch": 'psw1',21 "vtep-logical-switch": 'lsw1'}}22 with self.network() as n:23 with self.subnet(n):24 res = self._create_port(self.fmt, n['network']['id'],25 arg_list=(OVN_PROFILE,),26 **binding)27 port = self.deserialize(self.fmt, res)28 self.assertEqual(binding[OVN_PROFILE],29 port['port'][OVN_PROFILE])30 def test_create_port_with_only_vtep_physical_switch(self):31 binding = {OVN_PROFILE: {"vtep-physical-switch": 'psw'}}32 with self.network() as n:33 with self.subnet(n):34 self._create_port(self.fmt, n['network']['id'],35 arg_list=(OVN_PROFILE,),36 expected_res_status=400,37 **binding)38 def test_create_port_with_only_vtep_logical_switch(self):39 binding = {OVN_PROFILE: {"vtep-logical-switch": 'lsw1'}}40 with self.network() as n:41 with self.subnet(n):42 self._create_port(self.fmt, n['network']['id'],43 arg_list=(OVN_PROFILE,),44 expected_res_status=400,45 **binding)46 def test_create_port_with_invalid_vtep_logical_switch(self):47 binding = {OVN_PROFILE: {"vtep-logical-switch": 1234,48 "vtep-physical-switch": "psw1"}}49 with self.network() as n:50 with self.subnet(n):51 self._create_port(self.fmt, n['network']['id'],52 arg_list=(OVN_PROFILE,),53 expected_res_status=400,54 **binding)55 def test_create_port_with_vtep_options_and_parent_name_tag(self):56 binding = {OVN_PROFILE: {"vtep-logical-switch": "lsw1",57 "vtep-physical-switch": "psw1",58 "parent_name": "pname", "tag": 22}}59 with self.network() as n:60 with self.subnet(n):61 self._create_port(self.fmt, n['network']['id'],62 arg_list=(OVN_PROFILE,),63 expected_res_status=400,64 **binding)65 def test_create_port_with_vtep_options_and_check_vtep_keys(self):66 port = {67 'id': 'foo-port',68 'device_owner': 'compute:None',69 'fixed_ips': [{'subnet_id': 'foo-subnet',70 'ip_address': '10.0.0.11'}],71 OVN_PROFILE: {"vtep-logical-switch": "lsw1",72 "vtep-physical-switch": "psw1"}73 }74 ovn_port_info = (75 self.mech_driver._ovn_client._get_port_options(port))...

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