Fixes return values and exceptions in some plugins

This avoids misleading exceptions in the logs.
This commit is contained in:
Alessandro Pilotti 2013-05-01 15:35:56 +03:00
parent 4b08f9ef93
commit 3e120de02a
4 changed files with 13 additions and 7 deletions

View File

@ -37,10 +37,11 @@ class NetworkConfigPlugin(base.BasePlugin):
def execute(self, service):
meta_data = service.get_meta_data('openstack')
if 'network_config' not in meta_data:
return False
return (base.PLUGIN_EXECUTION_DONE, False)
network_config = meta_data['network_config']
if 'content_path' not in network_config:
return False
return (base.PLUGIN_EXECUTION_DONE, False)
content_path = network_config['content_path']
content_name = content_path.rsplit('/', 1)[-1]

View File

@ -26,7 +26,7 @@ class SetHostNamePlugin(base.BasePlugin):
meta_data = service.get_meta_data('openstack')
if 'hostname' not in meta_data:
LOG.debug('Hostname not found in metadata')
return False
return (base.PLUGIN_EXECUTION_DONE, False)
osutils = osutils_factory.OSUtilsFactory().get_os_utils()

View File

@ -29,7 +29,7 @@ class SetUserSSHPublicKeysPlugin(base.BasePlugin):
def execute(self, service):
meta_data = service.get_meta_data('openstack')
if not 'public_keys' in meta_data:
return False
return (base.PLUGIN_EXECUTION_DONE, False)
username = CONF.username

View File

@ -19,6 +19,7 @@ import re
import tempfile
import uuid
from cloudbaseinit.metadata.services import base as metadata_services_base
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.osutils import factory as osutils_factory
from cloudbaseinit.plugins import base
@ -28,9 +29,13 @@ LOG = logging.getLogger(__name__)
class UserDataPlugin(base.BasePlugin):
def execute(self, service):
user_data = service.get_user_data('openstack')
try:
user_data = service.get_user_data('openstack')
except metadata_services_base.NotExistingMetadataException:
return (base.PLUGIN_EXECUTION_DONE, False)
if not user_data:
return False
return (base.PLUGIN_EXECUTION_DONE, False)
LOG.debug('User data content:\n%s' % user_data)
@ -53,7 +58,7 @@ class UserDataPlugin(base.BasePlugin):
else:
# Unsupported
LOG.warning('Unsupported user_data format')
return False
return (base.PLUGIN_EXECUTION_DONE, False)
try:
with open(target_path, 'wb') as f: