From f37bcc779347c9e0d1e37258a6d072b718edf7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 18 Aug 2020 15:30:04 +0200 Subject: [PATCH] Add a new type HostDomain. HostDomain is like HostAddress with the support of _ character - RFC1033 openstack services are failing to start when a hostname with underscore _ is provided. Example: ``` overcloud-novacompute_edge1-0.internalapi.localdomain overcloud-novacompute_edge1-0.internalapi ``` Nova use `HostAddressOpt` to define `live_migration_inbound_addr`, and if a hostname with underscore is present in the config file then the service fail to start. Example: ``` /etc/nova/nova.conf live_migration_inbound_addr = overcloud-novacompute_edge1-0.internalapi.localdomain ``` FQDN is a domain name that specifies its exact location in the tree hierarchy of the Domain Name System (DNS). Underscore are allowed by RFC1033 [1][2][3]. Indeed, while a hostname may not contain other characters, such as the underscore character (_), other DNS names may contain the underscore.[1][2]. Systems such as DomainKeys and service records use the underscore. These changes allow us to use underscore with the `HostDomain`. [1] https://www.ietf.org/rfc/rfc1912.txt [2] https://www.ietf.org/rfc/rfc1033.txt [3] http://domainkeys.sourceforge.net/underscore.html Co-authored-by: Daniel Bengtsson Change-Id: I0a0670207f96a987996d329e5efa9a5eb2ce000c Closes-Bug: #1892044 (cherry picked from commit 6480356928c9ae6169ea1e5a5b5f1df3d6e0dc75) --- oslo_config/tests/test_types.py | 24 +++++++++- oslo_config/types.py | 47 +++++++++++++++++-- ...in-implement-rfc1033-c985a3054f824e9d.yaml | 9 ++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-HostDomain-implement-rfc1033-c985a3054f824e9d.yaml diff --git a/oslo_config/tests/test_types.py b/oslo_config/tests/test_types.py index 644a2393..8ab4a098 100644 --- a/oslo_config/tests/test_types.py +++ b/oslo_config/tests/test_types.py @@ -766,6 +766,27 @@ class HostAddressTypeTests(TypeTestHelper, unittest.TestCase): self.assertConvertedValue('abc.0-0', 'abc.0-0') +class HostDomainTypeTests(TypeTestHelper, unittest.TestCase): + type = types.HostDomain() + + def test_invalid_host_addresses(self): + self.assertInvalid('-1') + self.assertInvalid('3.14') + self.assertInvalid('10.0') + self.assertInvalid('host..name') + self.assertInvalid('org.10') + self.assertInvalid('0.0.00') + + def test_valid_host_addresses(self): + self.assertConvertedValue('_foo', '_foo') + self.assertConvertedValue('host_name', 'host_name') + self.assertConvertedValue( + 'overcloud-novacompute_edge1-0.internalapi.localdomain', + 'overcloud-novacompute_edge1-0.internalapi.localdomain') + self.assertConvertedValue('host_01.co.uk', 'host_01.co.uk') + self.assertConvertedValue('_site01001', '_site01001') + + class HostnameTypeTests(TypeTestHelper, unittest.TestCase): type = types.Hostname() @@ -796,8 +817,8 @@ class HostnameTypeTests(TypeTestHelper, unittest.TestCase): self.assertInvalid("h'ost'") self.assertInvalid("h'ost") self.assertInvalid("h$ost") - self.assertInvalid("h%ost") self.assertInvalid("host_01.co.uk") + self.assertInvalid("h%ost") self.assertInvalid("host;name=99") self.assertInvalid('___site0.1001') self.assertInvalid('_site01001') @@ -808,6 +829,7 @@ class HostnameTypeTests(TypeTestHelper, unittest.TestCase): def test_invalid_hostnames_with_numeric_characters(self): self.assertInvalid("10.0.0.0") self.assertInvalid("3.14") + self.assertInvalid('___site0.1001') self.assertInvalid("org.10") self.assertInvalid('0.0.00') diff --git a/oslo_config/types.py b/oslo_config/types.py index dfd89bce..a1f75c9b 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -761,11 +761,12 @@ class Hostname(ConfigType): :param type_name: Type name to be used in the sample config file. """ + HOSTNAME_REGEX = '(?!-)[A-Z0-9-]{1,63}(?