Add 'ccp config dump' command
This command dumps current config with all default vaules omitted from original config Change-Id: I4fda39903330452780c898be0cfae1c249e5f527
This commit is contained in:
parent
f34b2a909b
commit
a2fb1c0b27
|
@ -161,6 +161,20 @@ class ShowDep(BaseCommand):
|
|||
dependencies.show_dep(parsed_args.components)
|
||||
|
||||
|
||||
class ConfigDump(BaseCommand):
|
||||
"""Dump full current configuration to stdout"""
|
||||
|
||||
def get_parser(self, *args, **kwargs):
|
||||
parser = super(ConfigDump, self).get_parser(*args, **kwargs)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
if CONF.repositories.clone:
|
||||
do_fetch()
|
||||
config.load_component_defaults()
|
||||
config.dump_yaml(self.app.stdout)
|
||||
|
||||
|
||||
def signal_handler(signo, frame):
|
||||
sys.exit(-signo)
|
||||
|
||||
|
|
|
@ -106,3 +106,7 @@ def load_component_defaults():
|
|||
global _REAL_CONF
|
||||
new_config._merge(_REAL_CONF)
|
||||
_REAL_CONF = new_config
|
||||
|
||||
|
||||
def dump_yaml(stream):
|
||||
_yaml.dump(_REAL_CONF, stream)
|
||||
|
|
|
@ -115,6 +115,20 @@ def load_with_includes(filename):
|
|||
return res
|
||||
|
||||
|
||||
class Dumper(yaml.SafeDumper):
|
||||
pass
|
||||
|
||||
|
||||
def represent_attr_dict(dumper, data):
|
||||
return dumper.represent_dict(data._dict)
|
||||
|
||||
Dumper.add_representer(AttrDict, represent_attr_dict)
|
||||
|
||||
|
||||
def dump(obj, stream):
|
||||
yaml.dump(obj, stream, Dumper=Dumper, default_flow_style=False)
|
||||
|
||||
|
||||
class UnwrapAttrDict(dict):
|
||||
def __init__(self, attr_dict):
|
||||
return super(UnwrapAttrDict, self).__init__(attr_dict._dict)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import fixtures
|
||||
import io
|
||||
import mock
|
||||
import six
|
||||
import testscenarios
|
||||
|
@ -101,3 +102,31 @@ class TestLoadWithIncludes(testscenarios.WithScenarios, base.TestCase):
|
|||
|
||||
res = _yaml.load_with_includes('config')
|
||||
self.assertEqual(res, self.expected_result)
|
||||
|
||||
|
||||
class TestLoadDump(testscenarios.WithScenarios, base.TestCase):
|
||||
scenarios = [
|
||||
('simple', {'yaml': 'a: b\n', 'parsed': {'a': 'b'}}),
|
||||
('nested', {
|
||||
'yaml': 'a:\n b: c\n',
|
||||
'parsed': {'a': {'b': 'c'}},
|
||||
}),
|
||||
]
|
||||
|
||||
yaml = None
|
||||
parsed = None
|
||||
|
||||
def test_load(self):
|
||||
res = _yaml.load(self.yaml)
|
||||
self.assertIsInstance(res, _yaml.AttrDict)
|
||||
self.assertEqual(self.parsed, res)
|
||||
|
||||
def test_dump(self):
|
||||
obj = _yaml.AttrDict()
|
||||
obj._merge(self.parsed)
|
||||
if str is bytes:
|
||||
stream = io.BytesIO()
|
||||
else:
|
||||
stream = io.StringIO()
|
||||
_yaml.dump(obj, stream)
|
||||
self.assertEqual(self.yaml, stream.getvalue())
|
||||
|
|
Loading…
Reference in New Issue