def tearDown(self): if not os.environ.get('MIG_CONF', False): os.environ['MIG_CONF'] = '/home/mig/mig/server/MiGserver.conf' configuration = get_configuration_object() test_vgrid = default_vgrid # Remove tmp vgrid_file_home vgrid_file_path = os.path.join(configuration.vgrid_files_home, test_vgrid) if os.path.exists(vgrid_file_path): self.assertTrue(remove_rec(vgrid_file_path, self.configuration)) self.assertFalse(os.path.exists(vgrid_file_path)) # Remove tmp mrsl_files mrsl_file_path = os.path.join(configuration.mrsl_files_dir, self.username) if os.path.exists(mrsl_file_path): self.assertTrue(remove_rec(mrsl_file_path, self.configuration)) self.assertFalse(os.path.exists(mrsl_file_path)) configuration.workflows_db_home = this_path configuration.workflows_db = \ os.path.join(this_path, 'test_sessions_db.pickle') configuration.workflows_db_lock = \ os.path.join(this_path, 'test_sessions_db.lock') self.assertTrue(delete_workflow_sessions_db(configuration)) # Also clear vgrid_dir of any patterns and recipes self.assertTrue(reset_workflows(configuration, vgrid=test_vgrid)) configuration.site_enable_workflows = False
def remove_vgrid_entry(vgrid, configuration): """Remove an entry for a VGrid in the vgrid configuration directory. configuration.vgrid_home/<vgrid> The VGrid contents (shared files and web pages) are assumed to either be abandoned entirely, or become subdirectory of another vgrid (for sub-vgrids). Wiki and SCM are deleted as well, as they would be unusable and undeletable. vgrid: the name of the VGrid to delete configuration: to determine configuration.vgrid_home Returns: Success indicator and potential messages. """ _logger = configuration.logger _logger.debug('Removing entry for vgrid %s' % vgrid) msg = '' success = remove_rec(os.path.join(configuration.vgrid_home, vgrid), configuration) if not success: _logger.debug('Error while removing %s.' % vgrid) msg += "Error while removing entry for %s." % vgrid else: for prefix in [configuration.vgrid_public_base, configuration.vgrid_private_base, configuration.vgrid_files_home]: # Gracefully delete any public, member, and owner SCMs/Trackers/... # They may already have been wiped with parent dir if they existed for collab_dir in _dot_vgrid: collab_path = os.path.join(prefix, vgrid, collab_dir) if not os.path.exists(collab_path): continue # Re-map to writable if collab_path points inside readonly dir if prefix == configuration.vgrid_files_home: (_, _, rw_path, ro_path) = \ vgrid_restrict_write_paths(vgrid, configuration) real_collab = os.path.realpath(collab_path) if real_collab.startswith(ro_path): collab_path = real_collab.replace(ro_path, rw_path) if not remove_rec(collab_path, configuration): _logger.warning('Error while removing %s.' % collab_path) collab_name = collab_dir.replace('.vgrid', '') msg += "Error while removing %s for %s" % (collab_name, vgrid) return (success, msg)
def delete_frozen_archive(freeze_id, configuration): """Delete an existing frozen archive without checking ownership or persistance of frozen archives. """ frozen_dir = os.path.join(configuration.freeze_home, freeze_id) if remove_rec(frozen_dir, configuration): return (True, '') else: return (False, 'Error deleting frozen archive "%s"' % freeze_id)
def remove_vgrid_entry(vgrid, configuration): """Remove an entry for a VGrid in the vgrid configuration directory. configuration.vgrid_home/<vgrid> The VGrid contents (shared files and web pages) are assumed to either be abandoned entirely, or become subdirectory of another vgrid (for sub-vgrids). Wiki and SCM are deleted as well, as they would be unusable and undeletable. vgrid: the name of the VGrid to delete configuration: to determine configuration.vgrid_home Returns: Success indicator and potential messages. """ configuration.logger.debug('Removing entry for %s %s' % \ (configuration.site_vgrid_label, vgrid)) msg = '' success = remove_rec(os.path.join(configuration.vgrid_home, vgrid), configuration) if not success: configuration.logger.debug('Error while removing %s.' % vgrid) msg += "Error while removing entry for %s." % vgrid else: for prefix in [configuration.vgrid_public_base, configuration.vgrid_private_base, configuration.vgrid_files_home]: # delete public, member, and owner scms/trackers # we just remove and do not check success for these if configuration.hg_path and configuration.hgweb_scripts: remove_rec(os.path.join(prefix, vgrid, '.vgridscm'), configuration) if configuration.trac_admin_path: remove_rec(os.path.join(prefix, vgrid, '.vgridtracker'), configuration) return (success, msg)
def delete_vm(client_id, configuration, machine_name): """Deletes the vm dir with configuration and images for vm with given machine_name""" # Grab the base directory of the user client_dir = client_id_dir(client_id) user_home = os.path.abspath(os.path.join(configuration.user_home, client_dir)) vms_machine_path = os.path.join(user_home, vm_base, machine_name) msg = '' success = remove_rec(vms_machine_path, configuration) if not success: msg = "Error while removing %s" % machine_name return (success, msg)
_logger.debug( 'not removing soft link to public vgrids pages for %s: %s' % (vgrid, err)) for prefix in [configuration.vgrid_public_base, configuration.vgrid_private_base, configuration.vgrid_files_home]: data_path = os.path.join(prefix, vgrid) # VGrids on flat format with readonly support has a link and a dir if os.path.islink(data_path): link_path = data_path data_path = os.path.realpath(link_path) _logger.debug('delete symlink: %s' % link_path) delete_symlink(link_path, _logger) _logger.debug('delete vgrid dir: %s' % data_path) success_here = remove_rec(data_path, configuration) if not success_here: kind = prefix.strip(os.sep).split(os.sep)[-1] msg += "Error while removing %s %s" % (vgrid, kind) success = False if msg: _logger.debug('Messages: %s.' % msg) return (success, msg) def inherit_vgrid_files(vgrid, configuration): """Transfer ownership of all files which belong to the given VGrid argument to parent VGrid. This is the default when a nested VGrid is removed. This corresponds to the functionality in createvgrid.py, but we
success = True msg = "" # removing this soft link may fail, since it is a directory for sub-VGrids try: os.remove(os.path.join(configuration.wwwpublic, 'vgrid', vgrid)) except Exception, err: configuration.logger.debug( 'not removing soft link to public %s pages for %s: %s' % \ (configuration.site_vgrid_label, vgrid, err)) for prefix in [configuration.vgrid_public_base, configuration.vgrid_private_base, configuration.vgrid_files_home]: success_here = remove_rec(os.path.join(prefix, vgrid), configuration) if not success_here: msg += "Error while removing %s." % os.path.join(prefix, vgrid) success = False configuration.logger.debug('Messages: %s.' % msg) return (success, msg) def remove_vgrid_entry(vgrid, configuration): """Remove an entry for a VGrid in the vgrid configuration directory. configuration.vgrid_home/<vgrid> The VGrid contents (shared files and web pages) are assumed to either be abandoned entirely, or become subdirectory of another vgrid (for sub-vgrids). Wiki and SCM are deleted as well, as they would be unusable
'ID': freeze_id, 'CREATED_TIMESTAMP': datetime.datetime.now(), 'CREATOR': client_id, } freeze_dict.update(freeze_meta) if freeze_meta['PUBLISH']: real_pub_dir = published_dir(freeze_dict, configuration) real_pub_index = os.path.join(real_pub_dir, public_archive_index) freeze_dict['PUBLISH_URL'] = published_url(freeze_dict, configuration) frozen_files = [] logger.info("create_frozen_archive: save meta for %s" % freeze_id) try: dump(freeze_dict, os.path.join(frozen_dir, freeze_meta_filename)) except Exception, err: logger.error("create_frozen_archive: failed: %s" % err) remove_rec(frozen_dir, configuration) return (False, 'Error writing frozen archive info: %s' % err) logger.info("create_frozen_archive: copy %s for %s" % \ (freeze_copy, freeze_id)) for (real_source, rel_dst) in freeze_copy: freeze_path = os.path.join(frozen_dir, rel_dst) frozen_files.append(rel_dst) logger.debug("create_frozen_archive: copy %s" % freeze_path) if os.path.isdir(real_source): (status, msg) = copy_rec(real_source, freeze_path, configuration) if not status: logger.error("create_frozen_archive: failed: %s" % msg) remove_rec(frozen_dir, configuration) return (False, 'Error writing frozen archive') else: