Fail ironic startup if no protocol prefix in ironic api address

Add regex validation of api_url specified in configuration file.
Oslo config will raise exception if no supported protocol prefix
is included in Ironic api address in configuration file.
Supported protocols are http and https.
Regenerated the config file.

Change-Id: Iabe576134d804211d7f552bfd5a76c404524ffef
Closes-Bug: #1630785
This commit is contained in:
Joanna Taryma 2016-11-30 15:27:43 -06:00
parent b7f001f441
commit 30a4340175
4 changed files with 22 additions and 6 deletions

View File

@ -712,7 +712,8 @@
#heartbeat_interval = 10 #heartbeat_interval = 10
# URL of Ironic API service. If not set ironic can get the # URL of Ironic API service. If not set ironic can get the
# current value from the keystone service catalog. (string # current value from the keystone service catalog. If set, the
# value must start with either http:// or https://. (string
# value) # value)
#api_url = <None> #api_url = <None>
@ -2300,6 +2301,11 @@
# Minimum value: 5 # Minimum value: 5
#default_notify_timeout = 30 #default_notify_timeout = 30
# The duration to schedule a purge of idle sender links.
# Detach link after expiry. (integer value)
# Minimum value: 1
#default_sender_link_timeout = 600
# Indicates the addressing mode used by the driver. # Indicates the addressing mode used by the driver.
# Permitted values: # Permitted values:
# 'legacy' - use legacy non-routable addressing # 'legacy' - use legacy non-routable addressing

View File

@ -29,9 +29,11 @@ opts = [
default=10, default=10,
help=_('Seconds between conductor heart beats.')), help=_('Seconds between conductor heart beats.')),
cfg.StrOpt('api_url', cfg.StrOpt('api_url',
regex='^http(s?):\/\/.+',
help=_('URL of Ironic API service. If not set ironic can ' help=_('URL of Ironic API service. If not set ironic can '
'get the current value from the keystone service ' 'get the current value from the keystone service '
'catalog.')), 'catalog. If set, the value must start with either '
'http:// or https://.')),
cfg.IntOpt('heartbeat_timeout', cfg.IntOpt('heartbeat_timeout',
default=60, default=60,
help=_('Maximum time (in seconds) since the last check-in ' help=_('Maximum time (in seconds) since the last check-in '

View File

@ -1588,19 +1588,19 @@ class AgentMethodsTestCase(db_base.DbTestCase):
self._test_tear_down_inband_cleaning(manage_boot=False) self._test_tear_down_inband_cleaning(manage_boot=False)
def test_build_agent_options_conf(self): def test_build_agent_options_conf(self):
self.config(api_url='api-url', group='conductor') self.config(api_url='https://api-url', group='conductor')
options = utils.build_agent_options(self.node) options = utils.build_agent_options(self.node)
self.assertEqual('api-url', options['ipa-api-url']) self.assertEqual('https://api-url', options['ipa-api-url'])
self.assertEqual(0, options['coreos.configdrive']) self.assertEqual(0, options['coreos.configdrive'])
@mock.patch.object(utils, '_get_ironic_session') @mock.patch.object(utils, '_get_ironic_session')
def test_build_agent_options_keystone(self, session_mock): def test_build_agent_options_keystone(self, session_mock):
self.config(api_url=None, group='conductor') self.config(api_url=None, group='conductor')
sess = mock.Mock() sess = mock.Mock()
sess.get_endpoint.return_value = 'api-url' sess.get_endpoint.return_value = 'https://api-url'
session_mock.return_value = sess session_mock.return_value = sess
options = utils.build_agent_options(self.node) options = utils.build_agent_options(self.node)
self.assertEqual('api-url', options['ipa-api-url']) self.assertEqual('https://api-url', options['ipa-api-url'])
self.assertEqual(0, options['coreos.configdrive']) self.assertEqual(0, options['coreos.configdrive'])

View File

@ -0,0 +1,8 @@
---
fixes:
- Accepting ``[conductor]/api_url`` value specified in the configuration
file that does not start with either ``https://`` or ``http://``.
Such value leads to deployment failure on ironic-python-agent side.
This misconfiguration will be detected during ironic-conductor
and ironic-api start. An exception will be raised and an error about
the invalid value will be logged.