Register all config options in one place

Make a single point responsible for config option registration to
increase control over config initialization and avoid conflicts.

Usually such conflicts become visible when sharing code with externa
callers. In our case it was the deployment config validator (part of
data drivers), exported as part of the ironic data driver via the
setuptools entry point.

Change-Id: Ibba18db61c222d910d8dca8866ea74b14ce011c8
This commit is contained in:
Dmitry Bogun 2017-02-23 15:27:42 +02:00 committed by Bogun Dmitriy
parent 726e510897
commit 937eb632e5
15 changed files with 297 additions and 381 deletions

View File

@ -27,49 +27,7 @@ from bareon.utils import grub as gu
from bareon.utils import hardware as hw
from bareon.utils import utils
opts = [
cfg.IntOpt(
'timeout',
default=10,
help='Timeout in secs for GRUB'
),
cfg.BoolOpt(
'fix_udev_net_rules',
default=True,
help='Add udev rules for NIC remapping'
),
cfg.ListOpt(
'lvm_filter_for_mpath',
default=['r|^/dev/disk/.*|',
'a|^/dev/mapper/.*|',
'r/.*/'],
help='Extra filters for lvm.conf to force LVM works with partitions '
'on multipath devices properly.'
),
cfg.ListOpt(
'mpath_lvm_preferred_names',
default=['^/dev/mapper/'],
help='List of devlinks patterns which are preffered for LVM. If '
'multipath device has a few devlinks, LVM will use the one '
'matching to the given pattern.'
),
cfg.ListOpt(
'mpath_lvm_scan_dirs',
default=['/dev/disk/', '/dev/mapper/'],
help='List of directories to scan recursively for LVM physical '
'volumes. Devices in directories outside this hierarchy will be '
'ignored.'
),
cfg.StrOpt(
'lvm_conf_path',
default='/etc/lvm/lvm.conf',
help='Path to LVM configuration file'
)
]
CONF = cfg.CONF
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)

View File

@ -27,32 +27,7 @@ from bareon import errors
from bareon.utils import fs as fu
from bareon.utils import utils
opts = [
cfg.StrOpt(
'nc_template_path',
default='/usr/share/bareon/cloud-init-templates',
help='Path to directory with cloud init templates',
),
cfg.StrOpt(
'tmp_path',
default='/tmp',
help='Temporary directory for file manipulations',
),
cfg.StrOpt(
'config_drive_path',
default='/tmp/config-drive.img',
help='Path where to store generated config drive image',
),
cfg.BoolOpt(
'prepare_configdrive',
default=True,
help='Create configdrive file, use pre-builded if set to False'
),
]
CONF = cfg.CONF
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)

View File

@ -27,44 +27,7 @@ from bareon.utils import md as mu
from bareon.utils import partition as pu
from bareon.utils import utils
opts = [
cfg.StrOpt(
'udev_rules_dir',
default='/etc/udev/rules.d',
help='Path where to store actual rules for udev daemon',
),
cfg.StrOpt(
'udev_rules_lib_dir',
default='/lib/udev/rules.d',
help='Path where to store default rules for udev daemon',
),
cfg.StrOpt(
'udev_rename_substr',
default='.renamedrule',
help='Substring to which file extension .rules be renamed',
),
cfg.StrOpt(
'udev_empty_rule',
default='empty_rule',
help='Correct empty rule for udev daemon',
),
cfg.BoolOpt(
'skip_md_containers',
default=True,
help='Allow to skip MD containers (fake raid leftovers) while '
'cleaning the rest of MDs',
),
cfg.StrOpt(
'partition_alignment',
default='optimal',
help='Set alignment for newly created partitions, valid alignment '
'types are: none, cylinder, minimal, optimal'
),
]
CONF = cfg.CONF
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)

View File

@ -21,6 +21,7 @@ from oslo_log import log as logging
import six
import yaml
from bareon import conf
from bareon import errors
from bareon.utils import utils
from bareon import version
@ -56,11 +57,6 @@ cli_opts = [
default='/tmp/config-drive.img',
help='Path where to store generated config drive image',
),
cfg.StrOpt(
'image_build_dir',
default='/tmp',
help='Directory where the image is supposed to be built',
),
]
CONF = cfg.CONF
@ -141,6 +137,8 @@ def handle_exception(exc):
def main(actions=None):
conf.register_opts()
# NOTE(agordeev): get its own process group by calling setpgrp.
# Process group is used to distribute signals to subprocesses.
# The main application is already a process group leader,

