Exemple #1
0
    def test_demoted_call_no(self):
        """Test running with different UID/GID"""
        eq_(fork_call(self._name, self._group, self._dummy_ok)(), 'ok')
        eq_(fork_call(self._uid, None, self._dummy_ok)(), 'ok')
        eq_(fork_call(None, self._gid, self._dummy_ok)(), 'ok')

        eq_(self._no_fork_call(self._uid, self._gid, self._dummy_ok)(), 'ok')
    def test_demoted_call_no(self):
        """Test running with different UID/GID"""
        eq_(fork_call(self._name, self._group, self._dummy_ok)(), 'ok')
        eq_(fork_call(self._uid, None, self._dummy_ok)(), 'ok')
        eq_(fork_call(None, self._gid, self._dummy_ok)(), 'ok')

        eq_(self._no_fork_call(self._uid, self._gid, self._dummy_ok)(), 'ok')
    def test_success(self):
        """Basic test for successful call"""
        eq_(fork_call(None, None, self._dummy_ok)(), 'ok')

        eq_(fork_call(None, None, self._dummy_args)(1, '2', arg3='foo'),
            (1, '2', 'foo'))

        ok_(os.getpid() != fork_call(None, None, os.getpid)())
Exemple #4
0
    def test_fail(self):
        """Tests for function call failures"""
        with assert_raises(GbpChildBTError) as exc:
            fork_call(None, None, self._dummy_raise)()
        eq_(exc.exception.typ, _DummyException)

        with assert_raises(GbpChildBTError) as exc:
            fork_call(None, None, self._dummy_ok)('unexptected_arg')
        eq_(exc.exception.typ, TypeError)
Exemple #5
0
    def test_success(self):
        """Basic test for successful call"""
        eq_(fork_call(None, None, self._dummy_ok)(), 'ok')

        eq_(
            fork_call(None, None, self._dummy_args)(1, '2', arg3='foo'),
            (1, '2', 'foo'))

        ok_(os.getpid() != fork_call(None, None, os.getpid)())
    def test_fail(self):
        """Tests for function call failures"""
        with assert_raises(GbpChildBTError) as exc:
            fork_call(None, None, self._dummy_raise)()
        eq_(exc.exception.typ, _DummyException)

        with assert_raises(GbpChildBTError) as exc:
            fork_call(None, None, self._dummy_ok)('unexptected_arg')
        eq_(exc.exception.typ, TypeError)
def gbp_export(repo, args, config):
    """Export sources with GBP"""
    # Create output directories
    try:
        if not os.path.exists(args.outdir):
            os.makedirs(args.outdir)
        tmp_out = tempfile.mkdtemp(dir=args.outdir)
    except OSError as err:
        raise ExportError('Failed to create output directory: %s' % err,
                          EXIT_ERR_SERVICE)
    # Determine UID/GID
    try:
        uid, gid = sanitize_uid_gid(config['gbp-user'], config['gbp-group'])
    except GbpServiceError as err:
        raise ExportError(err, EXIT_ERR_SERVICE)
    # Make temp outdir accessible to the GBP UID/GID
    os.chown(tmp_out, uid, gid)

    # Call GBP
    rpm_args, deb_args = construct_gbp_args(args, config, tmp_out)
    orig_dir = os.path.abspath(os.curdir)
    try:
        os.chdir(repo.repodir)
        specs_found = have_spec('.')
        if args.rpm == 'yes' or (args.rpm == 'auto' and specs_found):
            LOGGER.info('Exporting RPM packaging files with GBP')
            LOGGER.debug('git-buildpackage-rpm args: %s', ' '.join(rpm_args))
            ret = fork_call(uid, gid, gbp_rpm)(rpm_args)
            if ret:
                raise ExportError('Git-buildpackage-rpm failed, unable to '
                                  'export RPM packaging files',
                                  EXIT_ERR_RPM_EXPORT)
        if args.deb == 'yes' or (args.deb== 'auto' and os.path.isdir('debian')):
            LOGGER.info('Exporting Debian source package with GBP')
            LOGGER.debug('git-buildpackage args: %s', ' '.join(deb_args))
            ret = fork_call(uid, gid, gbp_deb)(deb_args)
            if ret:
                raise ExportError('Git-buildpackage failed, unable to export '
                                  'Debian sources package files',
                                  EXIT_ERR_DEB_EXPORT)
        move_dir_content(tmp_out, args.outdir)
    except GbpChildBTError as err:
        LOGGER.error('Unhandled exception in GBP:\n'
                     '%s', err.prettyprint_tb())
        raise ExportError('Failed to export packaging files',
                          EXIT_ERR_GBP_CRASH)
    except GbpServiceError as err:
        LOGGER.error('Internal service error when trying to run GBP: %s', err)
        raise ExportError('This is most likely a configuration error (or a '
                          'BUG)!', EXIT_ERR_SERVICE)
    finally:
        os.chdir(orig_dir)
        shutil.rmtree(tmp_out)
