Esempio n. 1
0
from oslo_config import cfg
from oslo_config import types

opts = [
        cfg.StrOpt('server_addr', default='127.0.0.1', help='Server IP address.'),
        cfg.Opt('server_port', type=types.Integer(1024, 65535), default=9090,
            help='Server port number.'),
        ]

CONF = cfg.ConfigOpts()
CONF.register_cli_opts(opts)



Esempio n. 2
0
https://static.openvz.org/vz-man/man1/pstorage-mount.1.gz.html
Format is a python string representation of arguments list, like:
"[\'-v\', \'-R\', \'500\']"
Shouldn\'t include -c, -l, -C, -u, -g and -m as those have
explicit vzstorage_* options.

Related options:

* All other vzstorage_* options
"""),
]

# The queue size requires value to be a power of two from [256, 1024]
# range.
# https://libvirt.org/formatdomain.html#elementsDriverBackendOptions
QueueSizeType = types.Integer(choices=(256, 512, 1024))

libvirt_virtio_queue_sizes = [
    cfg.Opt('rx_queue_size',
            type=QueueSizeType,
            help="""
Configure virtio rx queue size.

This option is only usable for virtio-net device with vhost and
vhost-user backend. Available only with QEMU/KVM. Requires libvirt
v2.3 QEMU v2.7."""),
    cfg.Opt('tx_queue_size',
            type=QueueSizeType,
            help="""
Configure virtio tx queue size.
Esempio n. 3
0
class IntegerTypeTests(TypeTestHelper, unittest.TestCase):
    type = types.Integer()

    def test_empty_string(self):
        self.assertConvertedValue('', None)

    def test_whitespace_string(self):
        self.assertConvertedValue("   \t\t\t\t", None)

    def test_positive_values_are_valid(self):
        self.assertConvertedValue('123', 123)

    def test_zero_is_valid(self):
        self.assertConvertedValue('0', 0)

    def test_negative_values_are_valid(self):
        self.assertConvertedValue('-123', -123)

    def test_leading_whitespace_is_ignored(self):
        self.assertConvertedValue('   5', 5)

    def test_trailing_whitespace_is_ignored(self):
        self.assertConvertedValue('7   ', 7)

    def test_non_digits_are_invalid(self):
        self.assertInvalid('12a45')

    def test_repr(self):
        t = types.Integer()
        self.assertEqual('Integer', repr(t))

    def test_repr_with_min(self):
        t = types.Integer(min=123)
        self.assertEqual('Integer(min=123)', repr(t))

    def test_repr_with_max(self):
        t = types.Integer(max=456)
        self.assertEqual('Integer(max=456)', repr(t))

    def test_repr_with_min_and_max(self):
        t = types.Integer(min=123, max=456)
        self.assertEqual('Integer(min=123, max=456)', repr(t))
        t = types.Integer(min=0, max=0)
        self.assertEqual('Integer(min=0, max=0)', repr(t))

    def test_repr_with_choices(self):
        t = types.Integer(choices=[80, 457])
        self.assertEqual('Integer(choices=[80, 457])', repr(t))

    def test_repr_with_choices_tuple(self):
        t = types.Integer(choices=(80, 457))
        self.assertEqual('Integer(choices=[80, 457])', repr(t))

    def test_repr_with_choices_dict(self):
        t = types.Integer(choices=[(80, 'ab'), (457, 'xy')])
        self.assertEqual('Integer(choices=[80, 457])', repr(t))

    def test_equal(self):
        self.assertTrue(types.Integer() == types.Integer())

    def test_equal_with_same_min_and_no_max(self):
        self.assertTrue(types.Integer(min=123) == types.Integer(min=123))

    def test_equal_with_same_max_and_no_min(self):
        self.assertTrue(types.Integer(max=123) == types.Integer(max=123))

    def test_equal_with_same_min_and_max(self):
        t1 = types.Integer(min=1, max=123)
        t2 = types.Integer(min=1, max=123)
        self.assertTrue(t1 == t2)

    def test_equal_with_same_choices(self):
        t1 = types.Integer(choices=[80, 457])
        t2 = types.Integer(choices=[457, 80])
        t3 = types.Integer(choices=(457, 80))
        t4 = types.Integer(choices=[(80, 'ab'), (457, 'xy')])
        self.assertTrue(t1 == t2 == t3 == t4)

    def test_not_equal(self):
        self.assertFalse(types.Integer(min=123) == types.Integer(min=456))
        self.assertFalse(
            types.Integer(choices=[80, 457]) == types.Integer(
                choices=[80, 40]))
        self.assertFalse(types.Integer(choices=[80, 457]) == types.Integer())

    def test_not_equal_to_other_class(self):
        self.assertFalse(types.Integer() == types.String())

    def test_choices_with_min_max(self):
        self.assertRaises(ValueError, types.Integer, min=100, choices=[50, 60])
        self.assertRaises(ValueError, types.Integer, max=10, choices=[50, 60])
        types.Integer(min=10, max=100, choices=[50, 60])

    def test_min_greater_max(self):
        self.assertRaises(ValueError, types.Integer, min=100, max=50)
        self.assertRaises(ValueError, types.Integer, min=-50, max=-100)
        self.assertRaises(ValueError, types.Integer, min=0, max=-50)
        self.assertRaises(ValueError, types.Integer, min=50, max=0)

    def test_with_max_and_min(self):
        t = types.Integer(min=123, max=456)
        self.assertRaises(ValueError, t, 122)
        t(123)
        t(300)
        t(456)
        self.assertRaises(ValueError, t, 0)
        self.assertRaises(ValueError, t, 457)

    def test_with_min_zero(self):
        t = types.Integer(min=0, max=456)
        self.assertRaises(ValueError, t, -1)
        t(0)
        t(123)
        t(300)
        t(456)
        self.assertRaises(ValueError, t, -201)
        self.assertRaises(ValueError, t, 457)

    def test_with_max_zero(self):
        t = types.Integer(min=-456, max=0)
        self.assertRaises(ValueError, t, 1)
        t(0)
        t(-123)
        t(-300)
        t(-456)
        self.assertRaises(ValueError, t, 201)
        self.assertRaises(ValueError, t, -457)

    def _test_with_choices(self, t):
        self.assertRaises(ValueError, t, 1)
        self.assertRaises(ValueError, t, 200)
        self.assertRaises(ValueError, t, -457)
        t(80)
        t(457)

    def test_with_choices_list(self):
        t = types.Integer(choices=[80, 457])
        self._test_with_choices(t)

    def test_with_choices_tuple(self):
        t = types.Integer(choices=(80, 457))
        self._test_with_choices(t)

    def test_with_choices_dict(self):
        t = types.Integer(choices=[(80, 'ab'), (457, 'xy')])
        self._test_with_choices(t)