27
bareon/conf/__init__.py Normal file
View File

@ -0,0 +1,27 @@
#
# Copyright 2017 Cray Inc. All Rights Reserved.
#
# 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.
from oslo_config import cfg
from oslo_log import log as logging
from bareon.conf import default
CONF = cfg.CONF
def register_opts():
default.register_opts(CONF)
logging.register_options(CONF)

247
bareon/conf/default.py Normal file
View File

@ -0,0 +1,247 @@
#
# Copyright 2017 Cray Inc. All Rights Reserved.
#
# 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.
from oslo_config import cfg
action_opts = [
cfg.IntOpt(
'timeout',
default=10,
help='Timeout in secs for GRUB'
),
cfg.BoolOpt(
'fix_udev_net_rules',
default=True,
help='Add udev rules for NIC remapping'
),
cfg.ListOpt(
'lvm_filter_for_mpath',
default=['r|^/dev/disk/.*|',
'a|^/dev/mapper/.*|',
'r/.*/'],
help='Extra filters for lvm.conf to force LVM works with partitions '
'on multipath devices properly.'
),
cfg.ListOpt(
'mpath_lvm_preferred_names',
default=['^/dev/mapper/'],
help='List of devlinks patterns which are preffered for LVM. If '
'multipath device has a few devlinks, LVM will use the one '
'matching to the given pattern.'
),
cfg.ListOpt(
'mpath_lvm_scan_dirs',
default=['/dev/disk/', '/dev/mapper/'],
help='List of directories to scan recursively for LVM physical '
'volumes. Devices in directories outside this hierarchy will be '
'ignored.'
),
cfg.StrOpt(
'lvm_conf_path',
default='/etc/lvm/lvm.conf',
help='Path to LVM configuration file'
),
cfg.StrOpt(
'nc_template_path',
default='/usr/share/bareon/cloud-init-templates',
help='Path to directory with cloud init templates',
),
cfg.StrOpt(
'tmp_path',
default='/tmp',
help='Temporary directory for file manipulations',
),
cfg.StrOpt(
'config_drive_path',
default='/tmp/config-drive.img',
help='Path where to store generated config drive image',
),
cfg.BoolOpt(
'prepare_configdrive',
default=True,
help='Create configdrive file, use pre-builded if set to False'
),
cfg.StrOpt(
'udev_rules_dir',
default='/etc/udev/rules.d',
help='Path where to store actual rules for udev daemon',
),
cfg.StrOpt(
'udev_rules_lib_dir',
default='/lib/udev/rules.d',
help='Path where to store default rules for udev daemon',
),
cfg.StrOpt(
'udev_rename_substr',
default='.renamedrule',
help='Substring to which file extension .rules be renamed',
),
cfg.StrOpt(
'udev_empty_rule',
default='empty_rule',
help='Correct empty rule for udev daemon',
),
cfg.BoolOpt(
'skip_md_containers',
default=True,
help='Allow to skip MD containers (fake raid leftovers) while '
'cleaning the rest of MDs',
),
cfg.StrOpt(
'partition_alignment',
default='optimal',
help='Set alignment for newly created partitions, valid alignment '
'types are: none, cylinder, minimal, optimal'
),
]
generic_deploy_opts = [
cfg.StrOpt(
'udev_rules_dir',
default='/etc/udev/rules.d',
help='Path where to store actual rules for udev daemon',
),
cfg.StrOpt(
'udev_rules_lib_dir',
default='/lib/udev/rules.d',
help='Path where to store default rules for udev daemon',
),
cfg.StrOpt(
'udev_rename_substr',
default='.renamedrule',
help='Substring to which file extension .rules be renamed',
),
cfg.StrOpt(
'udev_empty_rule',
default='empty_rule',
help='Correct empty rule for udev daemon',
),
cfg.IntOpt(
'grub_timeout',
default=5,
help='Timeout in secs for GRUB'
),
cfg.StrOpt(
'default_root_password',
default='r00tme',
help='Default password for root user',
),
]
swift_deploy_opts = [
cfg.StrOpt(
'image_build_dir',
default='/tmp',
help='Directory where the image is supposed to be built',
),
cfg.StrOpt(
'image_build_suffix',
default='.fuel-agent-image',
help='Suffix which is used while creating temporary files',
),
cfg.IntOpt(
'max_loop_devices_count',
default=255,
# NOTE(agordeev): up to 256 loop devices could be allocated up to
# kernel version 2.6.23, and the limit (from version 2.6.24 onwards)
# isn't theoretically present anymore.
help='Maximum allowed loop devices count to use'
),
cfg.IntOpt(
'sparse_file_size',
# XXX: Apparently Fuel configures the node root filesystem to span
# the whole hard drive. However 2 GB filesystem created with default
# options can grow at most to 2 TB (1024x its initial size). This
# maximal size can be configured by mke2fs -E resize=NNN option,
# however the version of e2fsprogs shipped with CentOS 6.[65] seems
# to silently ignore the `resize' option. Therefore make the initial
# filesystem a bit bigger so it can grow to 8 TB.
default=8192,
help='Size of sparse file in MiBs'
),
cfg.IntOpt(
'loop_device_major_number',
default=7,
help='System-wide major number for loop device'
),
cfg.IntOpt(
'fetch_packages_attempts',
default=10,
help='Maximum allowed debootstrap/apt-get attempts to execute'
),
cfg.StrOpt(
'allow_unsigned_file',
default='allow_unsigned_packages',
help='File where to store apt setting for unsigned packages'
),
cfg.StrOpt(
'force_ipv4_file',
default='force_ipv4',
help='File where to store apt setting for forcing IPv4 usage'
),
cfg.IntOpt(
'max_allowed_attempts_attach_image',
default=10,
help='Maximum allowed attempts to attach image file to loop device'
),
]
utils_opts = [
cfg.IntOpt(
'data_chunk_size',
default=1048576,
help='Size of data chunk to operate with images'
),
cfg.IntOpt(
'http_max_retries',
default=30,
help='Maximum retries count for http requests. 0 means infinite',
),
cfg.FloatOpt(
'http_request_timeout',
# Setting it to 10 secs will allow fuel-agent to overcome the momentary
# peak loads when network bandwidth becomes as low as 0.1MiB/s, thus
# preventing of wasting too much retries on such false positives.
default=10.0,
help='Http request timeout in seconds',
),
cfg.FloatOpt(
'http_retry_delay',
default=2.0,
help='Delay in seconds before the next http request retry',
),
cfg.IntOpt(
'read_chunk_size',
default=1048576,
help='Block size of data to read for calculating checksum',
),
cfg.FloatOpt(
'execute_retry_delay',
default=2.0,
help='Delay in seconds before the next exectuion will retry',
),
cfg.IntOpt(
'partition_udev_settle_attempts',
default=10,
help='How many times udev settle will be called after partitioning'
),
]
def register_opts(conf):
conf.register_opts(action_opts)
conf.register_opts(generic_deploy_opts)
conf.register_opts(swift_deploy_opts)
conf.register_opts(utils_opts)

