Slawek Kaplonski | 2bc7367 | 2020-10-27 13:06:08 +0100 | [diff] [blame^] | 1 | # All Rights Reserved. |
| 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 | from oslo_log import log |
| 15 | from paramiko import ssh_exception as ssh_exc |
| 16 | from tempest.common import utils |
| 17 | from tempest.lib.common.utils import data_utils |
| 18 | from tempest.lib import decorators |
| 19 | from tempest.lib import exceptions as lib_exc |
| 20 | |
| 21 | from neutron_tempest_plugin.common import ssh |
| 22 | from neutron_tempest_plugin import config |
| 23 | from neutron_tempest_plugin.scenario import base |
| 24 | |
| 25 | CONF = config.CONF |
| 26 | LOG = log.getLogger(__name__) |
| 27 | |
| 28 | |
| 29 | class DHCPTest(base.BaseTempestTestCase): |
| 30 | |
| 31 | credentials = ['primary', 'admin'] |
| 32 | force_tenant_isolation = False |
| 33 | |
| 34 | @classmethod |
| 35 | def resource_setup(cls): |
| 36 | super(DHCPTest, cls).resource_setup() |
| 37 | cls.rand_name = data_utils.rand_name( |
| 38 | cls.__name__.rsplit('.', 1)[-1]) |
| 39 | cls.network = cls.create_network(name=cls.rand_name) |
| 40 | cls.subnet = cls.create_subnet( |
| 41 | network=cls.network, name=cls.rand_name) |
| 42 | cls.router = cls.create_router_by_client() |
| 43 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
| 44 | cls.keypair = cls.create_keypair(name=cls.rand_name) |
| 45 | cls.security_group = cls.create_security_group(name=cls.rand_name) |
| 46 | cls.create_loginable_secgroup_rule(cls.security_group['id']) |
| 47 | |
| 48 | @utils.requires_ext(extension='extra_dhcp_opt', service='network') |
| 49 | @decorators.idempotent_id('58f7c094-1980-4e03-b0d3-6c4dd27217b1') |
| 50 | def test_extra_dhcp_opts(self): |
| 51 | """This test case tests DHCP extra options configured for Neutron port. |
| 52 | |
| 53 | Test is checking just extra option "15" which is domain-name |
| 54 | according to the RFC 2132: |
| 55 | https://tools.ietf.org/html/rfc2132#section-5.3 |
| 56 | |
| 57 | To test that option, there is spawned VM connected to the port with |
| 58 | configured extra_dhcp_opts and test asserts that search domain name is |
| 59 | configured inside VM in /etc/resolv.conf file |
| 60 | """ |
| 61 | |
| 62 | test_domain = "test.domain" |
| 63 | extra_dhcp_opts = [ |
| 64 | {'opt_name': 'domain-name', |
| 65 | 'opt_value': '"%s"' % test_domain}] |
| 66 | port = self.create_port( |
| 67 | network=self.network, name=self.rand_name, |
| 68 | security_groups=[self.security_group['id']], |
| 69 | extra_dhcp_opts=extra_dhcp_opts) |
| 70 | floating_ip = self.create_floatingip(port=port) |
| 71 | |
| 72 | server = self.create_server( |
| 73 | flavor_ref=CONF.compute.flavor_ref, |
| 74 | image_ref=CONF.compute.image_ref, |
| 75 | key_name=self.keypair['name'], |
| 76 | networks=[{'port': port['id']}]) |
| 77 | self.wait_for_server_active(server['server']) |
| 78 | self.wait_for_guest_os_ready(server['server']) |
| 79 | |
| 80 | try: |
| 81 | ssh_client = ssh.Client( |
| 82 | floating_ip['floating_ip_address'], |
| 83 | CONF.validation.image_ssh_user, |
| 84 | pkey=self.keypair['private_key']) |
| 85 | vm_resolv_conf = ssh_client.exec_command( |
| 86 | "cat /etc/resolv.conf") |
| 87 | self.assertIn(test_domain, vm_resolv_conf) |
| 88 | except (lib_exc.SSHTimeout, |
| 89 | ssh_exc.AuthenticationException, |
| 90 | AssertionError) as error: |
| 91 | LOG.debug(error) |
| 92 | self._log_console_output([server]) |
| 93 | self._log_local_network_status() |
| 94 | raise |