Esempio n. 4
0
 def test_equal_with_equal_custom_item_types(self):
     it1 = types.Integer()
     it2 = types.Integer()
     self.assertTrue(types.Dict(it1) == types.Dict(it2))
Esempio n. 5
0
 def test_not_equal_to_other_class(self):
     self.assertNotEqual(types.Hostname(), types.Integer())
     self.assertNotEqual(types.Hostname(), types.String())
Esempio n. 6
0
 def test_bounds_required(self):
     self.type_instance = types.List(types.Integer(), bounds=True)
     self.assertInvalid('1,2,3')
     self.assertInvalid('[1,2,3')
     self.assertInvalid('1,2,3]')
Esempio n. 7
0
 def test_custom_value_type(self):
     self.type_instance = types.Dict(types.Integer())
     self.assertConvertedValue('foo:123, bar: 456', {
         'foo': 123,
         'bar': 456
     })
Esempio n. 8
0
 def test_repr_with_min(self):
     t = types.Integer(min=123)
     self.assertEqual('Integer(min=123)', repr(t))
Esempio n. 9
0
 def test_repr_with_max(self):
     t = types.Integer(max=456)
     self.assertEqual('Integer(max=456)', repr(t))
Esempio n. 10
0
#coding:utf8
from oslo_config import cfg
from oslo_config import types
from test_1 import CONF

PortType = types.Integer(1, 65535)

common_opts = [
    cfg.StrOpt('bind_host', default='0.0.0.0', help='ip address to listen on'),
    cfg.Opt('bind_port',
            type=PortType,
            default=9292,
            help='port number to listen on')
]

server_name_opt = cfg.StrOpt('server_name',
                             default='qq',
                             help='this is server name')


def register_opts(conf):
    conf.register_opts(common_opts)  #注册默认配置选项列表
    conf.register_opt(server_name_opt)  #注册单个默认配置选项