View File

@ -29,15 +29,7 @@ from bareon.drivers.data.base import PartitioningDataDriverMixin
from bareon.drivers.data.base import ProvisioningDataDriverMixin
opts = [
cfg.StrOpt(
'config_drive_path',
default='/tmp/config-drive.img',
help='Path where to store generated config drive image',
),
]
CONF = cfg.CONF
CONF.register_opts(opts)
# TODO(lobur): This driver mostly copies nailgun driver. Need to merge them.

View File

@ -39,11 +39,7 @@ from bareon import objects
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.import_opt('prepare_configdrive', 'bareon.drivers.deploy.nailgun')
CONF.import_opt('config_drive_path', 'bareon.drivers.deploy.nailgun')
CONF.import_opt('default_root_password', 'bareon.drivers.deploy.nailgun')
def match_device(hu_disk, ks_disk):

View File

@ -38,37 +38,7 @@ from bareon.utils import md as mu
from bareon.utils import partition as pu
from bareon.utils import utils
opts = [
cfg.StrOpt(
'udev_rules_dir',
default='/etc/udev/rules.d',
help='Path where to store actual rules for udev daemon',
),
cfg.StrOpt(
'udev_rules_lib_dir',
default='/lib/udev/rules.d',
help='Path where to store default rules for udev daemon',
),
cfg.StrOpt(
'udev_rename_substr',
default='.renamedrule',
help='Substring to which file extension .rules be renamed',
),
cfg.StrOpt(
'udev_empty_rule',
default='empty_rule',
help='Correct empty rule for udev daemon',
),
cfg.IntOpt(
'grub_timeout',
default=5,
help='Timeout in secs for GRUB'
),
]
CONF = cfg.CONF
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)

