From e4d1af832a22a1a819ad70083133fdd9af5e789f Mon Sep 17 00:00:00 2001 From: Stefan Caraiman Date: Mon, 7 Nov 2016 16:30:04 +0200 Subject: [PATCH] Improve the get metadata logic In case the metadata service is not found, cloudbase-init will now continue on running, instead of throwing an exception, thus avoiding infinite loops caused by the 'configure_host'. Change-Id: Id7ae33817c1ec8f3a7366825ab9bcc05997477db Closes-Bug: #1643921 --- cloudbaseinit/exception.py | 7 +++++++ cloudbaseinit/init.py | 8 +++++++- cloudbaseinit/metadata/factory.py | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cloudbaseinit/exception.py b/cloudbaseinit/exception.py index 2d7f60c4..f6337eca 100644 --- a/cloudbaseinit/exception.py +++ b/cloudbaseinit/exception.py @@ -30,6 +30,13 @@ class ServiceException(Exception): pass +class MetadaNotFoundException(CloudbaseInitException): + + """Exception thrown in case no metadata service is found.""" + + pass + + class CertificateVerifyFailed(ServiceException): """The received certificate is not valid. diff --git a/cloudbaseinit/init.py b/cloudbaseinit/init.py index 7fbbbcad..6282ea7e 100644 --- a/cloudbaseinit/init.py +++ b/cloudbaseinit/init.py @@ -18,6 +18,7 @@ import sys from oslo_log import log as oslo_logging from cloudbaseinit import conf as cloudbaseinit_conf +from cloudbaseinit import exception from cloudbaseinit.metadata import factory as metadata_factory from cloudbaseinit.osutils import factory as osutils_factory from cloudbaseinit.plugins.common import base as plugins_base @@ -134,7 +135,12 @@ class InitManager(object): plugins_base.PLUGIN_STAGE_PRE_METADATA_DISCOVERY) if not (reboot_required and CONF.allow_reboot): - service = metadata_factory.get_metadata_service() + try: + service = metadata_factory.get_metadata_service() + except exception.MetadaNotFoundException: + LOG.error("No metadata service found") + service = None + if service: LOG.info('Metadata service loaded: \'%s\'' % service.get_name()) diff --git a/cloudbaseinit/metadata/factory.py b/cloudbaseinit/metadata/factory.py index 24bea30f..7923b048 100644 --- a/cloudbaseinit/metadata/factory.py +++ b/cloudbaseinit/metadata/factory.py @@ -34,4 +34,4 @@ def get_metadata_service(): except Exception as ex: LOG.error("Failed to load metadata service '%s'" % class_path) LOG.exception(ex) - raise exception.CloudbaseInitException("No available service found") + raise exception.MetadaNotFoundException("No available service found")