cli_opts = [
    cfg.BoolOpt('verbose',
                short='v',
                default=False,
                help='Print more verbose output'),
    cfg.BoolOpt('debug',
Esempio n. 11
0
class GeneratorTestCase(base.BaseTestCase):

    groups = {
        'group1':
        cfg.OptGroup(name='group1',
                     help='Lorem ipsum dolor sit amet, consectetur '
                     'adipisicing elit, sed do eiusmod tempor '
                     'incididunt ut labore et dolore magna '
                     'aliqua. Ut enim ad minim veniam, quis '
                     'nostrud exercitation ullamco laboris '
                     'nisi ut aliquip ex ea commodo '
                     'consequat. Duis aute irure dolor in.'),
        'group2':
        cfg.OptGroup(name='group2', title='Group 2'),
        'foo':
        cfg.OptGroup(name='foo', title='Foo Title', help='foo help'),
    }

    opts = {
        'foo':
        cfg.StrOpt('foo', help='foo option'),
        'bar':
        cfg.StrOpt('bar', help='bar option'),
        'foo-bar':
        cfg.StrOpt('foo-bar', help='foobar'),
        'no_help':
        cfg.StrOpt('no_help'),
        'long_help':
        cfg.StrOpt('long_help',
                   help='Lorem ipsum dolor sit amet, consectetur '
                   'adipisicing elit, sed do eiusmod tempor '
                   'incididunt ut labore et dolore magna '
                   'aliqua. Ut enim ad minim veniam, quis '
                   'nostrud exercitation ullamco laboris '
                   'nisi ut aliquip ex ea commodo '
                   'consequat. Duis aute irure dolor in '
                   'reprehenderit in voluptate velit esse '
                   'cillum dolore eu fugiat nulla '
                   'pariatur. Excepteur sint occaecat '
                   'cupidatat non proident, sunt in culpa '
                   'qui officia deserunt mollit anim id est '
                   'laborum.'),
        'long_help_pre':
        cfg.StrOpt('long_help_pre',
                   help='This is a very long help text which '
                   'is preformatted with line breaks. '
                   'It should break when it is too long '
                   'but also keep the specified line '
                   'breaks. This makes it possible to '
                   'create lists with items:\n'
                   '\n'
                   '* item 1\n'
                   '* item 2\n'
                   '\n'
                   'and should increase the '
                   'readability.'),
        'choices_opt':
        cfg.StrOpt('choices_opt',
                   default='a',
                   choices=(None, '', 'a', 'b', 'c'),
                   help='a string with choices'),
        'deprecated_opt_without_deprecated_group':
        cfg.StrOpt('bar', deprecated_name='foobar', help='deprecated'),
        'deprecated_for_removal_opt':
        cfg.StrOpt('bar',
                   deprecated_for_removal=True,
                   help='deprecated for removal'),
        'deprecated_reason_opt':
        cfg.BoolOpt(
            'turn_off_stove',
            default=False,
            deprecated_for_removal=True,
            deprecated_reason='This was supposed to work but it really, '
            'really did not. Always buy house insurance.',
            help='DEPRECATED: Turn off stove'),
        'deprecated_opt_with_deprecated_since':
        cfg.BoolOpt('tune_in',
                    deprecated_for_removal=True,
                    deprecated_since='13.0'),
        'deprecated_opt_with_deprecated_group':
        cfg.StrOpt('bar',
                   deprecated_name='foobar',
                   deprecated_group='group1',
                   help='deprecated'),
        'opt_with_DeprecatedOpt':
        cfg.BoolOpt(
            'foo-bar',
            help='Opt with DeprecatedOpt',
            deprecated_opts=[cfg.DeprecatedOpt('foo-bar',
                                               group='deprecated')]),
        # Unknown Opt default must be a string
        'unknown_type':
        cfg.Opt('unknown_opt',
                default='123',
                help='unknown',
                type=types.String(type_name='unknown type')),
        'str_opt':
        cfg.StrOpt('str_opt', default='foo bar', help='a string'),
        'str_opt_sample_default':
        cfg.StrOpt('str_opt', default='fooishbar', help='a string'),
        'str_opt_with_space':
        cfg.StrOpt('str_opt',
                   default='  foo bar  ',
                   help='a string with spaces'),
        'bool_opt':
        cfg.BoolOpt('bool_opt', default=False, help='a boolean'),
        'int_opt':
        cfg.IntOpt('int_opt', default=10, min=1, max=20, help='an integer'),
        'int_opt_min_0':
        cfg.IntOpt('int_opt_min_0',
                   default=10,
                   min=0,
                   max=20,
                   help='an integer'),
        'int_opt_max_0':
        cfg.IntOpt('int_opt_max_0', default=-1, max=0, help='an integer'),
        'float_opt':
        cfg.FloatOpt('float_opt', default=0.1, help='a float'),
        'list_opt':
        cfg.ListOpt('list_opt', default=['1', '2', '3'], help='a list'),
        'dict_opt':
        cfg.DictOpt('dict_opt', default={
            '1': 'yes',
            '2': 'no'
        }, help='a dict'),
        'ip_opt':
        cfg.IPOpt('ip_opt', default='127.0.0.1', help='an ip address'),
        'port_opt':
        cfg.PortOpt('port_opt', default=80, help='a port'),
        'hostname_opt':
        cfg.HostnameOpt('hostname_opt',
                        default='compute01.nova.site1',
                        help='a hostname'),
        'uri_opt':
        cfg.URIOpt('uri_opt', default='http://example.com', help='a URI'),
        'multi_opt':
        cfg.MultiStrOpt('multi_opt',
                        default=['1', '2', '3'],
                        help='multiple strings'),
        'multi_opt_none':
        cfg.MultiStrOpt('multi_opt_none', help='multiple strings'),
        'multi_opt_empty':
        cfg.MultiStrOpt('multi_opt_empty', default=[],
                        help='multiple strings'),
        'multi_opt_sample_default':
        cfg.MultiStrOpt('multi_opt',
                        default=['1', '2', '3'],
                        sample_default=['5', '6'],
                        help='multiple strings'),
        'string_type_with_bad_default':
        cfg.Opt('string_type_with_bad_default',
                help='string with bad default',
                default=4096),
        'native_str_type':
        cfg.Opt('native_str_type', help='native help', type=str),
        'native_int_type':
        cfg.Opt('native_int_type', help='native help', type=int),
        'native_float_type':
        cfg.Opt('native_float_type', help='native help', type=float),
        'custom_type':
        cfg.Opt('custom_type', help='custom help', type=custom_type),
        'custom_type_name':
        cfg.Opt('custom_opt_type',
                type=types.Integer(type_name='port'
                                   ' number'),
                default=5511,
                help='this is a port'),
    }

    content_scenarios = [
        ('empty', dict(opts=[], expected='''[DEFAULT]
''')),
        ('single_namespace',
         dict(opts=[('test', [(None, [opts['foo']])])],
              expected='''[DEFAULT]

#
# From test
#

# foo option (string value)
#foo = <None>
''')),
        ('multiple_namespaces',
         dict(opts=[('test', [(None, [opts['foo']])]),
                    ('other', [(None, [opts['bar']])])],
              expected='''[DEFAULT]

#
# From other
#

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

#
# From test
#

# foo option (string value)
#foo = <None>
''')),
        ('group',
         dict(opts=[('test', [(groups['group1'], [opts['foo']])])],
              expected='''[DEFAULT]


[group1]
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in.

#
# From test
#

# foo option (string value)
#foo = <None>
''')),
        ('empty_group',
         dict(opts=[('test', [(groups['group1'], [])])],
              expected='''[DEFAULT]
''')),
        ('multiple_groups',
         dict(opts=[('test', [(groups['group1'], [opts['foo']]),
                              (groups['group2'], [opts['bar']])])],
              expected='''[DEFAULT]


[group1]
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in.

#
# From test
#

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


[group2]

#
# From test
#

# bar option (string value)
#bar = <None>
''')),
        ('group_in_multiple_namespaces',
         dict(opts=[('test', [(groups['group1'], [opts['foo']])]),
                    ('other', [(groups['group1'], [opts['bar']])])],
              expected='''[DEFAULT]


[group1]
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in.

#
# From other
#

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

#
# From test
#

# foo option (string value)
#foo = <None>
''')),
        ('hyphenated_name',
         dict(opts=[('test', [(None, [opts['foo-bar']])])],
              expected='''[DEFAULT]

#
# From test
#

# foobar (string value)
#foo_bar = <None>
''')),
        ('no_help',
         dict(opts=[('test', [(None, [opts['no_help']])])],
              log_warning=('"%s" is missing a help string', 'no_help'),
              expected='''[DEFAULT]

#
# From test
#

# (string value)
#no_help = <None>
''')),
        ('long_help',
         dict(opts=[('test', [(None, [opts['long_help']])])],
              expected='''[DEFAULT]

#
# From test
#

# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in
# reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
# pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
# culpa qui officia deserunt mollit anim id est laborum. (string
# value)
#long_help = <None>
''')),
        ('long_help_wrap_at_40',
         dict(opts=[('test', [(None, [opts['long_help']])])],
              wrap_width=40,
              expected='''[DEFAULT]

#
# From test
#

# Lorem ipsum dolor sit amet,
# consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et
# dolore magna aliqua. Ut enim ad minim
# veniam, quis nostrud exercitation
# ullamco laboris nisi ut aliquip ex ea
# commodo consequat. Duis aute irure
# dolor in reprehenderit in voluptate
# velit esse cillum dolore eu fugiat
# nulla pariatur. Excepteur sint
# occaecat cupidatat non proident, sunt
# in culpa qui officia deserunt mollit
# anim id est laborum. (string value)
#long_help = <None>
''')),
        (
            'long_help_no_wrapping',
            dict(
                opts=[('test', [(None, [opts['long_help']])])],
                wrap_width=0,
                expected='''[DEFAULT]

#
# From test
#

'''

                # noqa
                '# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod '
                'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, '
                'quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo '
                'consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse '
                'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat '
                'non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
                '(string value)'
                '''
#long_help = <None>
''')),
        ('long_help_with_preformatting',
         dict(opts=[('test', [(None, [opts['long_help_pre']])])],
              wrap_width=70,
              expected='''[DEFAULT]

#
# From test
#

# This is a very long help text which is preformatted with line
# breaks. It should break when it is too long but also keep the
# specified line breaks. This makes it possible to create lists with
# items:
#
# * item 1
# * item 2
#
# and should increase the readability. (string value)
#long_help_pre = <None>
''')),
        ('choices_opt',
         dict(opts=[('test', [(None, [opts['choices_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a string with choices (string value)
# Allowed values: <None>, '', a, b, c
#choices_opt = a
''')),
        ('deprecated opt without deprecated group',
         dict(opts=[('test', [
             (groups['foo'], [opts['deprecated_opt_without_deprecated_group']])
         ])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From test
#

# deprecated (string value)
# Deprecated group/name - [foo]/foobar
#bar = <None>
''')),
        ('deprecated_for_removal',
         dict(opts=[('test', [(groups['foo'],
                               [opts['deprecated_for_removal_opt']])])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From test
#

# DEPRECATED: deprecated for removal (string value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#bar = <None>
''')),
        ('deprecated_reason',
         dict(opts=[('test', [(groups['foo'], [opts['deprecated_reason_opt']])
                              ])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From test
#

# DEPRECATED: Turn off stove (boolean value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
# Reason: This was supposed to work but it really, really did not.
# Always buy house insurance.
#turn_off_stove = false
''')),
        ('deprecated_opt_with_deprecated_group',
         dict(opts=[('test', [
             (groups['foo'], [opts['deprecated_opt_with_deprecated_group']])
         ])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From test
#

# deprecated (string value)
# Deprecated group/name - [group1]/foobar
#bar = <None>
''')),
        ('unknown_type',
         dict(opts=[('test', [(None, [opts['unknown_type']])])],
              expected='''[DEFAULT]

#
# From test
#

# unknown (unknown type)
#unknown_opt = 123
''')),
        ('str_opt',
         dict(opts=[('test', [(None, [opts['str_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a string (string value)
#str_opt = foo bar
''')),
        ('str_opt_with_space',
         dict(opts=[('test', [(None, [opts['str_opt_with_space']])])],
              expected='''[DEFAULT]

#
# From test
#

# a string with spaces (string value)
#str_opt = "  foo bar  "
''')),
        ('bool_opt',
         dict(opts=[('test', [(None, [opts['bool_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a boolean (boolean value)
#bool_opt = false
''')),
        ('int_opt',
         dict(opts=[('test', [(None, [opts['int_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# an integer (integer value)
# Minimum value: 1
# Maximum value: 20
#int_opt = 10
''')),
        ('int_opt_min_0',
         dict(opts=[('test', [(None, [opts['int_opt_min_0']])])],
              expected='''[DEFAULT]

#
# From test
#

# an integer (integer value)
# Minimum value: 0
# Maximum value: 20
#int_opt_min_0 = 10
''')),
        ('int_opt_max_0',
         dict(opts=[('test', [(None, [opts['int_opt_max_0']])])],
              expected='''[DEFAULT]

#
# From test
#

# an integer (integer value)
# Maximum value: 0
#int_opt_max_0 = -1
''')),
        ('float_opt',
         dict(opts=[('test', [(None, [opts['float_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a float (floating point value)
#float_opt = 0.1
''')),
        ('list_opt',
         dict(opts=[('test', [(None, [opts['list_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a list (list value)
#list_opt = 1,2,3
''')),
        ('dict_opt',
         dict(opts=[('test', [(None, [opts['dict_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a dict (dict value)
#dict_opt = 1:yes,2:no
''')),
        ('ip_opt',
         dict(opts=[('test', [(None, [opts['ip_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# an ip address (IP address value)
#ip_opt = 127.0.0.1
''')),
        ('port_opt',
         dict(opts=[('test', [(None, [opts['port_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a port (port value)
# Minimum value: 0
# Maximum value: 65535
#port_opt = 80
''')),
        ('hostname_opt',
         dict(opts=[('test', [(None, [opts['hostname_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# a hostname (hostname value)
#hostname_opt = compute01.nova.site1
''')),
        ('multi_opt',
         dict(opts=[('test', [(None, [opts['multi_opt']])])],
              expected='''[DEFAULT]

#
# From test
#

# multiple strings (multi valued)
#multi_opt = 1
#multi_opt = 2
#multi_opt = 3
''')),
        ('multi_opt_none',
         dict(opts=[('test', [(None, [opts['multi_opt_none']])])],
              expected='''[DEFAULT]

#
# From test
#

# multiple strings (multi valued)
#multi_opt_none =
''')),
        ('multi_opt_empty',
         dict(opts=[('test', [(None, [opts['multi_opt_empty']])])],
              expected='''[DEFAULT]

#
# From test
#

# multiple strings (multi valued)
#multi_opt_empty =
''')),
        ('str_opt_sample_default',
         dict(opts=[('test', [(None, [opts['str_opt_sample_default']])])],
              expected='''[DEFAULT]

#
# From test
#

# a string (string value)
#str_opt = fooishbar
''')),
        ('native_str_type',
         dict(opts=[('test', [(None, [opts['native_str_type']])])],
              expected='''[DEFAULT]

#
# From test
#

# native help (string value)
#native_str_type = <None>
''')),
        ('native_int_type',
         dict(opts=[('test', [(None, [opts['native_int_type']])])],
              expected='''[DEFAULT]

#
# From test
#

# native help (integer value)
#native_int_type = <None>
''')),
        ('native_float_type',
         dict(opts=[('test', [(None, [opts['native_float_type']])])],
              expected='''[DEFAULT]

#
# From test
#

# native help (floating point value)
#native_float_type = <None>
''')),
        ('multi_opt_sample_default',
         dict(opts=[('test', [(None, [opts['multi_opt_sample_default']])])],
              expected='''[DEFAULT]

#
# From test
#

# multiple strings (multi valued)
#multi_opt = 5
#multi_opt = 6
''')),
        ('custom_type_name',
         dict(opts=[('test', [(None, [opts['custom_type_name']])])],
              expected='''[DEFAULT]

#
# From test
#

# this is a port (port number)
#custom_opt_type = 5511
''')),
        ('custom_type',
         dict(opts=[('test', [(None, [opts['custom_type']])])],
              expected='''[DEFAULT]

#
# From test
#

# custom help (unknown value)
#custom_type = <None>
''')),
        ('string_type_with_bad_default',
         dict(opts=[('test', [(None, [opts['string_type_with_bad_default']])])
                    ],
              expected='''[DEFAULT]

#
# From test
#

# string with bad default (string value)
#string_type_with_bad_default = 4096
''')),
        ('str_opt_str_group',
         dict(opts=[('test', [('foo', [opts['str_opt']]),
                              (groups['foo'], [opts['int_opt']])]),
                    ('foo', [('foo', [opts['bool_opt']])])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From foo
#

# a boolean (boolean value)
#bool_opt = false

#
# From test
#

# a string (string value)
#str_opt = foo bar

#
# From test
#

# an integer (integer value)
# Minimum value: 1
# Maximum value: 20
#int_opt = 10
''')),
        ('opt_str_opt_group',
         dict(opts=[('test', [(groups['foo'], [opts['int_opt']]),
                              ('foo', [opts['str_opt']])]),
                    ('foo', [(groups['foo'], [opts['bool_opt']])])],
              expected='''[DEFAULT]


[foo]
# foo help

#
# From foo
#

# a boolean (boolean value)
#bool_opt = false

#
# From test
#

# an integer (integer value)
# Minimum value: 1
# Maximum value: 20
#int_opt = 10

#
# From test
#

# a string (string value)
#str_opt = foo bar
''')),
        ('opt_with_DeprecatedOpt',
         dict(opts=[('test', [(None, [opts['opt_with_DeprecatedOpt']])])],
              expected='''[DEFAULT]

#
# From test
#

# Opt with DeprecatedOpt (boolean value)
# Deprecated group/name - [deprecated]/foo_bar
#foo_bar = <None>
''')),
    ]

    output_file_scenarios = [
        ('stdout', dict(stdout=True, output_file=None)),
        ('output_file', dict(output_file='sample.conf', stdout=False)),
    ]

    @classmethod
    def generate_scenarios(cls):
        cls.scenarios = testscenarios.multiply_scenarios(
            cls.content_scenarios, cls.output_file_scenarios)

    def setUp(self):
        super(GeneratorTestCase, self).setUp()

        self.conf = cfg.ConfigOpts()
        self.config_fixture = config_fixture.Config(self.conf)
        self.config = self.config_fixture.config
        self.useFixture(self.config_fixture)

        self.tempdir = self.useFixture(fixtures.TempDir())

    def _capture_stream(self, stream_name):
        self.useFixture(
            fixtures.MonkeyPatch("sys.%s" % stream_name, moves.StringIO()))
        return getattr(sys, stream_name)

    def _capture_stdout(self):
        return self._capture_stream('stdout')

    @mock.patch.object(generator, '_get_raw_opts_loaders')
    @mock.patch.object(generator, 'LOG')
    def test_generate(self, mock_log, raw_opts_loader):
        generator.register_cli_opts(self.conf)

        namespaces = [i[0] for i in self.opts]
        self.config(namespace=namespaces)

        for group in self.groups.values():
            self.conf.register_group(group)

        wrap_width = getattr(self, 'wrap_width', None)
        if wrap_width is not None:
            self.config(wrap_width=wrap_width)

        if self.stdout:
            stdout = self._capture_stdout()
        else:
            output_file = self.tempdir.join(self.output_file)
            self.config(output_file=output_file)

        # We have a static data structure matching what should be
        # returned by _list_opts() but we're mocking out a lower level
        # function that needs to return a namespace and a callable to
        # return options from that namespace. We have to pass opts to
        # the lambda to cache a reference to the name because the list
        # comprehension changes the thing pointed to by the name each
        # time through the loop.
        raw_opts_loader.return_value = [(ns, lambda opts=opts: opts)
                                        for ns, opts in self.opts]

        generator.generate(self.conf)

        if self.stdout:
            self.assertEqual(self.expected, stdout.getvalue())
        else:
            with open(output_file, 'r') as f:
                actual = f.read()
            self.assertEqual(self.expected, actual)

        log_warning = getattr(self, 'log_warning', None)
        if log_warning is not None:
            mock_log.warning.assert_called_once_with(*log_warning)
        else:
            self.assertFalse(mock_log.warning.called)
Esempio n. 12
0
 def test_choices_with_min_max(self):
     self.assertRaises(ValueError, types.Integer, min=100, choices=[50, 60])
     self.assertRaises(ValueError, types.Integer, max=10, choices=[50, 60])
     types.Integer(min=10, max=100, choices=[50, 60])
Esempio n. 13
0
 def test_repr_with_choices_tuple(self):
     t = types.Integer(choices=(80, 457))
     self.assertEqual('Integer(choices=(80, 457))', repr(t))
from neutron.agent.linux import ip_lib  # noqa: E402
from neutron.common import config as common_config  # noqa: E402
from neutron.plugins.ml2.drivers.linuxbridge.agent import \
    linuxbridge_neutron_agent as lnx_agt  # noqa: E402

from neutron_lib.agent import l2_extension  # noqa: E402
from neutron_lib import constants as n_const  # noqa: E402

LOG = logging.getLogger(__name__)

BAGPIPE_L2_SERVICE = 'bagpipe_l2'

opts = [
    cfg.ListOpt('as_number',
                default=[64512],
                item_type=types.Integer(min=1, max=2**32),
                help=("Autonomous System number used to generate BGP RTs for"
                      "E-VPNs used by bagpipe ML2 (more than one is possible,"
                      "to allow a deployment to do a 2-step transition "
                      "to change the AS number used)"))
]
cfg.CONF.register_opts(opts, "ml2_bagpipe_extension")


class BagpipeML2AgentExtension(l2_extension.L2AgentExtension,
                               agent_base_info.BaseInfoManager):
    def initialize(self, connection, driver_type):

        self.bagpipe_bgp_agent = (
            bagpipe_bgp_agent.BaGPipeBGPAgent.get_instance(
                n_const.AGENT_TYPE_LINUXBRIDGE))
Esempio n. 15
0
 def test_list_of_custom_type(self):
     self.type_instance = types.List(types.Integer())
     self.assertConvertedValue('1,2,3,5', [1, 2, 3, 5])
Esempio n. 16
0
 def test_repr_with_min_and_max(self):
     t = types.Integer(min=123, max=456)
     self.assertEqual('Integer(min=123, max=456)', repr(t))
     t = types.Integer(min=0, max=0)
     self.assertEqual('Integer(min=0, max=0)', repr(t))
Esempio n. 17
0
 def test_bounds_parsing(self):
     self.type_instance = types.List(types.Integer(), bounds=True)
     self.assertConvertedValue('[1,2,3]', [1, 2, 3])
Esempio n. 18
0
 def test_repr_with_choices(self):
     t = types.Integer(choices=[80, 457])
     self.assertEqual('Integer(choices=[80, 457])', repr(t))
Esempio n. 19
0
 def test_repr(self):
     t = types.List(types.Integer())
     self.assertEqual('List of Integer', repr(t))
Esempio n. 20
0
 def test_equal(self):
     self.assertTrue(types.Integer() == types.Integer())
Esempio n. 21
0
 def test_repr(self):
     t = types.Dict(types.Integer())
     self.assertEqual('Dict of Integer', repr(t))
Esempio n. 22
0
 def test_equal_with_same_max_and_no_min(self):
     self.assertTrue(types.Integer(max=123) == types.Integer(max=123))
Esempio n. 23
0
 def test_not_equal_with_non_equal_custom_item_types(self):
     it1 = types.Integer()
     it2 = types.String()
     self.assertFalse(it1 == it2)
     self.assertFalse(types.Dict(it1) == types.Dict(it2))
Esempio n. 24
0
 def test_equal_with_same_min_and_max(self):
     t1 = types.Integer(min=1, max=123)
     t2 = types.Integer(min=1, max=123)
     self.assertTrue(t1 == t2)
Esempio n. 25
0
    cfg.IntOpt('max_retry',
               default=3,
               help='The number of retry when there is a '
               'connection error.'),
    cfg.BoolOpt('auto_commit',
                default=False,
                help='If automatically commmit when consume '
                'messages.'),
    cfg.BoolOpt('async', default=True, help='The type of posting.'),
    cfg.BoolOpt('compact',
                default=True,
                help=('Specify if the message received should be parsed.'
                      'If True, message will not be parsed, otherwise '
                      'messages will be parsed.')),
    cfg.MultiOpt('partitions',
                 item_type=types.Integer(),
                 default=0,
                 help='The partitions this connection should '
                 'listen for messages on. Currently does not '
                 'support multiple partitions. '
                 'Default is to listen on partition 0.'),
    cfg.BoolOpt('drop_data',
                default=False,
                help=('Specify if received data should be simply dropped. '
                      'This parameter is only for testing purposes.')),
]

kafka_group = cfg.OptGroup(name='kafka', title='title')
cfg.CONF.register_group(kafka_group)
cfg.CONF.register_opts(kafka_opts, kafka_group)
Esempio n. 26
0
 def test_equal_with_same_choices(self):
     t1 = types.Integer(choices=[80, 457])
     t2 = types.Integer(choices=[457, 80])
     self.assertTrue(t1 == t2)
Esempio n. 27
0
 def test_not_equal_to_other_class(self):
     self.assertFalse(types.String() == types.Integer())
Esempio n. 28
0
 def test_not_equal(self):
     self.assertFalse(types.Integer(min=123) == types.Integer(min=456))
     self.assertFalse(
         types.Integer(choices=[80, 457]) == types.Integer(
             choices=[80, 40]))
     self.assertFalse(types.Integer(choices=[80, 457]) == types.Integer())
Esempio n. 29
0
 def test_repr(self):
     t = types.Integer()
     self.assertEqual('Integer', repr(t))
Esempio n. 30
0
 def test_tuple_of_custom_type(self):
     self.type_instance = types.List(types.Integer())
     self.assertConvertedValue(('1', '2', '3', '5'), [1, 2, 3, 5])