Merge "Adding the missing HostDomain config option"
This commit is contained in:
commit
6e91dbb2d5
|
@ -1175,6 +1175,28 @@ class HostAddressOpt(Opt):
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class HostDomainOpt(Opt):
|
||||||
|
|
||||||
|
r"""Option for either an IP or a hostname.
|
||||||
|
|
||||||
|
Like HostAddress with the support of _ character.
|
||||||
|
|
||||||
|
Option with ``type`` :class:`oslo_config.types.HostDomain`
|
||||||
|
|
||||||
|
:param name: the option's name
|
||||||
|
:param version: one of either ``4``, ``6``, or ``None`` to specify
|
||||||
|
either version.
|
||||||
|
:param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`
|
||||||
|
|
||||||
|
.. versionadded:: 8.6
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, name, version=None, **kwargs):
|
||||||
|
super(HostDomainOpt, self).__init__(name,
|
||||||
|
type=types.HostDomain(version),
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class URIOpt(Opt):
|
class URIOpt(Opt):
|
||||||
|
|
||||||
r"""Opt with URI type
|
r"""Opt with URI type
|
||||||
|
|
|
@ -1872,5 +1872,32 @@ class HostAddressTestCase(base.BaseTestCase):
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
|
||||||
|
class HostDomainTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
|
opts = [cfg.HostDomainOpt('foo', help='foo option', default='0.0.0.0')]
|
||||||
|
|
||||||
|
def test_host_domain(self):
|
||||||
|
|
||||||
|
config = [("namespace", [("alpha", self.opts)])]
|
||||||
|
groups = generator._get_groups(config)
|
||||||
|
|
||||||
|
out = io.StringIO()
|
||||||
|
formatter = build_formatter(out)
|
||||||
|
generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
|
||||||
|
result = out.getvalue()
|
||||||
|
|
||||||
|
expected = textwrap.dedent('''
|
||||||
|
[alpha]
|
||||||
|
|
||||||
|
#
|
||||||
|
# From namespace
|
||||||
|
#
|
||||||
|
|
||||||
|
# foo option (host domain value)
|
||||||
|
#foo = 0.0.0.0
|
||||||
|
''').lstrip()
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
|
||||||
GeneratorTestCase.generate_scenarios()
|
GeneratorTestCase.generate_scenarios()
|
||||||
MachineReadableGeneratorTestCase.generate_scenarios()
|
MachineReadableGeneratorTestCase.generate_scenarios()
|
||||||
|
|
|
@ -871,6 +871,13 @@ class HostDomain(HostAddress):
|
||||||
# DOMAIN_REGEX is HOSTNAME_REGEX with the _ character added
|
# DOMAIN_REGEX is HOSTNAME_REGEX with the _ character added
|
||||||
DOMAIN_REGEX = '(?!-)[A-Z0-9-_]{1,63}(?<!-)$'
|
DOMAIN_REGEX = '(?!-)[A-Z0-9-_]{1,63}(?<!-)$'
|
||||||
|
|
||||||
|
def __init__(self, version=None, type_name='host domain value'):
|
||||||
|
"""Check for valid version in case an IP address is provided
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
super(HostDomain, self).__init__(type_name=type_name)
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
"""Checks if is a valid IP/hostname.
|
"""Checks if is a valid IP/hostname.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Adding the missing ``HostDomain`` config option. Previously this available
|
||||||
|
type couldn't been imported because no related config option was defined.
|
Loading…
Reference in New Issue