Skip to content

Commit

Permalink
Fixes EUCA-12499
Browse files Browse the repository at this point in the history
Update failure handling for conf file values to return None if not present
  • Loading branch information
Jeremy Breiding committed Jun 24, 2016
1 parent e1cc2d7 commit 95f3deb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
23 changes: 14 additions & 9 deletions tools/nodeadmin-pack-instance
Expand Up @@ -60,8 +60,7 @@ _LIBVIRT_XML = 'instance-libvirt.xml'
_INSTANCE_XML = 'instance.xml'
_DISCONNECT_ISCSI_PL = '/usr/share/eucalyptus/disconnect_iscsitarget.pl'
_NCHOOK_PATH = '/etc/eucalyptus/nc-hooks/stop-delete.sh'
_STOP_DELETE = r'''
#!/bin/bash
_STOP_DELETE = r'''#!/bin/bash
event=$1
if [ "$event" == "euca-nc-pre-clean" ] ; then
Expand Down Expand Up @@ -153,6 +152,15 @@ def _parse_eucalyptus_conf():
return parser


def _get_conf_value(variable_name):
euca_conf = _parse_eucalyptus_conf()

try:
return euca_conf.get(_GLOBAL_SECTION, variable_name).strip('"')
except:
return None


def _list_instances():
logging.debug("attempting to open %s", _QEMU_CONN)
conn = libvirt.open(_QEMU_CONN)
Expand Down Expand Up @@ -286,15 +294,11 @@ def _create_tar(files, pack_path, skip_compression):


def _get_eucalyptus_home_path():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, _EUCALYPTUS).strip('"')
return _get_conf_value(_EUCALYPTUS)


def _get_instances_path():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, _INSTANCE_PATH).strip('"')
return _get_conf_value(_INSTANCE_PATH)


def _detach_iscsi_target(volume_id, volume_dev_name, volume_serial, volume_bus, connection_string):
Expand Down Expand Up @@ -365,7 +369,8 @@ def _gather_files(instance_name, instance_path):
dir_name = os.path.splitext(os.path.basename(block_file))[0]

if not os.path.exists(os.path.join(instance_path, "%s.dm" % dir_name)):
logging.debug("Skipping %s as there is no associated .dm file", block_file)
logging.debug(
"Skipping %s as there is no associated .dm file", block_file)
continue

with open(os.path.join(instance_path, "%s.dm" % dir_name)) as dm_file:
Expand Down
25 changes: 13 additions & 12 deletions tools/nodeadmin-unpack-instance
Expand Up @@ -125,6 +125,15 @@ def _parse_eucalyptus_conf():
return parser


def _get_conf_value(variable_name):
euca_conf = _parse_eucalyptus_conf()

try:
return euca_conf.get(_GLOBAL_SECTION, variable_name).strip('"')
except:
return None


def _find_instance(packed_path):
tar_cmd = ["/bin/tar", "-xzOf", packed_path,
"--wildcards", "*/instance.xml"]
Expand Down Expand Up @@ -188,27 +197,19 @@ def _extract_files(packed_path):


def _get_eucalyptus_home_path():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, _EUCALYPTUS).strip('"')
return _get_conf_value(_EUCALYPTUS)


def _get_ceph_user_name():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, "CEPH_USER_NAME").strip('"')
return _get_conf_value("CEPH_USER_NAME")


def _get_ceph_keyring_path():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, "CEPH_KEYRING_PATH").strip('"')
return _get_conf_value("CEPH_KEYRING_PATH")


def _get_ceph_config_path():
euca_conf = _parse_eucalyptus_conf()

return euca_conf.get(_GLOBAL_SECTION, "CEPH_CONFIG_PATH").strip('"')
return _get_conf_value("CEPH_CONFIG_PATH")


def _attach_iscsi_target(volume_id, volume_dev_name, volume_serial, volume_bus, connection_string):
Expand Down

0 comments on commit 95f3deb

Please sign in to comment.