View File

@ -32,95 +32,7 @@ from bareon.utils import build as bu
from bareon.utils import fs as fu
from bareon.utils import utils
opts = [
cfg.StrOpt(
'nc_template_path',
default='/usr/share/bareon/cloud-init-templates',
help='Path to directory with cloud init templates',
),
cfg.StrOpt(
'tmp_path',
default='/tmp',
help='Temporary directory for file manipulations',
),
cfg.StrOpt(
'config_drive_path',
default='/tmp/config-drive.img',
help='Path where to store generated config drive image',
),
cfg.StrOpt(
'image_build_suffix',
default='.bareon-image',
help='Suffix which is used while creating temporary files',
),
cfg.IntOpt(
'max_loop_devices_count',
default=255,
# NOTE(agordeev): up to 256 loop devices could be allocated up to
# kernel version 2.6.23, and the limit (from version 2.6.24 onwards)
# isn't theoretically present anymore.
help='Maximum allowed loop devices count to use'
),
cfg.IntOpt(
'max_allowed_attempts_attach_image',
default=10,
help='Maximum allowed attempts to attach image file to loop device'
),
cfg.IntOpt(
'sparse_file_size',
# XXX: Apparently Fuel configures the node root filesystem to span
# the whole hard drive. However 2 GB filesystem created with default
# options can grow at most to 2 TB (1024x its initial size). This
# maximal size can be configured by mke2fs -E resize=NNN option,
# however the version of e2fsprogs shipped with CentOS 6.[65] seems
# to silently ignore the `resize' option. Therefore make the initial
# filesystem a bit bigger so it can grow to 8 TB.
default=8192,
help='Size of sparse file in MiBs'
),
cfg.IntOpt(
'loop_device_major_number',
default=7,
help='System-wide major number for loop device'
),
cfg.IntOpt(
'fetch_packages_attempts',
default=10,
help='Maximum allowed debootstrap/apt-get attempts to execute'
),
cfg.StrOpt(
'allow_unsigned_file',
default='allow_unsigned_packages',
help='File where to store apt setting for unsigned packages'
),
cfg.StrOpt(
'force_ipv4_file',
default='force_ipv4',
help='File where to store apt setting for forcing IPv4 usage'
),
cfg.BoolOpt(
'prepare_configdrive',
default=True,
help='Create configdrive file, use pre-builded if set to False'
),
cfg.BoolOpt(
'fix_udev_net_rules',
default=True,
help='Add udev rules for NIC remapping'
),
cfg.StrOpt(
'default_root_password',
default='r00tme',
help='Default password for root user',
)
]
CONF = cfg.CONF
CONF.register_opts(opts)
CONF.import_opt('image_build_dir', 'bareon.cmd.agent')
CONF.import_opt('mpath_lvm_preferred_names', 'bareon.actions.bootloader')
CONF.import_opt('lvm_conf_path', 'bareon.actions.bootloader')
LOG = logging.getLogger(__name__)
@ -687,23 +599,3 @@ class Manager(BaseDeployDriver):
finally:
LOG.info('Cleanup chroot')
self.destroy_chroot(chroot)
def list_opts():
"""Returns a list of oslo.config options available in the library.
The returned list includes all oslo.config options which may be registered
at runtime by the library.
Each element of the list is a tuple. The first element is the name of the
group under which the list of elements in the second element will be
registered. A group name of None corresponds to the [DEFAULT] group in
config files.
The purpose of this is to allow tools like the Oslo sample config file
generator (oslo-config-generator) to discover the options exposed to users
by this library.
:returns: a list of (group_name, opts) tuples
"""
return [(None, (opts))]

View File

