blob: 23574eea3877f474abdc2bbd60695df0230918b3 [file] [log] [blame]
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +02001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +020013import netaddr
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000014from tempest.lib import decorators
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020015
Chandan Kumar667d3d32017-09-22 12:24:06 +053016from neutron_tempest_plugin.api import base
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020017
18
19class SubnetsSearchCriteriaTest(base.BaseSearchCriteriaTest):
20
21 resource = 'subnet'
22
23 list_kwargs = {'shared': False}
24
25 @classmethod
26 def resource_setup(cls):
27 super(SubnetsSearchCriteriaTest, cls).resource_setup()
28 net = cls.create_network(network_name='subnet-search-test-net')
29 for name in cls.resource_names:
30 cls.create_subnet(net, name=name)
31
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000032 @decorators.idempotent_id('d2d61995-5dd5-4b93-bce7-3edefdb79563')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020033 def test_list_sorts_asc(self):
34 self._test_list_sorts_asc()
35
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000036 @decorators.idempotent_id('c3c6b0af-c4ac-4da0-b568-8d08ae550604')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020037 def test_list_sorts_desc(self):
38 self._test_list_sorts_desc()
39
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000040 @decorators.idempotent_id('b93063b3-f713-406e-bf93-e5738e09153c')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020041 def test_list_pagination(self):
42 self._test_list_pagination()
43
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000044 @decorators.idempotent_id('2ddd9aa6-de28-410f-9cbc-ce752893c407')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020045 def test_list_pagination_with_marker(self):
46 self._test_list_pagination_with_marker()
47
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000048 @decorators.idempotent_id('351183ef-6ed9-4d71-a9f2-a5ac049bd7ea')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020049 def test_list_pagination_with_href_links(self):
50 self._test_list_pagination_with_href_links()
51
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000052 @decorators.idempotent_id('dfaa20ca-6d84-4f26-962f-2fee4d247cd9')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020053 def test_list_pagination_page_reverse_asc(self):
54 self._test_list_pagination_page_reverse_asc()
55
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000056 @decorators.idempotent_id('40552213-3e12-4d6a-86f3-dda92f3de88c')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020057 def test_list_pagination_page_reverse_desc(self):
58 self._test_list_pagination_page_reverse_desc()
59
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000060 @decorators.idempotent_id('3cea9053-a731-4480-93ee-19b2c28a9ce4')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020061 def test_list_pagination_page_reverse_with_href_links(self):
62 self._test_list_pagination_page_reverse_with_href_links()
63
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000064 @decorators.idempotent_id('d851937c-9821-4b46-9d18-43e9077ecac0')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020065 def test_list_no_pagination_limit_0(self):
66 self._test_list_no_pagination_limit_0()
Victor Morales1be97b42016-09-05 08:50:06 -050067
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000068 @decorators.idempotent_id('c0f9280b-9d81-4728-a967-6be22659d4c8')
Victor Morales1be97b42016-09-05 08:50:06 -050069 def test_list_validation_filters(self):
Rodolfo Alonso Hernandez8f726122024-06-24 18:20:15 +000070 if 'subnet-external-network' in self.get_loaded_network_extensions():
71 self.list_kwargs['router:external'] = False
Hongbin Lu54f55922018-07-12 19:05:39 +000072 self._test_list_validation_filters(self.list_kwargs)
73 self._test_list_validation_filters({
74 'unknown_filter': 'value'}, filter_is_valid=False)
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +020075
76
77class SubnetServiceTypeTestJSON(base.BaseNetworkTest):
78
Slawek Kaplonskia5cdede2021-06-23 09:37:04 +020079 required_extensions = ['subnet-service-types']
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +020080
81 @classmethod
82 def resource_setup(cls):
83 super(SubnetServiceTypeTestJSON, cls).resource_setup()
84 cls.network = cls.create_network()
85
86 @decorators.idempotent_id('7e0edb66-1bb2-4473-ab83-d039cddced0d')
87 def test_allocate_ips_are_from_correct_subnet(self):
88 cidr_1 = netaddr.IPNetwork('192.168.1.0/24')
89 cidr_2 = netaddr.IPNetwork('192.168.2.0/24')
90
Slawek Kaplonski9115c8e2021-07-06 13:50:17 +020091 # NOTE(slaweq): service_type "network:distributed" is needed for
92 # ML2/OVN backend. It's needed because OVN driver creates additional
93 # port for metadata service in each subnet with enabled dhcp and such
94 # port needs to have allocated IP address from the subnet also.
95 self.create_subnet(
96 self.network,
97 service_types=['test:type_1', 'network:distributed'],
98 cidr=str(cidr_1))
99 self.create_subnet(
100 self.network,
101 service_types=['test:type_2', 'network:distributed'],
102 cidr=str(cidr_2))
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +0200103 port_type_1 = self.create_port(self.network,
104 device_owner="test:type_1")
105 port_type_2 = self.create_port(self.network,
106 device_owner="test:type_2")
107
108 self.assertEqual(1, len(port_type_1['fixed_ips']))
109 self.assertEqual(1, len(port_type_2['fixed_ips']))
110 self.assertIn(
111 netaddr.IPAddress(port_type_1['fixed_ips'][0]['ip_address']),
112 cidr_1)
113 self.assertIn(
114 netaddr.IPAddress(port_type_2['fixed_ips'][0]['ip_address']),
115 cidr_2)