|
| 1 | +# Copyright 2023 Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +from neutron_lib import constants |
| 16 | + |
| 17 | +from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as ovn_config |
| 18 | +from neutron.tests.functional import base |
| 19 | + |
| 20 | + |
| 21 | +class TestOVNClient(base.TestOVNFunctionalBase): |
| 22 | + |
| 23 | + def test_create_metadata_port(self): |
| 24 | + def check_metadata_port(enable_dhcp): |
| 25 | + ports = self.plugin.get_ports( |
| 26 | + self.context, filters={'network_id': [network['id']]}) |
| 27 | + self.assertEqual(1, len(ports)) |
| 28 | + if enable_dhcp: |
| 29 | + self.assertEqual(1, len(ports[0]['fixed_ips'])) |
| 30 | + else: |
| 31 | + self.assertEqual(0, len(ports[0]['fixed_ips'])) |
| 32 | + return ports |
| 33 | + |
| 34 | + ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True, |
| 35 | + group='ovn') |
| 36 | + ovn_client = self.mech_driver._ovn_client |
| 37 | + for enable_dhcp in (True, False): |
| 38 | + network_args = {'tenant_id': 'project_1', |
| 39 | + 'name': 'test_net_1', |
| 40 | + 'admin_state_up': True, |
| 41 | + 'shared': False, |
| 42 | + 'status': constants.NET_STATUS_ACTIVE} |
| 43 | + network = self.plugin.create_network(self.context, |
| 44 | + {'network': network_args}) |
| 45 | + subnet_args = {'tenant_id': 'project_1', |
| 46 | + 'name': 'test_snet_1', |
| 47 | + 'network_id': network['id'], |
| 48 | + 'ip_version': constants.IP_VERSION_4, |
| 49 | + 'cidr': '10.210.10.0/28', |
| 50 | + 'enable_dhcp': enable_dhcp, |
| 51 | + 'gateway_ip': constants.ATTR_NOT_SPECIFIED, |
| 52 | + 'allocation_pools': constants.ATTR_NOT_SPECIFIED, |
| 53 | + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, |
| 54 | + 'host_routes': constants.ATTR_NOT_SPECIFIED} |
| 55 | + self.plugin.create_subnet(self.context, {'subnet': subnet_args}) |
| 56 | + |
| 57 | + # The metadata port has been created during the network creation. |
| 58 | + ports = check_metadata_port(enable_dhcp) |
| 59 | + |
| 60 | + # Force the deletion and creation the metadata port. |
| 61 | + self.plugin.delete_port(self.context, ports[0]['id']) |
| 62 | + ovn_client.create_metadata_port(self.context, network) |
| 63 | + check_metadata_port(enable_dhcp) |
| 64 | + |
| 65 | + # Call again the "create_metadata_port" method as is idempotent |
| 66 | + # because it checks first if the metadata port exists. |
| 67 | + ovn_client.create_metadata_port(self.context, network) |
| 68 | + check_metadata_port(enable_dhcp) |
0 commit comments