@ -22,57 +22,7 @@ from bareon.utils import artifact as au
from bareon.utils import fs as fu
from bareon.utils import utils
opts = [
cfg.StrOpt(
'image_build_suffix',
default='.bareon-image',
help='Suffix which is used while creating temporary files',
),
cfg.IntOpt(
'max_loop_devices_count',
default=255,
# NOTE(agordeev): up to 256 loop devices could be allocated up to
# kernel version 2.6.23, and the limit (from version 2.6.24 onwards)
# isn't theoretically present anymore.
help='Maximum allowed loop devices count to use'
),
cfg.IntOpt(
'sparse_file_size',
# XXX: Apparently Fuel configures the node root filesystem to span
# the whole hard drive. However 2 GB filesystem created with default
# options can grow at most to 2 TB (1024x its initial size). This
# maximal size can be configured by mke2fs -E resize=NNN option,
# however the version of e2fsprogs shipped with CentOS 6.[65] seems
# to silently ignore the `resize' option. Therefore make the initial
# filesystem a bit bigger so it can grow to 8 TB.
default=8192,
help='Size of sparse file in MiBs'
),
cfg.IntOpt(
'loop_device_major_number',
default=7,
help='System-wide major number for loop device'
),
cfg.IntOpt(
'fetch_packages_attempts',
default=10,
help='Maximum allowed debootstrap/apt-get attempts to execute'
),
cfg.StrOpt(
'allow_unsigned_file',
default='allow_unsigned_packages',
help='File where to store apt setting for unsigned packages'
),
cfg.StrOpt(
'force_ipv4_file',
default='force_ipv4',
help='File where to store apt setting for forcing IPv4 usage'
),
]
CONF = cfg.CONF
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)

View File

@ -0,0 +1,18 @@
#
# Copyright 2017 Cray Inc. All Rights Reserved.
#
# 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.
from bareon import conf
conf.register_opts()

View File

@ -26,17 +26,7 @@ from bareon import errors
from bareon.utils import utils
LOG = logging.getLogger(__name__)
au_opts = [
cfg.IntOpt(
'data_chunk_size',
default=1048576,
help='Size of data chunk to operate with images'
),
]
CONF = cfg.CONF
CONF.register_opts(au_opts)
@six.add_metaclass(abc.ABCMeta)
@ -229,23 +219,3 @@ class Chain(object):
else:
return next_proc(proc)
return six.moves.reduce(jump, self.processors)
def list_opts():
"""Returns a list of oslo.config options available in the library.
The returned list includes all oslo.config options which may be registered
at runtime by the library.
Each element of the list is a tuple. The first element is the name of the
group under which the list of elements in the second element will be
registered. A group name of None corresponds to the [DEFAULT] group in
config files.
The purpose of this is to allow tools like the Oslo sample config file
generator (oslo-config-generator) to discover the options exposed to users
by this library.
:returns: a list of (group_name, opts) tuples
"""
return [(None, (au_opts))]

View File

@ -35,51 +35,13 @@ import six
import stevedore.driver
import urllib3
from bareon import conf
from bareon import errors
random = _random.SystemRandom()
LOG = logging.getLogger(__name__)
u_opts = [
cfg.IntOpt(
'http_max_retries',
default=30,
help='Maximum retries count for http requests. 0 means infinite',
),
cfg.FloatOpt(
'http_request_timeout',
# Setting it to 10 secs will allow bareon to overcome the momentary
# peak loads when network bandwidth becomes as low as 0.1MiB/s, thus
# preventing of wasting too much retries on such false positives.
default=10.0,
help='Http request timeout in seconds',
),
cfg.FloatOpt(
'http_retry_delay',
default=2.0,
help='Delay in seconds before the next http request retry',
),
cfg.IntOpt(
'read_chunk_size',
default=1048576,
help='Block size of data to read for calculating checksum',
),
cfg.FloatOpt(
'execute_retry_delay',
default=2.0,
help='Delay in seconds before the next exectuion will retry',
),
cfg.IntOpt(
'partition_udev_settle_attempts',
default=10,
help='How many times udev settle will be called after partitioning'
),
]
CONF = cfg.CONF
CONF.register_opts(u_opts)
# NOTE(agordeev): signature compatible with execute from oslo
@ -494,7 +456,7 @@ def list_opts():
:returns: a list of (group_name, opts) tuples
"""
return [(None, (u_opts))]
return [(None, conf.default.utils_opts)]
class EqualComparisonMixin(object):

View File

@ -47,10 +47,8 @@ bareon.actions =
do_bootloader = bareon.actions.bootloader:BootLoaderAction
oslo.config.opts =
bareon.manager = bareon.manager:list_opts
bareon.agent = bareon.cmd.agent:list_opts
bareon.utils = bareon.utils.utils:list_opts
bareon.artifact= bareon.utils.artifact:list_opts
[pbr]
autodoc_index_modules = True