コード例 #1
0
    def test_summarized_option_order_single_ns(self):

        config = [('namespace1', [('alpha', self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter,
                                   'alpha',
                                   groups.pop('alpha'),
                                   summarize=True)
        expected = '''[alpha]

#
# From namespace1
#

# This is the summary line for a config option. For more information,
# refer to the documentation. (string value)
#foo = fred

# This is a less carefully formatted configuration
# option, where the author has not broken their description into a
# brief
# summary line and larger description. Watch this person's commit
# messages! (string value)
#bar = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #2
0
    def test_required_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha',
                                   groups.pop('alpha'), True)
        expected = '''[alpha]

#
# From namespace1
#

# bar option (string value)
bar = <None>

# bars foo (string value)
bars = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #3
0
 def test_get_groups_multiple_ns(self):
     config = [("namespace1", [
                ("beta", self.opts),
                ("alpha", self.opts)]),
               ("namespace2", [
                ("gamma", self.opts),
                ("alpha", self.opts)])]
     groups = generator._get_groups(config)
     self.assertEqual(['DEFAULT', 'alpha', 'beta', 'gamma'], sorted(groups))
コード例 #4
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [
                   ("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[DEFAULT]
'''
        generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
コード例 #5
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [
                   ("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        expected = '''[DEFAULT]
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #6
0
    def test_output_opts_group(self):

        config = [("namespace1", [
                   ("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
コード例 #7
0
    def test_output_opts_group(self):

        config = [("namespace1", [
                   ("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #8
0
    def _test_output_default_list_opt_with_string_value(self, default):
        opt = cfg.ListOpt('list_opt', help='a list', default=default)
        config = [("namespace1", [
                   ("alpha", [opt])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# a list (list value)
#list_opt = %(default)s
''' % {'default': default}
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
コード例 #9
0
    def test_advanced_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred

# foobar (string value)
#foo_bar = <None>

# bar option (string value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bar = <None>

# bars foo (boolean value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bars = true
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #10
0
    def test_advanced_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred

# foobar (string value)
#foo_bar = <None>

# bar option (string value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bar = <None>

# bars foo (boolean value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bars = true
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
コード例 #11
0
ファイル: generator.py プロジェクト: openstack/congress
def generate_ns_data(namespace):
    """Generate a json string containing the namespace"""
    groups = generator._get_groups(generator._list_opts([namespace]))
    return OptionJsonEncoder(sort_keys=True).encode(groups)
コード例 #12
0
 def test_get_groups_empty_ns(self):
     groups = generator._get_groups([])
     self.assertEqual({'DEFAULT': []}, groups)
コード例 #13
0
 def test_get_groups_empty_ns(self):
     groups = generator._get_groups([])
     self.assertEqual({'DEFAULT': {'object': None, 'namespaces': []}},
                      groups)
コード例 #14
0
 def test_get_groups_multiple_ns(self):
     config = [("namespace1", [("beta", self.opts), ("alpha", self.opts)]),
               ("namespace2", [("gamma", self.opts), ("alpha", self.opts)])]
     groups = generator._get_groups(config)
     self.assertEqual(['DEFAULT', 'alpha', 'beta', 'gamma'], sorted(groups))
コード例 #15
0
 def test_get_groups_empty_ns(self):
     groups = generator._get_groups([])
     self.assertEqual({'DEFAULT': {
         'object': None,
         'namespaces': []
     }}, groups)
コード例 #16
0
def generate_ns_data(namespace):
    """Generate a json string containing the namespace"""
    groups = generator._get_groups(generator._list_opts([namespace]))
    return OptionJsonEncoder(sort_keys=True).encode(groups)
コード例 #17
0
def generate(conf):
    """Generate a sample config file.

    List all of the options available via the namespaces specified in the given
    configuration and write a description of them to the specified output file.

    :param conf: a ConfigOpts instance containing the generator's configuration
    """
    conf.register_opts(_generator_opts)

    output_file = (open(conf.output_file, 'w')
                   if conf.output_file else sys.stdout)

    output_file.write('''
# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{ include "%s.conf.%s_values_skeleton" .Values.conf.%s | trunc 0 }}
{{ include "%s.conf.%s" .Values.conf.%s }}
\n''' % (conf.helm_chart, conf.helm_namespace, conf.helm_namespace, conf.helm_chart, conf.helm_namespace, conf.helm_namespace))


    output_file.write('''
{{- define "%s.conf.%s_values_skeleton" -}}
\n''' % (conf.helm_chart, conf.helm_namespace))

    ### values skeleton 
    formatter = _ValuesSkeletonFormatter(output_file=output_file,
                              wrap_width=conf.wrap_width)

    groups = _get_groups(_list_opts(conf.namespace))

    # Output the "DEFAULT" section as the very first section
    _output_opts_null(formatter, 'DEFAULT', groups.pop('DEFAULT'), conf.minimal,
                 conf.summarize)

    # output all other config sections with groups in alphabetical order
    for group, group_data in sorted(groups.items()):
        _output_opts_null(formatter, group, group_data, conf.minimal,
                     conf.summarize)

    output_file.write('''
{{- end -}}
\n''')

    output_file.write('''
{{- define "%s.conf.%s" -}}
\n''' % (conf.helm_chart, conf.helm_namespace))


    ### helm options

    formatter = _HelmOptFormatter(output_file=output_file,
                              wrap_width=conf.wrap_width)

    groups = _get_groups(_list_opts(conf.namespace))

    # Output the "DEFAULT" section as the very first section
    _output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'), conf.minimal,
                 conf.summarize)

    # output all other config sections with groups in alphabetical order
    for group, group_data in sorted(groups.items()):
        formatter.write('\n\n')
        _output_opts(formatter, group, group_data, conf.minimal,
                     conf.summarize)


    output_file.write('''
{{- end -}}
\n''')
コード例 #18
0
 def test_get_groups_empty_ns(self):
     groups = generator._get_groups([])
     self.assertEqual({'DEFAULT': []}, groups)