How to use test_list_ports method in tempest

Best Python code snippet using tempest_python

test_port_types.py

Source:test_port_types.py Github

copy

Full Screen

1# Copyright 2017 VMware Inc2# All Rights Reserved3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15import base_provider as base16from tempest import config17from tempest.lib.common.utils import data_utils18from tempest.lib.common.utils import test_utils19from tempest.lib import decorators20from tempest.lib import exceptions as ex21from oslo_log import log as logging22CONF = config.CONF23LOG = logging.getLogger(__name__)24class PortTypeTest(base.BaseAdminNetworkTest):25 """NSX-V OpenStack port types test26 Positive27 - Create direct port28 - Enable port direct vnic-type29 - Delete direct port30 - List ports with direct port31 - Create, update, delete direct port32 Negative33 - Create direct port without flat network with port configs34 - Create direct port with flat network without port configs35 - Update direct port with flat network without port configs36 - Update direct port without flat network with port configs37 """38 @classmethod39 def setup_clients(cls):40 super(PortTypeTest, cls).setup_clients()41 @classmethod42 def resource_setup(cls):43 super(PortTypeTest, cls).resource_setup()44 def _create_flat_network(self, _auto_clean_up=True, network_name=None,45 **kwargs):46 network_name = network_name or data_utils.rand_name('flat-net')47 post_body = {'name': network_name,48 'provider:network_type': 'flat'}49 post_body.update(kwargs)50 LOG.debug("create FLAT network: %s", str(post_body))51 body = self.admin_networks_client.create_network(**post_body)52 network = body['network']53 self.networks.append(network)54 if _auto_clean_up:55 self.addCleanup(test_utils.call_and_ignore_notfound_exc,56 self.delete_network, network['id'])57 return network58 def _create_direct_port(self, network_id, _auto_clean_up=True,59 port_name=None, **kwargs):60 dir_port_name = port_name or data_utils.rand_name('direct-port')61 post_body = {'name': dir_port_name,62 'port_security_enabled': 'False',63 'security_groups': [],64 'binding:vnic_type': 'direct'}65 post_body.update(kwargs)66 LOG.debug("create DIRECT port: %s", str(post_body))67 body = self.create_port(network_id=network_id, **post_body)68 dir_port = body['port']69 if _auto_clean_up:70 self.addCleanup(test_utils.call_and_ignore_notfound_exc,71 self.delete_port, dir_port['id'])72 return dir_port73 @decorators.attr(type='nsxv')74 @decorators.idempotent_id('ebb15f36-79bd-4461-91b5-84a57616730c')75 def test_create_direct_port(self):76 """77 Test create a direct openstack port. After creation, check78 OpenStack for the port vnic-type.79 """80 test_flat_net = self._create_flat_network()81 dir_port = self._create_direct_port(network_id=test_flat_net['id'])82 self.assertEqual(dir_port['binding:vnic_type'], 'direct',83 "Created port type is not DIRECT")84 @decorators.attr(type='nsxv')85 @decorators.idempotent_id('2eaa0014-3265-479c-9012-c110df566ef1')86 def test_enable_port_direct(self):87 """88 Test updating a port to be a direct openstack port.89 After updating, check nsx_v backend for the port type.90 """91 test_flat_net = self._create_flat_network()92 test_port_name = data_utils.rand_name('test-port-')93 orig_post = {'name': test_port_name,94 'port_security_enabled': 'False',95 'security_groups': []}96 LOG.debug("create NORMAL port: %s", str(orig_post))97 test_port = self.create_port(network_id=test_flat_net['id'],98 **orig_post)99 self.addCleanup(test_utils.call_and_ignore_notfound_exc,100 self.delete_port, test_port['port']['id'])101 post_body = {'binding:vnic_type': 'direct'}102 LOG.debug("update port to be DIRECT: %s", str(orig_post))103 self.assertEqual(test_port['port']['binding:vnic_type'], 'normal',104 "Port vnic-type is not NORMAL")105 updated_port = self.update_port(test_port['port']['id'], **post_body)106 self.assertEqual(updated_port['port']['binding:vnic_type'], 'direct',107 "Port vnic-type was not updated to DIRECT")108 @decorators.attr(type='nsxv')109 @decorators.idempotent_id('d77125af-7e8f-4dcf-a3a4-7956b3eaa2d2')110 def test_delete_direct_port(self):111 """112 Test create, then delete a direct openstack port.113 Verify port type and port delete.114 """115 test_flat_net = self._create_flat_network()116 dir_port = self._create_direct_port(network_id=test_flat_net['id'])117 self.assertEqual(dir_port['binding:vnic_type'], 'direct',118 "Port type is not DIRECT")119 self.assertFalse(self.delete_port(dir_port['id']),120 "Delete of Direct port was not successful")121 @decorators.attr(type='nsxv')122 @decorators.idempotent_id('b69f5ff1-7e86-4790-9392-434cd9ab808f')123 def test_list_direct_ports(self):124 """125 Create one each of a normal and direct port.126 Verify that both ports are included in port-list output.127 """128 test_list_ports = []129 test_flat_net = self._create_flat_network()130 dir_port = self._create_direct_port(network_id=test_flat_net['id'])131 test_list_ports.append(dir_port)132 vanilla_port_name = data_utils.rand_name('vanilla-port-')133 vanilla_post = {'name': vanilla_port_name}134 body = self.create_port(network_id=test_flat_net['id'],135 **vanilla_post)136 test_port = body['port']137 test_list_ports.append(test_port)138 self.addCleanup(test_utils.call_and_ignore_notfound_exc,139 self.delete_port, test_port['id'])140 body = self.admin_ports_client.list_ports(141 network_id=test_flat_net['id'])142 ports_list = body['ports']143 pids_list = [p['id'] for p in ports_list]144 ports_not_listed = []145 for port in test_list_ports:146 if port['id'] not in pids_list:147 ports_not_listed.append(port['id'])148 self.assertEmpty(ports_not_listed, "These ports not listed: %s"149 % ports_not_listed)150 @decorators.attr(type='nsxv')151 @decorators.idempotent_id('9b7ec966-f4e4-4087-9789-96a3aa669fa2')152 def test_create_update_delete_direct_port(self):153 """154 Create, update, delete direct port. Verify port type and update155 operation.156 """157 test_flat_net = self._create_flat_network()158 dir_port = self._create_direct_port(network_id=test_flat_net['id'])159 self.assertEqual(dir_port['binding:vnic_type'], 'direct',160 "Port VNIC_TYPE should be set to DIRECT")161 updated_port_name = data_utils.rand_name('update-port-')162 updated_post = {'name': updated_port_name}163 updated_port = self.update_port(dir_port['id'], **updated_post)['port']164 self.assertEqual(updated_port['binding:vnic_type'], 'direct',165 "VNIC_TYPE is not correct type, should be DIRECT")166 self.assertEqual(updated_port['name'], updated_port_name,167 "Port name should be updated to %s"168 % updated_port_name)169 @decorators.attr(type='nsxv')170 @decorators.attr(type='negative')171 @decorators.idempotent_id('e661ba70-0ab4-4f91-8d84-c5c102ec5793')172 def test_create_direct_port_without_flat_network_negative(self):173 """174 Create a network. Create a direct openstack port.175 Creation should fail on a bad request since flat net prereq is not met176 """177 net_name = data_utils.rand_name('test-net')178 net_body = self.create_network(name=net_name)179 test_net = net_body['network']180 self.addCleanup(test_utils.call_and_ignore_notfound_exc,181 self.delete_network, test_net['id'])182 self.assertRaises(ex.BadRequest, self._create_direct_port,183 network_id=test_net['id'])184 @decorators.attr(type='nsxv')185 @decorators.attr(type='negative')186 @decorators.idempotent_id('ee87287f-4ec6-4502-9bc1-855fa7c93e90')187 def test_create_direct_port_w_flat_net_wout_port_settings_negative(self):188 """189 Create a flat network. Create a direct openstack port without required190 port settings.191 """192 test_flat_net = self._create_flat_network()193 test_port_name = data_utils.rand_name('test-port-')194 orig_post = {'name': test_port_name, 'binding:vnic_type': 'direct'}195 LOG.debug("create DIRECT port: %s", str(orig_post))196 self.assertRaises(ex.BadRequest,197 self.create_port, network_id=test_flat_net['id'],198 **orig_post)199 @decorators.attr(type='nsxv')200 @decorators.attr(type='negative')201 @decorators.idempotent_id('03e0065e-6d76-45d5-9192-ce89853dfa9e')202 def test_update_direct_port_w_flat_net_wout_port_configs_negative(self):203 """204 Create a flat network. Create an openstack port with vnic-type normal.205 Update port to set vnic-type to direct, without required port settings.206 Update should fail on a bad request since prereq is not met.207 """208 test_flat_net = self._create_flat_network()209 test_port_name = data_utils.rand_name('test-port-')210 orig_post = {'name': test_port_name}211 LOG.debug("create NORMAL port: %s", str(orig_post))212 test_port = self.create_port(network_id=test_flat_net['id'],213 **orig_post)214 self.addCleanup(test_utils.call_and_ignore_notfound_exc,215 self.delete_port, test_port['port']['id'])216 post_body = {'binding:vnic_type': 'direct'}217 LOG.debug("update port to be DIRECT: %s", str(orig_post))218 self.assertEqual(test_port['port']['binding:vnic_type'], 'normal',219 "Orig port should be vnic-type NORMAL")220 self.assertRaises(ex.BadRequest, self.update_port,221 test_port['port']['id'], **post_body)222 @decorators.attr(type='nsxv')223 @decorators.attr(type='negative')224 @decorators.idempotent_id('d3e75ed7-f3e5-4395-9ab0-063e7a8c141c')225 def test_update_direct_port_wout_flat_net_with_port_configs_negative(self):226 """227 Create a network. Create a normal openstack port. Update port to direct228 vnic-type. Update should fail since flat net prereq is not met229 """230 net_name = data_utils.rand_name('test-net')231 net_body = self.create_network(name=net_name)232 test_net = net_body['network']233 self.addCleanup(test_utils.call_and_ignore_notfound_exc,234 self.delete_network, test_net['id'])235 test_port_name = data_utils.rand_name('test-port-')236 orig_post = {'name': test_port_name}237 LOG.debug("create NORMAL port: %s", str(orig_post))238 test_port = self.create_port(network_id=test_net['id'],239 **orig_post)240 self.addCleanup(test_utils.call_and_ignore_notfound_exc,241 self.delete_port, test_port['port']['id'])242 post_body = {'port_security_enabled': 'False',243 'security_groups': [],244 'binding:vnic_type': 'direct'}245 self.assertRaises(ex.BadRequest, self.update_port,...

Full Screen

Full Screen

test_build.py

Source:test_build.py Github

copy

Full Screen

...21 return artifact_path22def test_help(artifact_path):23 result = subprocess.run([artifact_path, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)24 result.check_returncode()25def test_list_ports(artifact_path):26 result = subprocess.run([artifact_path, '--list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)27 result.check_returncode()28if __name__ == '__main__':29 # check minimal python version30 assert sys.version_info >= (3, 6)...

Full Screen

Full Screen

test_listports.py

Source:test_listports.py Github

copy

Full Screen

1""" Lets see what com ports pyserial reports on our test runners"""2from serial.tools import list_ports #pylint: disable=import-error3from ndicapy import ndiDeviceName4def test_list_ports():5 """6 Check that ndicapy.ndiDeviceName gets all the comports found7 by pyserial8 """9 #list ports10 print([comport.device for comport in list_ports.comports()])11 serial_ports = list_ports.comports()12 ndi_port_names = []13 max_com_port = 014 for port_number, serial_port in enumerate(serial_ports):15 ndi_port_names.append(ndiDeviceName(port_number))16 try:17 windows_port_number = int(serial_port.device.replace('COM', ''))18 if windows_port_number > max_com_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