def test_buildsrpm(self, monkeypatch):
        # Set to list to get it passed by reference to clusures
        checked_cmd = [[]]

        def check_output(cmd):
            checked_cmd[0] = list(cmd)
            return 'some output'
        monkeypatch.setattr(mock_chroot, 'check_output', check_output)
        mc = MockChroot(root='some_root')
        output = mc.buildsrpm(spec='some.spec', sources='/some/sources')
        expected = [
            MockChroot.mock_exe(),
            '--root=some_root',
            '--buildsrpm',
            '--spec', 'some.spec',
            '--sources', '/some/sources',
        ]
        assert checked_cmd[0] == expected
        assert output == 'some output'
        output = mc.buildsrpm(
            spec='some.spec', sources='/some/sources', define='def1'
        )
        expected = [
            MockChroot.mock_exe(),
            '--root=some_root',
            '--buildsrpm',
            '--spec', 'some.spec',
            '--sources', '/some/sources',
            '--define', 'def1',
        ]
        assert checked_cmd[0] == expected
        assert output == 'some output'
Exemplo n.º 2
0
    def build_in_mock(self, branch):
        """Build the sources in self.package_workdir as rhpkg woulb build them
        if they were pushed to the specified distgit branch

        The following environment variables can affect how this method works:
        - KOJI_TOPURL: Specifies a Koji package mirror to use
        - KOJI_PROFILE: Specifies which Koji configuration profile to use
                        (defaults to 'brew')
        """
        print("Building branch '{0}' in Mock".format(branch))
        out_dir = os.path.join(
            self.builder.rpmbuild_basedir,
            '{0}-{1}'.format(self.project_name,
                             self.builder.build_version), branch)
        getoutput("mkdir -p %s" % out_dir)
        print('build output will be written to {0}'.format(out_dir))
        # Logic taken from pyrpkg sources:
        target = '%s-candidate' % branch
        mock_conf = mock_config.compose(
            mock_config.from_koji(
                target=target,
                topurl=os.environ.get('KOJI_TOPURL', None),
                koji_profile=os.environ.get('KOJI_PROFILE', 'brew'),
            ), mock_config.to['resultdir'].set(out_dir),
            mock_config.to['root_cache_enable'].set(True),
            mock_config.to['yum_cache_enable'].set(True))
        extra_yum_config = self._build_extra_yum_config(branch)
        if extra_yum_config:
            print('Injecting extra yum configuration to Mock')
            mock_conf.append(mock_config.to['yum.conf'].add(extra_yum_config))
        debug('Dumping mock configuration')
        debug(str(mock_conf))
        mock = MockChroot(config=mock_conf)
        print('Building SRPM in Mock')
        mock.buildsrpm(
            spec=self.builder.spec_file,
            sources=self.package_workdir,
        )
        srpms = glob('{0}/*.src.rpm'.format(out_dir))
        if len(srpms) == 0:
            raise RuntimeError('no srpms found in {0}'.format(out_dir))
        elif len(srpms) > 1:
            raise RuntimeError('multiple srpms found in {0}'.format(out_dir))
        else:
            srpm = srpms[0]
        print('Building RPM in Mock')
        mock.rebuild(src_rpm=srpm, no_clean=True)
Exemplo n.º 3
0
    def build_in_mock(self, branch):
        """Build the sources in self.package_workdir as rhpkg woulb build them
        if they were pushed to the specified distgit branch

        The following environment variables can affect how this method works:
        - KOJI_TOPURL: Specifies a Koji package mirror to use
        - KOJI_PROFILE: Specifies which Koji configuration profile to use
                        (defaults to 'brew')
        """
        print("Building branch '{0}' in Mock".format(branch))
        out_dir = os.path.join(
            self.builder.rpmbuild_basedir, "{0}-{1}".format(self.project_name, self.builder.build_version), branch
        )
        getoutput("mkdir -p %s" % out_dir)
        print("build output will be written to {0}".format(out_dir))
        # Logic taken from pyrpkg sources:
        target = "%s-candidate" % branch
        mock_conf = mock_config.compose(
            mock_config.from_koji(
                target=target,
                topurl=os.environ.get("KOJI_TOPURL", None),
                koji_profile=os.environ.get("KOJI_PROFILE", "brew"),
            ),
            mock_config.to["resultdir"].set(out_dir),
            mock_config.to["root_cache_enable"].set(True),
            mock_config.to["yum_cache_enable"].set(True),
        )
        extra_yum_config = self._build_extra_yum_config(branch)
        if extra_yum_config:
            print("Injecting extra yum configuration to Mock")
            mock_conf.append(mock_config.to["yum.conf"].add(extra_yum_config))
        debug("Dumping mock configuration")
        debug(str(mock_conf))
        mock = MockChroot(config=mock_conf)
        print("Building SRPM in Mock")
        mock.buildsrpm(spec=self.builder.spec_file, sources=self.package_workdir)
        srpms = glob("{0}/*.src.rpm".format(out_dir))
        if len(srpms) == 0:
            raise RuntimeError("no srpms found in {0}".format(out_dir))
        elif len(srpms) > 1:
            raise RuntimeError("multiple srpms found in {0}".format(out_dir))
        else:
            srpm = srpms[0]
        print("Building RPM in Mock")
        mock.rebuild(src_rpm=srpm, no_clean=True)
    def test_buildsrpm(self, monkeypatch):
        # Set to list to get it passed by reference to clusures
        checked_cmd = [[]]

        def check_output(cmd):
            checked_cmd[0] = list(cmd)
            return 'some output'

        monkeypatch.setattr(mock_chroot, 'check_output', check_output)
        mc = MockChroot(root='some_root')
        output = mc.buildsrpm(spec='some.spec', sources='/some/sources')
        expected = [
            MockChroot.mock_exe(),
            '--root=some_root',
            '--buildsrpm',
            '--spec',
            'some.spec',
            '--sources',
            '/some/sources',
        ]
        assert checked_cmd[0] == expected
        assert output == 'some output'
        output = mc.buildsrpm(spec='some.spec',
                              sources='/some/sources',
                              define='def1')
        expected = [
            MockChroot.mock_exe(),
            '--root=some_root',
            '--buildsrpm',
            '--spec',
            'some.spec',
            '--sources',
            '/some/sources',
            '--define',
            'def1',
        ]
        assert checked_cmd[0] == expected
        assert output == 'some output'