Port from nova: Fix local variable 'root_uuid' ref

Port I0221984ce4f7c406990315ef820d9ce63fc6e015 from Nova.

Fixes an issue where the root_uuid variable gets used
before it is assigned.

Instead of generating NameError, log a more descriptive error
and allow the exception to be raised.

Fixes LP Bug #1190269.

Change-Id: Icecac7443d296546734f7a13995530a7991b9f04
This commit is contained in:
Devananda van der Veen 2013-06-20 13:42:12 -07:00
parent d63882812d
commit fb17b2cadd
1 changed files with 13 additions and 6 deletions

View File

@ -36,6 +36,7 @@ from ironic.common import exception
from ironic.common import states
from ironic.common import utils
from ironic import db
from ironic.openstack.common import excutils
from ironic.openstack.common import log as logging
@ -187,7 +188,12 @@ def work_on_disk(dev, root_mb, swap_mb, image_path):
return
dd(image_path, root_part)
mkswap(swap_part)
root_uuid = block_uuid(root_part)
try:
root_uuid = block_uuid(root_part)
except exception.ProcessExecutionError:
with excutils.save_and_reraise_exception():
LOG.error("Failed to detect root device UUID.")
return root_uuid
@ -202,11 +208,12 @@ def deploy(address, port, iqn, lun, image_path, pxe_config_path,
login_iscsi(address, port, iqn)
try:
root_uuid = work_on_disk(dev, root_mb, swap_mb, image_path)
except exception.ProcessExecutionError as err:
# Log output if there was a error
LOG.error("Cmd : %s" % err.cmd)
LOG.error("StdOut : %s" % err.stdout)
LOG.error("StdErr : %s" % err.stderr)
except exception.ProcessExecutionError, err:
with excutils.save_and_reraise_exception():
# Log output if there was a error
LOG.error("Cmd : %s" % err.cmd)
LOG.error("StdOut : %s" % err.stdout)
LOG.error("StdErr : %s" % err.stderr)
finally:
logout_iscsi(address, port, iqn)
switch_pxe_config(pxe_config_path, root_uuid)