From 3e7eecc9f43e4b326018c09d6976489ba5b0d098 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Mon, 7 May 2018 21:45:22 +0000 Subject: [PATCH] Properly initialize HostAddress The HostAddress class wasn't calling super in it's __init__() method, which resulted in the type_name not being set properly for instances of that class. Change-Id: I4e589f2081e5d95227938cba9ad1158548bc1048 Closes-Bug: 1768498 --- oslo_config/tests/test_generator.py | 27 +++++++++++++++++++++++++++ oslo_config/types.py | 1 + 2 files changed, 28 insertions(+) diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index 8575d8e2..88b30fde 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -13,6 +13,7 @@ # under the License. import sys +import textwrap import fixtures import mock @@ -1798,5 +1799,31 @@ class AdvancedOptionsTestCase(base.BaseTestCase): self.assertEqual(expected, actual) +class HostAddressTestCase(base.BaseTestCase): + + opts = [cfg.HostAddressOpt('foo', help='foo option', default='0.0.0.0')] + + def test_host_address(self): + + config = [("namespace", [("alpha", self.opts)])] + groups = generator._get_groups(config) + + out = moves.StringIO() + formatter = generator._OptFormatter(output_file=out) + generator._output_opts(formatter, 'alpha', groups.pop('alpha')) + result = out.getvalue() + + expected = textwrap.dedent(''' + [alpha] + + # + # From namespace + # + + # foo option (host address value) + #foo = 0.0.0.0 + ''').lstrip() + self.assertEqual(expected, result) + GeneratorTestCase.generate_scenarios() MachineReadableGeneratorTestCase.generate_scenarios() diff --git a/oslo_config/types.py b/oslo_config/types.py index a882cc0a..4cfe527c 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -823,6 +823,7 @@ class HostAddress(ConfigType): """ + super(HostAddress, self).__init__(type_name=type_name) self.ip_address = IPAddress(version, type_name) self.hostname = Hostname('localhost')