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}(?