def umount_task(driverCls, provider, identity, instance_id, volume_id, *args, **kwargs): try: celery_logger.debug("umount_task started at %s." % datetime.now()) driver = get_driver(driverCls, provider, identity) instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) attach_data = volume.extra["attachments"][0] device = attach_data["device"] # Check mount to find the mount_location for device private_key = "/opt/dev/atmosphere/extras/ssh/id_rsa" kwargs.update({"ssh_key": private_key}) kwargs.update({"timeout": 120}) mount_location = None cm_script = check_mount() kwargs.update({"deploy": cm_script}) driver.deploy_to(instance, **kwargs) regex = re.compile("(?P<device>[\w/]+) on (?P<location>.*) type") for line in cm_script.stdout.split("\n"): res = regex.search(line) if not res: continue search_dict = res.groupdict() dev_found = search_dict["device"] if device == dev_found: mount_location = search_dict["location"] break # Volume not mounted, move along.. if not mount_location: return um_script = umount_volume(device) kwargs.update({"deploy": um_script}) driver.deploy_to(instance, **kwargs) if "device is busy" in um_script.stdout: # Show all processes that are making device busy.. lsof_script = lsof_location(mount_location) kwargs.update({"deploy": lsof_script}) driver.deploy_to(instance, **kwargs) regex = re.compile("(?P<name>[\w]+)\s*(?P<pid>[\d]+)") offending_processes = [] for line in lsof_script.stdout.split("\n"): res = regex.search(line) if not res: continue search_dict = res.groupdict() offending_processes.append((search_dict["name"], search_dict["pid"])) raise DeviceBusyException(mount_location, offending_processes) # Return here if no errors occurred.. celery_logger.debug("umount_task finished at %s." % datetime.now()) except DeviceBusyException: raise except Exception as exc: celery_logger.warn(exc) umount_task.retry(exc=exc)
def umount_task(driverCls, provider, identity, instance_id, volume_id, *args, **kwargs): try: celery_logger.debug("umount_task started at %s." % datetime.now()) driver = get_driver(driverCls, provider, identity) instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) attach_data = volume.extra['attachments'][0] device = attach_data['device'] # Check mount to find the mount_location for device private_key = "/opt/dev/atmosphere/extras/ssh/id_rsa" kwargs.update({'ssh_key': private_key}) kwargs.update({'timeout': 120}) mount_location = None cm_script = check_mount() kwargs.update({'deploy': cm_script}) driver.deploy_to(instance, **kwargs) regex = re.compile("(?P<device>[\w/]+) on (?P<location>.*) type") for line in cm_script.stdout.split('\n'): res = regex.search(line) if not res: continue search_dict = res.groupdict() dev_found = search_dict['device'] if device == dev_found: mount_location = search_dict['location'] break # Volume not mounted, move along.. if not mount_location: return um_script = umount_volume(device) kwargs.update({'deploy': um_script}) driver.deploy_to(instance, **kwargs) if 'device is busy' in um_script.stdout: # Show all processes that are making device busy.. lsof_script = lsof_location(mount_location) kwargs.update({'deploy': lsof_script}) driver.deploy_to(instance, **kwargs) regex = re.compile("(?P<name>[\w]+)\s*(?P<pid>[\d]+)") offending_processes = [] for line in lsof_script.stdout.split('\n'): res = regex.search(line) if not res: continue search_dict = res.groupdict() offending_processes.append( (search_dict['name'], search_dict['pid'])) raise DeviceBusyException(mount_location, offending_processes) # Return here if no errors occurred.. celery_logger.debug("umount_task finished at %s." % datetime.now()) except DeviceBusyException: raise except Exception as exc: celery_logger.warn(exc) umount_task.retry(exc=exc)