def delete_repo_group(self, group_id): """ Delete a repo group. @param group_id: unique id of the repo group to delete @type group_id: str """ collection = validate_existing_repo_group(group_id) # Delete all distributors on the group distributor_manager = manager_factory.repo_group_distributor_manager() distributors = distributor_manager.find_distributors(group_id) for distributor in distributors: distributor_manager.remove_distributor(group_id, distributor['id']) # Delete the working directory for the group working_dir = common_utils.repo_group_working_dir(group_id) if os.path.exists(working_dir): try: shutil.rmtree(working_dir) except Exception: _LOG.exception('Error while deleting working dir [%s] for repo group [%s]' % (working_dir, group_id)) raise # Delete from the database collection.remove({'id': group_id}, safe=True)
def delete_repo_group(group_id): """ Delete a repo group. @param group_id: unique id of the repo group to delete @type group_id: str """ collection = validate_existing_repo_group(group_id) # Delete all distributors on the group distributors = RepoGroupDistributorManager.find_distributors(group_id) for distributor in distributors: RepoGroupDistributorManager.remove_distributor(group_id, distributor['id']) # Delete the working directory for the group working_dir = common_utils.repo_group_working_dir(group_id) if os.path.exists(working_dir): try: shutil.rmtree(working_dir) except Exception: msg = _('Error while deleting working dir [%(d)s] for repo group [%(g)s]') msg = msg % {'d': working_dir, 'g': group_id} _logger.exception(msg) raise # Delete from the database collection.remove({'id': group_id}, safe=True)
def test_delete(self): # Setup group_id = 'delete_me' self.manager.create_repo_group(group_id) group = self.collection.find_one({'id': group_id}) self.assertFalse(group is None) # Simulate the working dir being created by a plugin working_dir = common_utils.repo_group_working_dir(group_id) if os.path.exists(working_dir): shutil.rmtree(working_dir) os.makedirs(working_dir) self.assertTrue(os.path.exists(working_dir)) # Test self.manager.delete_repo_group(group_id) # Verify group = self.collection.find_one({'id': group_id}) self.assertTrue(group is None) # Ensure the working dir was deleted self.assertTrue(not os.path.exists(working_dir))