blob: 3b075d5df4616a909b78f48bfcaf4086829d48ea [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):
Hongbin Lu54f55922018-07-12 19:05:39 +000070 self._test_list_validation_filters(self.list_kwargs)
71 self._test_list_validation_filters({
72 'unknown_filter': 'value'}, filter_is_valid=False)
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +020073
74
75class SubnetServiceTypeTestJSON(base.BaseNetworkTest):
76
Slawek Kaplonskia5cdede2021-06-23 09:37:04 +020077 required_extensions = ['subnet-service-types']
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +020078
79 @classmethod
80 def resource_setup(cls):
81 super(SubnetServiceTypeTestJSON, cls).resource_setup()
82 cls.network = cls.create_network()
83
84 @decorators.idempotent_id('7e0edb66-1bb2-4473-ab83-d039cddced0d')
85 def test_allocate_ips_are_from_correct_subnet(self):
86 cidr_1 = netaddr.IPNetwork('192.168.1.0/24')
87 cidr_2 = netaddr.IPNetwork('192.168.2.0/24')
88
Slawek Kaplonski9115c8e2021-07-06 13:50:17 +020089 # NOTE(slaweq): service_type "network:distributed" is needed for
90 # ML2/OVN backend. It's needed because OVN driver creates additional
91 # port for metadata service in each subnet with enabled dhcp and such
92 # port needs to have allocated IP address from the subnet also.
93 self.create_subnet(
94 self.network,
95 service_types=['test:type_1', 'network:distributed'],
96 cidr=str(cidr_1))
97 self.create_subnet(
98 self.network,
99 service_types=['test:type_2', 'network:distributed'],
100 cidr=str(cidr_2))
Slawek Kaplonski2e68c7a2021-04-23 14:00:35 +0200101 port_type_1 = self.create_port(self.network,
102 device_owner="test:type_1")
103 port_type_2 = self.create_port(self.network,
104 device_owner="test:type_2")
105
106 self.assertEqual(1, len(port_type_1['fixed_ips']))
107 self.assertEqual(1, len(port_type_2['fixed_ips']))
108 self.assertIn(
109 netaddr.IPAddress(port_type_1['fixed_ips'][0]['ip_address']),
110 cidr_1)
111 self.assertIn(
112 netaddr.IPAddress(port_type_2['fixed_ips'][0]['ip_address']),
113 cidr_2)