How to use the koji.BUILD_STATES function in koji

To help you get started, we’ve selected a few koji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github containerbuildsystem / atomic-reactor / tests / plugins / test_koji_import.py View on Github external
        (False, koji.BUILD_STATES['FAILED']),
    ])
    def test_koji_import_failed_build(self, reserved_build, canceled_build, refund_state,
                                      tmpdir, os_env, reactor_config_map):
        session = MockedClientSession('')
        tasker, workflow = mock_environment(tmpdir,
                                            session=session,
                                            build_process_failed=True,
                                            build_process_canceled=canceled_build,
                                            name='ns/name',
                                            version='1.0',
                                            release='1')
        if reserved_build:
            workflow.reserved_build_id = 1
            workflow.reserved_token = 1

        runner = create_runner(tasker, workflow, reactor_config_map=reactor_config_map,
github koji-project / koji / tests / test_hub / test_notifications.py View on Github external
def test_get_notification_recipients(self, readPackageList, get_user):
        # without build / tag_id
        build = None
        tag_id = None
        state = koji.BUILD_STATES['CANCELED']

        emails = kojihub.get_notification_recipients(build, tag_id, state)
        self.assertEqual(emails, [])

        # only query to watchers
        self.assertEqual(len(self.queries), 1)
        q = self.queries[0]
        self.assertEqual(q.columns, ['email'])
        self.assertEqual(q.tables, ['build_notifications'])
        self.assertEqual(q.clauses, ['package_id IS NULL',
                                     'status = %(users_status)i',
                                     'success_only = FALSE',
                                     'tag_id IS NULL',
                                     'usertype IN %(users_usertypes)s'])
        self.assertEqual(q.joins, ['JOIN users ON build_notifications.user_id = users.id'])
        self.assertEqual(q.values['state'], state)
github koji-project / koji / tests / test_hub / test_recycle_build.py View on Github external
def test_recycle_states_bad(self):
        for state in 'BUILDING', 'COMPLETE', 'DELETED':
            yield self.check_recycle_states_bad, koji.BUILD_STATES[state]
github koji-project / koji / tests / test_hub / test_ensure_volume_symlink.py View on Github external
def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.pathinfo = koji.PathInfo(self.tempdir)
        mock.patch('koji.pathinfo', new=self.pathinfo).start()
        mock.patch('kojihub.lookup_name', new=self.my_lookup_name).start()
        self.check_volume_policy = mock.patch('kojihub.check_volume_policy',
                return_value={'id':0, 'name': 'DEFAULT'}).start()
        self.buildinfo = {
                'id': 137,
                'task_id': 'TASK_ID',
                'name': 'some-image',
                'version': '1.2.3.4',
                'release': '3',
                'epoch': None,
                'source': None,
                'state': koji.BUILD_STATES['BUILDING'],
                'volume_id': 0,
                'volume_name': 'DEFAULT',
                }
github containerbuildsystem / atomic-reactor / tests / test_koji_util.py View on Github external
def test_without_context(self, koji_return, should_raise):
        module = 'eog:master:20180821163756'
        spec = ModuleSpec.from_str(module)

        session = flexmock()
        (session
            .should_receive('getPackageID')
            .with_args('eog')
            .and_return(303))
        (session
            .should_receive('listBuilds')
            .with_args(packageID=303,
                       type='module',
                       state=koji.BUILD_STATES['COMPLETE'])
            .and_return(koji_return))

        if should_raise:
            with pytest.raises(Exception) as e:
                get_koji_module_build(session, spec)
            assert should_raise in str(e.value)
        else:
            self.mock_get_rpms(session)
            get_koji_module_build(session, spec)
github koji-project / koji / tests / test_hub / test_tag_operations.py View on Github external
def test_simple_untag(self):
        self.check_tag_access.return_value = (True, False, "")
        self.get_build.return_value = {
            'id': 1,
            'name': 'name',
            'version': 'version',
            'release': 'release',
            'state': koji.BUILD_STATES['COMPLETE'],
        }
        self.get_tag.return_value = {
            'id': 777,
            'name': 'tag',
        }
        self.get_user.return_value = {
            'id': 999,
            'name': 'user',
        }
        self.context.event_id = 42
        # set return for the already tagged check
        self.query_executeOne.return_value = None

        # call it
        kojihub._untag_build('sometag', 'name-version-release')
github koji-project / koji / tests / test_hub / test_complete_image_build.py View on Github external
def test_complete_image_build(self):
        self.set_up_files('import_1')
        buildinfo = {
                'id': 137,
                'task_id': 'TASK_ID',
                'name': 'some-image',
                'version': '1.2.3.4',
                'release': '3',
                'epoch': None,
                'source': None,
                'state': koji.BUILD_STATES['BUILDING'],
                'volume_id': 0,
                }
        image_info = {'build_id': buildinfo['id']}
        self.get_build.return_value = buildinfo
        self.get_image_build.return_value = image_info

        # run the import call
        self.hostcalls.completeImageBuild('TASK_ID', 'BUILD_ID', self.image_data)

        # make sure we wrote the files we expect
        expected = self.get_expected_files(buildinfo)
        files = []
        for dirpath, dirnames, filenames in os.walk(self.tempdir + '/packages'):
            files.extend([os.path.join(dirpath, fn) for fn in filenames])
        self.assertEqual(set(files), set(expected))
github containerbuildsystem / atomic-reactor / atomic_reactor / koji_util.py View on Github external
# The easy case - we can build the koji "name-version-release" out of the
        # module spec.
        koji_nvr = "{}-{}-{}.{}".format(module_spec.name,
                                        module_spec.stream.replace("-", "_"),
                                        module_spec.version,
                                        module_spec.context)
        logger.info("Looking up module build %s in Koji", koji_nvr)
        build = session.getBuild(koji_nvr)
    else:
        # Without the context, we have to retrieve all builds for the module, and
        # find the one we want. This is pretty inefficient, but won't be needed
        # long-term.
        logger.info("Listing all builds for %s in Koji", module_spec.name)
        package_id = session.getPackageID(module_spec.name)
        builds = session.listBuilds(packageID=package_id, type='module',
                                    state=koji.BUILD_STATES['COMPLETE'])
        build = None

        for b in builds:
            if '.' in b['release']:
                version, _ = b['release'].split('.', 1)
                if version == module_spec.version:
                    if build is not None:
                        raise RuntimeError("Multiple builds found for {}"
                                           .format(module_spec.to_str()))
                    else:
                        build = b

        if build is None:
            raise RuntimeError("No build found for {}".format(module_spec.to_str()))

    archives = session.listArchives(buildID=build['build_id'])
github ralphbean / lightsaber / roles / development / files / bin / ship-it.py View on Github external
Run this after you have made a change, committed and build the master branch.
"""

import argparse
import os
import sh
import sys
import six
import textwrap

import logging
logging.basicConfig(level=logging.DEBUG)

import fedmsg
import koji
build_state_names = {v: k for k, v in koji.BUILD_STATES.items()}

# sigh..
import time


aggregated = ""
passwd = ""

# open stdout in unbuffered mode
sys.stdout = os.fdopen(sys.stdout.fileno(), "wb", 0)


def _handle_stdout(char, stdin):
    global aggregated
    global passwd
github containerbuildsystem / atomic-reactor / atomic_reactor / plugins / pre_koji_parent.py View on Github external
"""
        Given image NVR, wait for the build that produced it to show up in koji.
        If it doesn't within the timeout, raise an error.

        :return build info dict with 'nvr' and 'id' keys
        """

        self.log.info('Waiting for Koji build for parent image %s', nvr)
        poll_start = time.time()
        while time.time() - poll_start < self.poll_timeout:
            build = self.koji_session.getBuild(nvr)
            if build:
                self.log.info('Parent image Koji build found with id %s', build.get('id'))
                if build['state'] == koji.BUILD_STATES['COMPLETE']:
                    return build
                elif build['state'] != koji.BUILD_STATES['BUILDING']:
                    exc_msg = ('Parent image Koji build for {} with id {} state is not COMPLETE.')
                    raise KojiParentBuildMissing(exc_msg.format(nvr, build.get('id')))
            time.sleep(self.poll_interval)
        raise KojiParentBuildMissing('Parent image Koji build NOT found for {}!'.format(nvr))