How to use _delete_port method in tempest

Best Python code snippet using tempest_python

test_nsx_mac_learning.py

Source:test_nsx_mac_learning.py Github

copy

Full Screen

...82 mac_learning_enabled=False,83 port_security_enabled=True,84 security_groups=updated_sec_grp)85 return updated_port86 def _delete_port(self, port):87 port_id = port['id']88 self.ports_client.delete_port(port_id)89 body = self.ports_client.list_ports()90 ports_list = body['ports']91 if len(ports_list) > 0:92 self.assertFalse(port_id in [n['id'] for n in ports_list],93 "Deleted port still present in ports list")94 def _conv_switch_prof_to_dict(self, switch_profiles):95 switch_prof_dict = {}96 for i in range(len(switch_profiles)):97 switch_prof_dict.update(98 {switch_profiles[i]['key']: switch_profiles[i]['value']})99 return switch_prof_dict100 def _check_mac_learning(self, port, mac_learn_state=True):101 # Enabling MAC Learning requires port security=False and no sec grps102 nsxport_mac_learning = self._get_nsx_mac_learning_enabled(port)103 if mac_learn_state:104 self.assertEmpty(port['security_groups'],105 "Sec grp for mac learn port is not empty")106 self.assertFalse(port['port_security_enabled'],107 "Port security is enabled")108 self.assertTrue(port['mac_learning_enabled'],109 "Mac Learning is not enabled")110 self.assertEqual(nsxport_mac_learning,111 port['mac_learning_enabled'],112 "OS and NSX mac learn states don't match")113 else:114 self.assertTrue(port['port_security_enabled'],115 "Port security is disabled")116 if 'mac_learning_enabled' in port.keys():117 self.assertFalse(port['mac_learning_enabled'],118 "Mac Learning is enabled")119 self.assertEqual(nsxport_mac_learning,120 port['mac_learning_enabled'],121 "OS and NSX mac learn states don't match")122 @test.attr(type='nsxv3')123 @decorators.idempotent_id('d4c533d4-194e-4d72-931d-a120cd3dd3b2')124 def test_create_mac_learning_port(self):125 """126 Test creation of MAC Learning enabled port127 """128 port = self._create_mac_learn_enabled_port(self.network)129 self.addCleanup(test_utils.call_and_ignore_notfound_exc,130 self._delete_port, port)131 self._check_mac_learning(port, mac_learn_state=True)132 @test.attr(type='nsxv3')133 @decorators.idempotent_id('d5067c7e-127b-4676-8b33-c421dcc8d6ae')134 def test_list_mac_learning_port(self):135 """136 Create port with MAC learning enabled. Create vanilla port.137 Verify that the created ports are included in list_ports().138 """139 mac_lrn_port = self._create_mac_learn_enabled_port(self.network)140 vanilla_name = data_utils.rand_name('vanilla_port-')141 vanilla_port = self.create_port(self.network, name=vanilla_name)142 self.addCleanup(test_utils.call_and_ignore_notfound_exc,143 self._delete_port, mac_lrn_port)144 self.addCleanup(test_utils.call_and_ignore_notfound_exc,145 self._delete_port, vanilla_port)146 self._check_mac_learning(mac_lrn_port, mac_learn_state=True)147 self._check_mac_learning(vanilla_port, mac_learn_state=False)148 body = self.ports_client.list_ports()149 nill_nsx = self.nsx.get_logical_port(vanilla_port['name'])150 ml_port_nsx = self.nsx.get_logical_port(mac_lrn_port['name'])151 test_ports_in_body = []152 # Verify the each port exists in the list of all ports153 for tport in body['ports']:154 if(nill_nsx['display_name'] == tport['name']):155 test_ports_in_body.append(nill_nsx['display_name'])156 if(ml_port_nsx['display_name'] == tport['name']):157 test_ports_in_body.append(ml_port_nsx['display_name'])158 self.assertEqual(len(test_ports_in_body), 2,159 'List ports does not match num of created ports')160 @test.attr(type='nsxv3')161 @decorators.idempotent_id('d2eaadb2-52e3-42c1-8225-7380cd70a82c')162 def test_show_mac_learning_port(self):163 """164 Create port with MAC learning enabled with OS. Test port show api165 on the MAC enabled port.166 """167 port = self._create_mac_learn_enabled_port(self.network)168 self.addCleanup(test_utils.call_and_ignore_notfound_exc,169 self._delete_port, port)170 nsx_port = self.nsx.get_logical_port(port['name'])171 nsxport_mac_learning = self._get_nsx_mac_learning_enabled(port)172 body = self.ports_client.show_port(port['id'])173 show_port_result = body['port']174 # Check the port ID exists and the MAC learning state and name match175 self.assertIn('id', show_port_result, "Port doesn't have id set")176 self.assertEqual(nsxport_mac_learning,177 show_port_result['mac_learning_enabled'],178 "OS and NSX Mac learning states do not match")179 self.assertEqual(nsx_port['display_name'], show_port_result['name'],180 "OS and NSX port names do not match")181 # from upstream tempest test_show_port()182 self.assertThat(port,183 custom_matchers.MatchesDictExceptForKeys184 (show_port_result, excluded_keys=['extra_dhcp_opts',185 'created_at',186 'updated_at']))187 @test.attr(type='nsxv3')188 @decorators.idempotent_id('4d5844bb-88d4-4cdc-b545-6cd9160ae351')189 def test_update_mac_learning_port(self):190 """191 Create a MAC learning-enabled port on network. Update the port's192 name. Check name and MAC learning configuration.193 """194 test_port = self._create_mac_learn_enabled_port(self.network)195 self.addCleanup(test_utils.call_and_ignore_notfound_exc,196 self._delete_port, test_port)197 update_port_name = data_utils.rand_name('updated_port-')198 updated_os_port = self.update_port(test_port,199 name=update_port_name)200 updated_nsx_port = self.nsx.get_logical_port(updated_os_port['name'])201 # Assert if NSXT and OS names do not match202 self.assertEqual(updated_nsx_port['display_name'],203 updated_os_port['name'],204 "Updated names do not match")205 # Check MAC Learn state between NSXT and OS match.206 nsxport_mac_learning_state = self._get_nsx_mac_learning_enabled(207 updated_os_port)208 self.assertEqual(nsxport_mac_learning_state,209 updated_os_port['mac_learning_enabled'],210 "MAC learning states do not match for %s"211 % updated_nsx_port['display_name'])212 @test.attr(type='nsxv3')213 @decorators.idempotent_id('e2295017-b3c4-4cdd-b8e2-daa51aaf7590')214 def test_delete_mac_learning_port(self):215 """216 Create MAC learning-enabled port on network. Verify port on217 NSX and OS. Delete port.218 """219 test_port = self._create_mac_learn_enabled_port(self.network)220 self.addCleanup(test_utils.call_and_ignore_notfound_exc,221 self._delete_port, test_port)222 nsx_port = self.nsx.get_logical_port(test_port['name'])223 # Check created port name matches name on NSXT and NSXT id exists224 self.assertIsNotNone(nsx_port['id'],225 "Port %s is None" % test_port['name'])226 self.assertEqual(nsx_port['display_name'], test_port['name'],227 "OS port and NSX port name do not match")228 self._delete_port(test_port)229 self.assertIsNone(self.nsx.get_logical_port(test_port['name']),230 "Port %s is not None" % test_port['name'])231 @test.attr(type='nsxv3')232 @decorators.idempotent_id('5105d8b5-5136-4789-9991-7e419d980169')233 def test_create_enable_mac_learning_port_delete(self):234 """235 CRUD Workflow 1236 Create vanilla network port237 Update port with options required and enable MAC Learning238 Delete port239 """240 test_port_name = data_utils.rand_name('port-')241 test_port = self.create_port(self.network, name=test_port_name)242 self.addCleanup(test_utils.call_and_ignore_notfound_exc,243 self._delete_port, test_port)244 self._check_mac_learning(test_port, mac_learn_state=False)245 updated_os_port = self._update_port_enable_mac_learning(test_port)246 self._check_mac_learning(updated_os_port, mac_learn_state=True)247 self._delete_port(updated_os_port)248 self.assertIsNone(self.nsx.get_logical_port(updated_os_port['name']),249 "Port %s is not None" % updated_os_port['name'])250 @test.attr(type='nsxv3')251 @decorators.idempotent_id('b7ecc93d-6c9b-4958-9a08-bc85d2946c03')252 def test_create_toggle_mac_learning_port_delete(self):253 """254 CRUD Workflow 2255 Create port with MAC Learning enabled256 Update port, disabling MAC Learning257 Update port, re-enabling MAC Learning258 Delete port259 """260 test_port = self._create_mac_learn_enabled_port(self.network)261 self.addCleanup(test_utils.call_and_ignore_notfound_exc,262 self._delete_port, test_port)263 self._check_mac_learning(test_port, mac_learn_state=True)264 ml_off_port = self._update_port_disable_mac_learning(test_port)265 self._check_mac_learning(ml_off_port, mac_learn_state=False)266 ml_on_port = self._update_port_enable_mac_learning(ml_off_port)267 self._check_mac_learning(ml_on_port, mac_learn_state=True)268 self._delete_port(ml_on_port)269 self.assertIsNone(self.nsx.get_logical_port(ml_on_port['name']),270 "Port %s is not None" % ml_on_port['name'])271 @test.attr(type='nsxv3')272 @decorators.idempotent_id('262e844f-a033-4fcd-b5d0-4641d9efeccd')273 def test_create_update_delete_mac_learning_port(self):274 """275 CRUD Workflow 3276 Create port with MAC Learning enabled277 Update port(non-MAC Learning settings)278 Delete port279 """280 test_port = self._create_mac_learn_enabled_port(self.network)281 new_port_name = data_utils.rand_name('updated_port-')282 updated_port = self.update_port(test_port,283 name=new_port_name)284 updated_nsx_port = self.nsx.get_logical_port(updated_port['name'])285 self.assertEqual(updated_nsx_port['display_name'],286 updated_port['name'],287 "Updated port names do not match OS and NSX")288 self._delete_port(updated_port)289 self.assertIsNone(self.nsx.get_logical_port(updated_port['name']),290 "Logical port %s is not None" % updated_port['name'])291 @test.attr(type='nsxv3')292 @test.attr(type='negative')293 @decorators.idempotent_id('e3465ea8-50fc-4070-88de-f4bd5df8ab86')294 def test_create_mac_learning_port_enable_port_security_negative(self):295 """296 Negative test297 Create port with MAC Learning enabled298 Update port - enable port security(should fail)299 """300 test_port = self._create_mac_learn_enabled_port(self.network)301 self.addCleanup(test_utils.call_and_ignore_notfound_exc,302 self._delete_port, test_port)...

Full Screen

Full Screen

test_ports.py

Source:test_ports.py Github

copy

Full Screen

...33 def resource_setup(cls):34 super(PortsTestJSON, cls).resource_setup()35 cls.network = cls.create_network()36 cls.port = cls.create_port(cls.network)37 def _delete_port(self, port_id):38 self.client.delete_port(port_id)39 body = self.client.list_ports()40 ports_list = body['ports']41 self.assertFalse(port_id in [n['id'] for n in ports_list])42 @test.attr(type='smoke')43 def test_create_update_delete_port(self):44 # Verify port creation45 body = self.client.create_port(network_id=self.network['id'])46 port = body['port']47 # Schedule port deletion with verification upon test completion48 self.addCleanup(self._delete_port, port['id'])49 self.assertTrue(port['admin_state_up'])50 # Verify port update51 new_name = "New_Port"52 body = self.client.update_port(port['id'],53 name=new_name,54 admin_state_up=False)55 updated_port = body['port']56 self.assertEqual(updated_port['name'], new_name)57 self.assertFalse(updated_port['admin_state_up'])...

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