blob: 126dc70a151f9260649a5d9c8e0edc24ea80366b [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):
Rodolfo Alonso Hernandezf4fb68d2024-08-06 16:36:38 +000027 if 'subnet-external-network' in cls.get_loaded_network_extensions():
28 cls.list_kwargs['router:external'] = False
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020029 super(SubnetsSearchCriteriaTest, cls).resource_setup()
30 net = cls.create_network(network_name='subnet-search-test-net')
31 for name in cls.resource_names:
32 cls.create_subnet(net, name=name)
33
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000034 @decorators.idempotent_id('d2d61995-5dd5-4b93-bce7-3edefdb79563')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020035 def test_list_sorts_asc(self):
36 self._test_list_sorts_asc()
37
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000038 @decorators.idempotent_id('c3c6b0af-c4ac-4da0-b568-8d08ae550604')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020039 def test_list_sorts_desc(self):
40 self._test_list_sorts_desc()
41
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000042 @decorators.idempotent_id('b93063b3-f713-406e-bf93-e5738e09153c')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020043 def test_list_pagination(self):
44 self._test_list_pagination()
45
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000046 @decorators.idempotent_id('2ddd9aa6-de28-410f-9cbc-ce752893c407')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020047 def test_list_pagination_with_marker(self):
48 self._test_list_pagination_with_marker()
49
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000050 @decorators.idempotent_id('351183ef-6ed9-4d71-a9f2-a5ac049bd7ea')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020051 def test_list_pagination_with_href_links(self):
52 self._test_list_pagination_with_href_links()
53
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000054 @decorators.idempotent_id('dfaa20ca-6d84-4f26-962f-2fee4d247cd9')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020055 def test_list_pagination_page_reverse_asc(self):
56 self._test_list_pagination_page_reverse_asc()
57
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000058 @decorators.idempotent_id('40552213-3e12-4d6a-86f3-dda92f3de88c')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020059 def test_list_pagination_page_reverse_desc(self):
60 self._test_list_pagination_page_reverse_desc()
61
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000062 @decorators.idempotent_id('3cea9053-a731-4480-93ee-19b2c28a9ce4')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020063 def test_list_pagination_page_reverse_with_href_links(self):
64 self._test_list_pagination_page_reverse_with_href_links()
65
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000066 @decorators.idempotent_id('d851937c-9821-4b46-9d18-43e9077ecac0')
Ihar Hrachyshka3cf4e7f2016-06-14 11:40:19 +020067 def test_list_no_pagination_limit_0(self):
68 self._test_list_no_pagination_limit_0()
Victor Morales1be97b42016-09-05 08:50:06 -050069
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000070 @decorators.idempotent_id('c0f9280b-9d81-4728-a967-6be22659d4c8')
Victor Morales1be97b42016-09-05 08:50:06 -050071 def test_list_validation_filters(self):
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)