예제 #1
0
def test_artifacts_folder_removal(monkeypatch):
    suppress_chown_during_debuild(monkeypatch)

    with workspace() as workdir:
        create_artifact_dir()
        artifacts_dir = get_artifact_dir()
        assert str(workdir) in str(artifacts_dir)
        random_dir_name = get_random_string(20)
        abs_dir_name = os.path.join(artifacts_dir, random_dir_name)
        run(['mkdir', '-p', abs_dir_name])
        assert os.path.isdir(abs_dir_name)
        safely_remove_artifacts_folder(abs_dir_name)
        assert not os.path.isdir(abs_dir_name)
예제 #2
0
    def clean(self):
        commands = self._get_commands()
        for filename, content, name, path, dictionary, raw_node, artifacts in commands:
            for _, artifact in artifacts.items():
                if not str(get_workdir()) in str(artifact):
                    raise FatalError(('Output artifact {} is not within the current working directory!'
                                      ).format(artifact))

                if os.path.isfile(artifact):
                    logging.info("Removing '{}'.".format(artifact))
                    os.remove(artifact)
                    print_success("Removed image file artifact {}.".format(artifact))
                elif os.path.isdir(artifact):
                    safely_remove_artifacts_folder(artifact, sudo=raw_node.get('require_root', False))
                    print_success("Removed image directory artifact {}.".format(artifact))
예제 #3
0
def test_artifacts_folder_removal_as_sudo():
    with workspace() as workdir:
        create_artifact_dir()
        artifacts_dir = get_artifact_dir()
        assert str(workdir) in str(artifacts_dir)
        random_dir_name = get_random_string(20)
        abs_dir_name = os.path.join(artifacts_dir, random_dir_name)
        mount_folder = os.path.join(workdir, get_random_string(20))
        mount_point = os.path.join(abs_dir_name, 'mnt')

        for folder in [abs_dir_name, mount_folder, mount_point]:
            run(['mkdir', '-p', folder])
            assert os.path.isdir(folder)

        run(['mount', '--bind', mount_folder, mount_point], sudo=True)

        with pytest.raises(FatalError) as error:
            safely_remove_artifacts_folder(abs_dir_name, sudo=True)
        assert abs_dir_name in error.value.message

        run(['umount', mount_point], sudo=True)
        safely_remove_artifacts_folder(abs_dir_name, sudo=True)

        assert not os.path.isdir(abs_dir_name)