Consolidate IPA configuration into a config module

This patch moves the IPA oslo configs out of the agent cmd into their
own module so that it is safe to import them from other places in the
application without causing circular imports.

Change-Id: I100792bd0d1f369763afaa6f93e144e9967c3048
This commit is contained in:
Sam Betts 2016-05-25 10:38:45 +01:00
parent 01d49886ac
commit 95e1e4e35a
4 changed files with 138 additions and 122 deletions

View File

@ -19,132 +19,17 @@ from oslo_log import log
from oslo_utils import strutils
from ironic_python_agent import agent
from ironic_python_agent import inspector
from ironic_python_agent import utils
from ironic_python_agent import config
CONF = cfg.CONF
APARAMS = utils.get_agent_params()
cli_opts = [
cfg.StrOpt('api_url',
default=APARAMS.get('ipa-api-url', 'http://127.0.0.1:6385'),
deprecated_name='api-url',
help='URL of the Ironic API'),
cfg.StrOpt('listen_host',
default=APARAMS.get('ipa-listen-host', '0.0.0.0'),
deprecated_name='listen-host',
help='The IP address to listen on.'),
cfg.IntOpt('listen_port',
default=int(APARAMS.get('ipa-listen-port', 9999)),
deprecated_name='listen-port',
help='The port to listen on'),
cfg.StrOpt('advertise_host',
default=APARAMS.get('ipa-advertise-host', None),
deprecated_name='advertise_host',
help='The host to tell Ironic to reply and send '
'commands to.'),
cfg.IntOpt('advertise_port',
default=int(APARAMS.get('ipa-advertise-port', 9999)),
deprecated_name='advertise-port',
help='The port to tell Ironic to reply and send '
'commands to.'),
cfg.IntOpt('ip_lookup_attempts',
default=int(APARAMS.get('ipa-ip-lookup-attempts', 3)),
deprecated_name='ip-lookup-attempts',
help='The number of times to try and automatically'
'determine the agent IPv4 address.'),
cfg.IntOpt('ip_lookup_sleep',
default=int(APARAMS.get('ipa-ip-lookup-timeout', 10)),
deprecated_name='ip-lookup-sleep',
help='The amaount of time to sleep between attempts'
'to determine IP address.'),
cfg.StrOpt('network_interface',
default=APARAMS.get('ipa-network-interface', None),
deprecated_name='network-interface',
help='The interface to use when looking for an IP'
'address.'),
cfg.IntOpt('lookup_timeout',
default=int(APARAMS.get('ipa-lookup-timeout', 300)),
deprecated_name='lookup-timeout',
help='The amount of time to retry the initial lookup '
'call to Ironic. After the timeout, the agent '
'will exit with a non-zero exit code.'),
cfg.IntOpt('lookup_interval',
default=int(APARAMS.get('ipa-lookup-timeout', 1)),
deprecated_name='lookup-interval',
help='The initial interval for retries on the initial '
'lookup call to Ironic. The interval will be '
'doubled after each failure until timeout is '
'exceeded.'),
cfg.StrOpt('driver_name',
default=APARAMS.get('ipa-driver-name', 'agent_ipmitool'),
deprecated_name='driver-name',
help='The Ironic driver in use for this node'),
cfg.FloatOpt('lldp_timeout',
default=APARAMS.get('lldp-timeout', 30.0),
help='The amount of seconds to wait for LLDP packets.'),
cfg.BoolOpt('standalone',
default=APARAMS.get('ipa-standalone', False),
help='Note: for debugging only. Start the Agent but suppress '
'any calls to Ironic API.'),
cfg.StrOpt('inspection_callback_url',
default=APARAMS.get('ipa-inspection-callback-url'),
help='Endpoint of ironic-inspector. If set, hardware inventory '
'will be collected and sent to ironic-inspector '
'on start up.'),
cfg.StrOpt('inspection_collectors',
default=APARAMS.get('ipa-inspection-collectors',
inspector.DEFAULT_COLLECTOR),
help='Comma-separated list of plugins providing additional '
'hardware data for inspection, empty value gives '
'a minimum required set of plugins.'),
cfg.IntOpt('inspection_dhcp_wait_timeout',
default=APARAMS.get('ipa-inspection-dhcp-wait-timeout',
inspector.DEFAULT_DHCP_WAIT_TIMEOUT),
help='Maximum time (in seconds) to wait for the PXE NIC '
'(or all NICs if inspection_dhcp_all_interfaces is True) '
'to get its IP address via DHCP before inspection. '
'Set to 0 to disable waiting completely.'),
cfg.BoolOpt('inspection_dhcp_all_interfaces',
default=APARAMS.get('ipa-inspection-dhcp-all-interfaces',
False),
help='Whether to wait for all interfaces to get their IP '
'addresses before inspection. If set to false '
'(the default), only waits for the PXE interface.'),
cfg.IntOpt('hardware_initialization_delay',
default=APARAMS.get('ipa-hardware-initialization-delay', 0),
help='How much time (in seconds) to wait for hardware to '
'initialize before proceeding with any actions.'),
]
CONF.register_cli_opts(cli_opts)
def run():
"""Entrypoint for IronicPythonAgent."""
log.register_options(CONF)
CONF(args=sys.argv[1:])
# Debug option comes from oslo.log, allow overriding it via kernel cmdline
ipa_debug = APARAMS.get('ipa-debug')
ipa_debug = config.APARAMS.get('ipa-debug')
if ipa_debug is not None:
ipa_debug = strutils.bool_from_string(ipa_debug)
CONF.set_override('debug', ipa_debug)