Exemple #8
0
    def test_demoted_call_fail(self):
        """Test running with invalid UID/GID"""
        with assert_raises(GbpServiceError):
            fork_call('_non_existent_user', None, self._dummy_ok)()
        with assert_raises(GbpServiceError):
            fork_call(None, '_non_existen_group', self._dummy_ok)()

        with assert_raises(GbpServiceError):
            self._no_fork_call(99999, None, self._dummy_ok)()
        with assert_raises(GbpServiceError):
            self._no_fork_call(None, 99999, self._dummy_ok)()
        with assert_raises(GbpChildBTError) as exc:
            self._no_fork_call(self._uid, self._gid, self._dummy_raise)()
        eq_(exc.exception.typ, _DummyException)
    def test_demoted_call_fail(self):
        """Test running with invalid UID/GID"""
        with assert_raises(GbpServiceError):
            fork_call('_non_existent_user', None, self._dummy_ok)()
        with assert_raises(GbpServiceError):
            fork_call(None, '_non_existen_group', self._dummy_ok)()

        with assert_raises(GbpServiceError):
            self._no_fork_call(99999, None, self._dummy_ok)()
        with assert_raises(GbpServiceError):
            self._no_fork_call(None, 99999, self._dummy_ok)()
        with assert_raises(GbpChildBTError) as exc:
            self._no_fork_call(self._uid, self._gid, self._dummy_raise)()
        eq_(exc.exception.typ, _DummyException)
Exemple #10
0
def gbs_export(repo, args, config):
    '''Export packaging files with GBS'''
    # Create temporary directory
    try:
        tmpdir = tempfile.mkdtemp(dir=args.outdir)
    except OSError as err:
        raise ServiceError('Failed to create tmpdir: %s' % err,
                           EXIT_ERR_SERVICE)

    # Determine UID/GID and grant permissions to tmpdir
    try:
        uid, gid = sanitize_uid_gid(config['gbs-user'], config['gbs-group'])
    except GbpServiceError as err:
        raise ServiceError(err, EXIT_ERR_SERVICE)
    os.chown(tmpdir, uid, gid)

    # Do export
    try:
        gbs_args = construct_gbs_args(args, tmpdir, repo.repodir)
        LOGGER.info('Exporting packaging files with GBS')
        LOGGER.debug('gbs args: %s', gbs_args)
        try:
            fork_call(uid, gid, cmd_export)(gbs_args)
        except GbpServiceError as err:
            LOGGER.error(
                'Internal service error when trying to run GBS: '
                '%s', err)
            LOGGER.error('Most likely a configuration error (or a BUG)!')
            raise ServiceError('Failed to run GBS thread: %s' % err,
                               EXIT_ERR_SERVICE)
        except GbpChildBTError as err:
            # CmdError and its sublasses are exptected errors
            if issubclass(err.typ, CmdError):
                raise ServiceError('GBS export failed: %s' % err.val,
                                   EXIT_ERR_GBS_EXPORT)
            else:
                LOGGER.error('Uncaught exception in GBS:\n'
                             '%s', err.prettyprint_tb())
                raise ServiceError('GBS crashed, export failed',
                                   EXIT_ERR_GBS_CRASH)

        # Move packaging files from tmpdir to actual outdir
        exportdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
        for fname in os.listdir(exportdir):
            shutil.move(os.path.join(exportdir, fname),
                        os.path.join(args.outdir, fname))
        LOGGER.info('Packaging files successfully exported')
    finally:
        shutil.rmtree(tmpdir)
Exemple #11
0
def gbs_export(repo, args, config):
    '''Export packaging files with GBS'''
    # Create temporary directory
    try:
        tmpdir = tempfile.mkdtemp(dir=args.outdir)
    except OSError as err:
        raise ServiceError('Failed to create tmpdir: %s' % err,
                           EXIT_ERR_SERVICE)

    # Determine UID/GID and grant permissions to tmpdir
    try:
        uid, gid = sanitize_uid_gid(config['gbs-user'], config['gbs-group'])
    except GbpServiceError as err:
        raise ServiceError(err, EXIT_ERR_SERVICE)
    os.chown(tmpdir, uid, gid)

    # Do export
    try:
        gbs_args = construct_gbs_args(args, tmpdir, repo.repodir)
        LOGGER.info('Exporting packaging files with GBS')
        LOGGER.debug('gbs args: %s', gbs_args)
        try:
            fork_call(uid, gid, cmd_export)(gbs_args)
        except GbpServiceError as err:
            LOGGER.error('Internal service error when trying to run GBS: '
                         '%s', err)
            LOGGER.error('Most likely a configuration error (or a BUG)!')
            raise ServiceError('Failed to run GBS thread: %s' % err,
                               EXIT_ERR_SERVICE)
        except GbpChildBTError as err:
            # CmdError and its sublasses are exptected errors
            if issubclass(err.typ, CmdError):
                raise ServiceError('GBS export failed: %s' % err.val,
                                   EXIT_ERR_GBS_EXPORT)
            else:
                LOGGER.error('Uncaught exception in GBS:\n'
                             '%s', err.prettyprint_tb())
                raise ServiceError('GBS crashed, export failed',
                                   EXIT_ERR_GBS_CRASH)

        # Move packaging files from tmpdir to actual outdir
        exportdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
        for fname in os.listdir(exportdir):
            shutil.move(os.path.join(exportdir, fname),
                        os.path.join(args.outdir, fname))
        LOGGER.info('Packaging files successfully exported')
    finally:
        shutil.rmtree(tmpdir)