Make failures of image-builder more human-friendly
Change-Id: I34fd36220b9be3fee0cd08901599ce3f5bdc2116
This commit is contained in:
@@ -34,10 +34,18 @@ def init():
|
||||
utils.init_config_and_logging(
|
||||
config.OPENSTACK_OPTS + config.IMAGE_BUILDER_OPTS)
|
||||
|
||||
openstack_client = openstack.OpenStackClient(
|
||||
username=cfg.CONF.os_username, password=cfg.CONF.os_password,
|
||||
tenant_name=cfg.CONF.os_tenant_name, auth_url=cfg.CONF.os_auth_url,
|
||||
region_name=cfg.CONF.os_region_name)
|
||||
openstack_client = None
|
||||
try:
|
||||
openstack_client = openstack.OpenStackClient(
|
||||
username=cfg.CONF.os_username, password=cfg.CONF.os_password,
|
||||
tenant_name=cfg.CONF.os_tenant_name, auth_url=cfg.CONF.os_auth_url,
|
||||
region_name=cfg.CONF.os_region_name)
|
||||
except Exception as e:
|
||||
LOG.error('Error establishing connection to OpenStack: %s. '
|
||||
'Please verify OpenStack credentials (--os-username, '
|
||||
'--os-password, --os-tenant-name, --os-auth-url)', e)
|
||||
exit(1)
|
||||
|
||||
return openstack_client
|
||||
|
||||
|
||||
@@ -56,13 +64,23 @@ def build_image():
|
||||
if glance.get_image(openstack_client.glance, image_name):
|
||||
LOG.info('Using existing image: %s', image_name)
|
||||
else:
|
||||
template = None
|
||||
template_filename = cfg.CONF.image_builder_template
|
||||
try:
|
||||
template = utils.read_file(template_filename)
|
||||
except IOError:
|
||||
LOG.error('Error reading template file: %s. '
|
||||
'Please verify correctness of --image-builder-template '
|
||||
'parameter', template_filename)
|
||||
exit(1)
|
||||
|
||||
external_net = (cfg.CONF.external_net or
|
||||
neutron.choose_external_net(openstack_client.neutron))
|
||||
stack_params = {
|
||||
'stack_name': 'shaker_%s' % uuid.uuid4(),
|
||||
'parameters': {'external_net': external_net,
|
||||
'flavor': flavor_name},
|
||||
'template': utils.read_file(cfg.CONF.image_builder_template),
|
||||
'template': template,
|
||||
}
|
||||
|
||||
stack = openstack_client.heat.stacks.create(**stack_params)['stack']
|
||||
|
||||
@@ -70,6 +70,16 @@ def init_config_and_logging(opts):
|
||||
|
||||
def read_file(file_name, base_dir=''):
|
||||
full_path = os.path.normpath(os.path.join(base_dir, file_name))
|
||||
if not os.path.exists(full_path):
|
||||
# treat file_name as relative to shaker's package root
|
||||
full_path = os.path.normpath(os.path.join(
|
||||
os.path.dirname(__import__('shaker').__file__), '../', file_name))
|
||||
if not os.path.exists(full_path):
|
||||
msg = ('File %s not found by absolute nor by relative path' %
|
||||
file_name)
|
||||
LOG.error(msg)
|
||||
raise IOError(msg)
|
||||
|
||||
fd = None
|
||||
try:
|
||||
fd = open(full_path)
|
||||
|
||||
Reference in New Issue
Block a user