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
This commit is contained in:
Stefan Caraiman 2016-11-07 16:30:04 +02:00
parent 4895b36344
commit e4d1af832a
3 changed files with 15 additions and 2 deletions

View File

@ -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.

View File

@ -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())

View File

@ -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")