diff --git a/README.rst b/README.rst index 7f49cc492..220c258b7 100644 --- a/README.rst +++ b/README.rst @@ -171,6 +171,7 @@ v0.2.2 * ``/v1/discover`` now does some sync checks (`bug #3`_). * Actually able to start under Python 3.3. +* On each start-up make several attempts to check that Ironic is available. .. _bug #3: https://github.com/Divius/ironic-discoverd/issues/3 diff --git a/example.conf b/example.conf index 12098cd1a..9bff79ff3 100644 --- a/example.conf +++ b/example.conf @@ -10,6 +10,11 @@ ; Tenant name for accessing Ironic API. ;os_tenant_name = +; Number of attempts to do when trying to connect to Ironic on start up. +;ironic_retry_attempts = 5 +; Amount of time between attempts to connect to Ironic on start up. +;ironic_retry_period = 5 + ; Interface on which dnsmasq listens, the default is for VM's. ;dnsmasq_interface = br-ctlplane ; Amount of time in seconds, after which repeat periodic update of firewall. diff --git a/ironic_discoverd/discoverd.py b/ironic_discoverd/discoverd.py index 8a319fd7a..ba6c74050 100644 --- a/ironic_discoverd/discoverd.py +++ b/ironic_discoverd/discoverd.py @@ -25,7 +25,9 @@ def init_conf(): 'dnsmasq_interface': 'br-ctlplane', 'authenticate': 'true', 'firewall_update_period': '15', - 'ports_for_inactive_interfaces': 'false'}) + 'ports_for_inactive_interfaces': 'false', + 'ironic_retry_attempts': '5', + 'ironic_retry_period': '5'}) CONF = None diff --git a/ironic_discoverd/main.py b/ironic_discoverd/main.py index 2ade259ed..3fa3bd71e 100644 --- a/ironic_discoverd/main.py +++ b/ironic_discoverd/main.py @@ -74,6 +74,27 @@ def main(): interface = discoverd.CONF.get('discoverd', 'dnsmasq_interface') firewall.init(interface) + + # Before proceeding we try to make sure: + # 1. Keystone access is configured properly + # 2. Keystone has already started + # 3. Ironic has already started + attempts = discoverd.CONF.getint('discoverd', 'ironic_retry_attempts') + assert attempts >= 0 + retry_period = discoverd.CONF.getint('discoverd', 'ironic_retry_period') + LOG.debug('Trying to connect to Ironic') + for i in range(attempts + 1): # one attempt always required + try: + discoverd.get_client().driver.list() + except Exception as exc: + if i == attempts: + raise + LOG.error('Unable to connect to Ironic or Keystone, retrying %d ' + 'times more: %s', attempts - i, exc) + else: + break + eventlet.greenthread.sleep(retry_period) + period = discoverd.CONF.getint('discoverd', 'firewall_update_period') eventlet.greenthread.spawn_n(periodic_update, period)