View File

@ -0,0 +1,133 @@
# Copyright 2016 Cisco Systems, Inc.
#
# 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 ironic_python_agent import inspector
from ironic_python_agent import utils
CONF = cfg.CONF
APARAMS = utils.get_agent_params()
cli_opts = [
cfg.StrOpt('api_url',
default=APARAMS.get('ipa-api-url', 'http://127.0.0.1:6385'),
deprecated_name='api-url',
help='URL of the Ironic API'),
cfg.StrOpt('listen_host',
default=APARAMS.get('ipa-listen-host', '0.0.0.0'),
deprecated_name='listen-host',
help='The IP address to listen on.'),
cfg.IntOpt('listen_port',
default=int(APARAMS.get('ipa-listen-port', 9999)),
deprecated_name='listen-port',
help='The port to listen on'),
cfg.StrOpt('advertise_host',
default=APARAMS.get('ipa-advertise-host', None),
deprecated_name='advertise_host',
help='The host to tell Ironic to reply and send '
'commands to.'),
cfg.IntOpt('advertise_port',
default=int(APARAMS.get('ipa-advertise-port', 9999)),
deprecated_name='advertise-port',
help='The port to tell Ironic to reply and send '
'commands to.'),
cfg.IntOpt('ip_lookup_attempts',
default=int(APARAMS.get('ipa-ip-lookup-attempts', 3)),
deprecated_name='ip-lookup-attempts',
help='The number of times to try and automatically'
'determine the agent IPv4 address.'),
cfg.IntOpt('ip_lookup_sleep',
default=int(APARAMS.get('ipa-ip-lookup-timeout', 10)),
deprecated_name='ip-lookup-sleep',
help='The amaount of time to sleep between attempts'
'to determine IP address.'),
cfg.StrOpt('network_interface',
default=APARAMS.get('ipa-network-interface', None),
deprecated_name='network-interface',
help='The interface to use when looking for an IP'
'address.'),
cfg.IntOpt('lookup_timeout',
default=int(APARAMS.get('ipa-lookup-timeout', 300)),
deprecated_name='lookup-timeout',
help='The amount of time to retry the initial lookup '
'call to Ironic. After the timeout, the agent '
'will exit with a non-zero exit code.'),
cfg.IntOpt('lookup_interval',
default=int(APARAMS.get('ipa-lookup-timeout', 1)),
deprecated_name='lookup-interval',
help='The initial interval for retries on the initial '
'lookup call to Ironic. The interval will be '
'doubled after each failure until timeout is '
'exceeded.'),
cfg.StrOpt('driver_name',
default=APARAMS.get('ipa-driver-name', 'agent_ipmitool'),
deprecated_name='driver-name',
help='The Ironic driver in use for this node'),
cfg.FloatOpt('lldp_timeout',
default=APARAMS.get('lldp-timeout', 30.0),
help='The amount of seconds to wait for LLDP packets.'),
cfg.BoolOpt('standalone',
default=APARAMS.get('ipa-standalone', False),
help='Note: for debugging only. Start the Agent but suppress '
'any calls to Ironic API.'),
cfg.StrOpt('inspection_callback_url',
default=APARAMS.get('ipa-inspection-callback-url'),
help='Endpoint of ironic-inspector. If set, hardware inventory '
'will be collected and sent to ironic-inspector '
'on start up.'),
cfg.StrOpt('inspection_collectors',
default=APARAMS.get('ipa-inspection-collectors',
inspector.DEFAULT_COLLECTOR),
help='Comma-separated list of plugins providing additional '
'hardware data for inspection, empty value gives '
'a minimum required set of plugins.'),
cfg.IntOpt('inspection_dhcp_wait_timeout',
default=APARAMS.get('ipa-inspection-dhcp-wait-timeout',
inspector.DEFAULT_DHCP_WAIT_TIMEOUT),
help='Maximum time (in seconds) to wait for the PXE NIC '
'(or all NICs if inspection_dhcp_all_interfaces is True) '
'to get its IP address via DHCP before inspection. '
'Set to 0 to disable waiting completely.'),
cfg.BoolOpt('inspection_dhcp_all_interfaces',
default=APARAMS.get('ipa-inspection-dhcp-all-interfaces',
False),
help='Whether to wait for all interfaces to get their IP '
'addresses before inspection. If set to false '
'(the default), only waits for the PXE interface.'),
cfg.IntOpt('hardware_initialization_delay',
default=APARAMS.get('ipa-hardware-initialization-delay', 0),
help='How much time (in seconds) to wait for hardware to '
'initialize before proceeding with any actions.'),
]
CONF.register_cli_opts(cli_opts)

View File

@ -22,11 +22,6 @@ import sys
from oslo_config import cfg
from oslo_log import log as logging
# FIXME(lucasagomes): If you don't import the agent module the tests in
# this file will fail, it was working before because the agent module was
# being imported at tests/agent.py
from ironic_python_agent.cmd import agent # noqa
LOG = logging.getLogger(__name__)
CONF = cfg.CONF

View File

@ -15,6 +15,7 @@
import binascii
import mock
from oslo_config import cfg
from oslotest import base as test_base
from ironic_python_agent import netutils
@ -28,6 +29,8 @@ FAKE_LLDP_PACKET = binascii.unhexlify(
'06020078'
)
cfg.CONF.import_opt('lldp_timeout', 'ironic_python_agent.config')
class TestNetutils(test_base.BaseTestCase):
def setUp(self):