How to use list_subnets method in tempest

Best Python code snippet using tempest_python

test_neutron_network_service.py

Source:test_neutron_network_service.py Github

copy

Full Screen

1from cloudshell.cp.openstack.domain.services.neutron.neutron_network_service import NeutronNetworkService2import cloudshell.cp.openstack.domain.services.neutron.neutron_network_service as test_neutron_network_service3from unittest import TestCase4from mock import Mock5class TestNeutronNetworkService(TestCase):6 def setUp(self):7 self.network_service = NeutronNetworkService()8 self.mock_logger = Mock()9 self.openstack_session = Mock()10 self.moc_cp_model = Mock()11 def test_create_or_get_network_with_segmentation_id_no_conflict(self):12 """13 Tests a successful operation of network creation with no NetCreateConflict error14 :return:15 """16 test_segmentation_id = '42'17 mock_client = Mock()18 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)19 mock_client.create_network = Mock(return_value={'network':'test_network'})20 result = self.network_service.create_or_get_network_with_segmentation_id(openstack_session=self.openstack_session,21 segmentation_id=test_segmentation_id,22 cp_resource_model=self.moc_cp_model,23 logger=self.mock_logger)24 self.assertEqual(result, 'test_network')25 def test_create_or_get_network_with_segmentation_id_conflict(self):26 test_segmentation_id = '42'27 mock_client = Mock()28 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)29 mock_client.create_network = Mock(side_effect=test_neutron_network_service.NetCreateConflict)30 mock_client.list_networks = Mock(return_value={'networks': ['test_network']})31 result = self.network_service.create_or_get_network_with_segmentation_id(openstack_session=self.openstack_session,32 segmentation_id=test_segmentation_id,33 cp_resource_model=self.moc_cp_model,34 logger=self.mock_logger)35 self.assertEqual(result, 'test_network')36 def test_get_network_with_segmentation_id_valid_network(self):37 test_segmentation_id = '42'38 mock_client = Mock()39 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)40 mock_client.list_networks = Mock(return_value={'networks': ['test_network']})41 result = self.network_service.get_network_with_segmentation_id(openstack_session=self.openstack_session,42 segmentation_id=test_segmentation_id,43 logger=self.mock_logger)44 self.assertEqual(result, 'test_network')45 def test_get_network_with_segmentation_id_no_network(self):46 test_segmentation_id = '42'47 mock_client = Mock()48 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)49 mock_client.list_networks = Mock(return_value={'networks': []})50 result = self.network_service.get_network_with_segmentation_id(openstack_session=self.openstack_session,51 segmentation_id=test_segmentation_id,52 logger=self.mock_logger)53 self.assertEqual(result, None)54 def test_valid_cidr_returned(self):55 mock_client = Mock()56 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)57 mock_client.create_subnet = Mock(return_value={'subnet': 'subnet success'})58 mock_return_subnets = {'subnets': [{'cidr': '10.0.0.0/24', 'id': 'test-id-1'},59 {'cidr': '10.0.1.0/24', 'id': 'test-id-2'}]}60 test_reserved_subnets = '172.0.0.0/8, 192.168.0.0/24'61 mock_client.list_subnets = Mock(return_value=mock_return_subnets)62 result = self.network_service._get_unused_cidr(client=mock_client,63 cp_resvd_cidrs=test_reserved_subnets,64 logger=self.mock_logger)65 self.assertEqual(result, '10.0.2.0/24')66 def test_none_cidr_returned(self):67 mock_client = Mock()68 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)69 mock_client.create_subnet = Mock(return_value={'subnet': 'subnet success'})70 mock_return_subnets = {'subnets': [{'cidr': '10.0.0.0/24', 'id': 'test-id-1'},71 {'cidr': '10.0.1.0/24', 'id': 'test-id-2'}]}72 test_reserved_subnets = '10.0.0.0/8, 172.16.0.0/12 , 192.168.0.0/16'73 mock_client.list_subnets = Mock(return_value=mock_return_subnets)74 result = self.network_service._get_unused_cidr(client=mock_client,75 cp_resvd_cidrs=test_reserved_subnets,76 logger=self.mock_logger)77 self.assertEqual(result, None)78 def test_empty_reserved_networks(self):79 mock_client = Mock()80 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)81 mock_client.create_subnet = Mock(return_value={'subnet': 'subnet success'})82 mock_return_subnets = {'subnets': [{'cidr': '10.0.0.0/24', 'id': 'test-id-1'},83 {'cidr': '10.0.1.0/24', 'id': 'test-id-2'}]}84 test_reserved_subnets = ''85 mock_client.list_subnets = Mock(return_value=mock_return_subnets)86 result = self.network_service._get_unused_cidr(client=mock_client,87 cp_resvd_cidrs=test_reserved_subnets,88 logger=self.mock_logger)89 self.assertEqual(result, '10.0.2.0/24')90 def test_reserved_networks_one_empty_entry(self):91 mock_client = Mock()92 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)93 mock_client.create_subnet = Mock(return_value={'subnet': 'subnet success'})94 mock_return_subnets = {'subnets': [{'cidr': '10.0.0.0/24', 'id': 'test-id-1'},95 {'cidr': '10.0.1.0/24', 'id': 'test-id-2'}]}96 test_reserved_subnets = '172.16.0.0/12,,192.168.0.0/16'97 mock_client.list_subnets = Mock(return_value=mock_return_subnets)98 result = self.network_service._get_unused_cidr(client=mock_client,99 cp_resvd_cidrs=test_reserved_subnets,100 logger=self.mock_logger)101 self.assertEqual(result, '10.0.2.0/24')102 def test_create_and_attach_subnet_to_net_success(self):103 test_net_id = 'test-net-id'104 mock_client = Mock()105 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)106 mock_client.create_subnet = Mock(return_value={'subnet':'subnet success'})107 mock_return_subnets = {'subnets':[{'cidr': '192.168.1.0/24', 'id':'test-id-1'},108 {'cidr': '192.168.1.0/24', 'id': 'test-id-2'}]}109 test_reserved_subnets = '10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/24'110 mock_client.list_subnets = Mock(return_value=mock_return_subnets)111 cp_resource_model = Mock()112 cp_resource_model.reserved_networks = test_reserved_subnets113 # self.network_service._get_unused_cidr = Mock(return_value = '10.0.0.0/24')114 result = self.network_service.create_and_attach_subnet_to_net(openstack_session=self.openstack_session,115 cp_resource_model=cp_resource_model,116 net_id=test_net_id,117 logger=self.mock_logger)118 self.assertEqual(result, 'subnet success')119 def test_create_and_attach_subnet_to_net_return_none(self):120 test_net_id = 'test-net-id'121 mock_client = Mock()122 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)123 mock_client.create_subnet = Mock(side_effect=Exception)124 self.network_service._get_unused_cidr = Mock(return_value = '10.0.0.0/24')125 with self.assertRaises(Exception) as context:126 result = self.network_service.create_and_attach_subnet_to_net(openstack_session=self.openstack_session,127 cp_resource_model=Mock(),128 net_id=test_net_id,129 logger=self.mock_logger)130 self.assertTrue(context)131 def test_create_floating_ip_success(self):132 mock_client = Mock()133 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)134 test_network_id = 'test_network_id'135 test_subnet_id = 'test_subnet_id'136 test_result_subnet_dict = {'subnets': [{'network_id':test_network_id}]}137 mock_client.list_subnets = Mock(return_value=test_result_subnet_dict)138 test_floating_ip = '1.2.3.4'139 test_floating_ip_dict = {'floatingip':test_floating_ip}140 mock_client.create_floatingip = Mock(return_value=test_floating_ip_dict)141 result = self.network_service.create_floating_ip(openstack_session=self.openstack_session,142 floating_ip_subnet_id=test_subnet_id,143 logger=self.mock_logger)144 floating_ip_call_dict = {'floatingip': {'floating_network_id':test_network_id, 'subnet_id':test_subnet_id}}145 mock_client.create_floatingip.assert_called_with(floating_ip_call_dict)146 self.assertEqual(result, test_floating_ip)147 def test_create_floating_ip_returns_None(self):148 mock_client = Mock()149 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)150 test_network_id = 'test_network_id'151 test_subnet_id = 'test_subnet_id'152 test_result_subnet_dict = {'subnets': [{'network_id':test_network_id}]}153 mock_client.list_subnets = Mock(return_value=test_result_subnet_dict)154 mock_client.create_floatingip = Mock(return_value={})155 result = self.network_service.create_floating_ip(openstack_session=self.openstack_session,156 floating_ip_subnet_id=test_subnet_id,157 logger=self.mock_logger)158 floating_ip_call_dict = {'floatingip': {'floating_network_id':test_network_id, 'subnet_id':test_subnet_id}}159 mock_client.create_floatingip.assert_called_with(floating_ip_call_dict)160 self.assertEqual(result, None)161 def test_delete_floating_ip_success(self):162 mock_client = Mock()163 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)164 test_floating_ip = '1.2.3.4'165 test_floating_ip_id = 'test_floating_id'166 mock_list_result_dict = {'floatingips': [{'id': test_floating_ip_id}]}167 mock_client.list_floatingips = Mock(return_value=mock_list_result_dict)168 mock_client.delete_floatingip = Mock()169 result = self.network_service.delete_floating_ip(openstack_session=self.openstack_session,170 floating_ip=test_floating_ip,171 logger=self.mock_logger)172 mock_client.delete_floatingip.assert_called_with(test_floating_ip_id)173 self.assertTrue(result)174 def test_delete_floating_ip_false(self):175 mock_client = Mock()176 test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client)177 test_floating_ip = ''178 mock_client.delete_floatingip = Mock()179 result = self.network_service.delete_floating_ip(openstack_session=self.openstack_session,180 floating_ip=test_floating_ip,181 logger=self.mock_logger)182 mock_client.delete_floatingip.assert_not_called()...

Full Screen

Full Screen

listSubnets.py

Source:listSubnets.py Github

copy

Full Screen

...6username="admin",7password="manoj",8user_domain_id="default",9project_domain_id="default")10def list_subnets(conn):11 for subnet in conn.network.subnets():12 print(subnet)...

Full Screen

Full Screen

aws_filters.py

Source:aws_filters.py Github

copy

Full Screen

1def subnet_name_filter(list, res_tag_name):2 list_subnets=[]3 #for filt_def in res_tag_name:4 # list_subnets.append(subnet['id'] for subnet in list if subnet['resource_tags']['Name'] == filt_def)5 #print (subnet)6 return [ x['id'] for x in list if x['resource_tags']['Name'] in res_tag_name ]7 #return list_subnets8class FilterModule(object):9 def filters(self):10 return { 11 'subnet_name_filter': subnet_name_filter...

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