コード例 #1
0
 def test_get_koji_build_info_fail(self, m_config):
     m_config.kojihub_url = "http://kojihub.com"
     m_proc = Mock()
     m_proc.exitstatus = 1
     m_remote = Mock()
     m_remote.run.return_value = m_proc
     m_ctx = Mock()
     m_ctx.summary = dict()
     with pytest.raises(RuntimeError):
         packaging.get_koji_build_info(1, m_remote, m_ctx)
コード例 #2
0
ファイル: test_packaging.py プロジェクト: charpty/teuthology
 def test_get_koji_build_info_success(self, m_config):
     m_config.kojihub_url = "http://kojihub.com"
     m_proc = Mock()
     expected = dict(foo="bar")
     m_proc.exitstatus = 0
     m_proc.stdout.getvalue.return_value = str(expected)
     m_remote = Mock()
     m_remote.run.return_value = m_proc
     result = packaging.get_koji_build_info(1, m_remote, dict())
     assert result == expected
     args, kwargs = m_remote.run.call_args
     expected_args = [
         "python",
         "-c",
         "import koji; " 'hub = koji.ClientSession("http://kojihub.com"); ' "print hub.getBuild(1)",
     ]
     assert expected_args == kwargs["args"]
コード例 #3
0
def process_role(ctx, config, timeout, role, role_config):
    need_install = None  # sha1 to dl, or path to rpm or deb
    need_version = None  # utsrelease or sha1

    # gather information about this remote
    (role_remote, ) = ctx.cluster.only(role).remotes.keys()
    system_type = role_remote.os.name
    if role_remote.is_container:
        log.info(
            f"Remote f{role_remote.shortname} is a container; skipping kernel installation"
        )
        return
    if role_config.get('rpm') or role_config.get('deb'):
        # We only care about path - deb: vs rpm: is meaningless,
        # rpm: just happens to be parsed first.  Nothing is stopping
        # 'deb: /path/to/foo.rpm' and it will work provided remote's
        # os.package_type is 'rpm' and vice versa.
        path = role_config.get('rpm')
        if not path:
            path = role_config.get('deb')
        sha1 = get_sha1_from_pkg_name(path)
        assert sha1, "failed to extract commit hash from path %s" % path
        if need_to_install(ctx, role, sha1):
            need_install = path
            need_version = sha1
    elif role_config.get('sha1') == 'distro':
        version = need_to_install_distro(role_remote, role_config)
        if version:
            need_install = 'distro'
            need_version = version
    elif role_config.get("koji") or role_config.get('koji_task'):
        # installing a kernel from koji
        build_id = role_config.get("koji")
        task_id = role_config.get("koji_task")
        if role_remote.os.package_type != "rpm":
            msg = ("Installing a kernel from koji is only supported "
                   "on rpm based systems. System type is {system_type}.")
            msg = msg.format(system_type=system_type)
            log.error(msg)
            ctx.summary["failure_reason"] = msg
            ctx.summary["status"] = "dead"
            raise ConfigError(msg)

        # FIXME: this install should probably happen somewhere else
        # but I'm not sure where, so we'll leave it here for now.
        install_package('koji', role_remote)

        if build_id:
            # get information about this build from koji
            build_info = get_koji_build_info(build_id, role_remote, ctx)
            version = "{ver}-{rel}.x86_64".format(ver=build_info["version"],
                                                  rel=build_info["release"])
        elif task_id:
            # get information about results of this task from koji
            task_result = get_koji_task_result(task_id, role_remote, ctx)
            # this is not really 'build_info', it's a dict of information
            # about the kernel rpm from the task results, but for the sake
            # of reusing the code below I'll still call it that.
            build_info = get_koji_task_rpm_info('kernel', task_result['rpms'])
            # add task_id so we can know later that we're installing
            # from a task and not a build.
            build_info["task_id"] = task_id
            version = build_info["version"]

        if need_to_install(ctx, role, version):
            need_install = build_info
            need_version = version
    else:
        builder = get_builder_project()(
            "kernel",
            role_config,
            ctx=ctx,
            remote=role_remote,
        )
        sha1 = builder.sha1
        log.debug('sha1 for {role} is {sha1}'.format(role=role, sha1=sha1))
        ctx.summary['{role}-kernel-sha1'.format(role=role)] = sha1

        if need_to_install(ctx, role, sha1):
            if teuth_config.use_shaman:
                version = builder.scm_version
            else:
                version = builder.version
            if not version:
                raise VersionNotFoundError(builder.base_url)
            need_install = sha1
            need_version = version

    if need_install:
        install_firmware(ctx, {role: need_install})
        download_kernel(ctx, {role: need_install})
        install_and_reboot(ctx, {role: need_install}, config)
        wait_for_reboot(ctx, {role: need_version}, timeout, config)

    # enable or disable kdb if specified, otherwise do not touch
    if role_config.get('kdb') is not None:
        kdb = role_config.get('kdb')
        enable_disable_kdb(ctx, {role: kdb})
コード例 #4
0
ファイル: kernel.py プロジェクト: yongseokoh/teuthology
def task(ctx, config):
    """
    Make sure the specified kernel is installed.
    This can be a branch, tag, or sha1 of ceph-client.git or a local
    kernel package.

    To install ceph-client.git branch (default: master)::

        kernel:
          branch: testing

    To install ceph-client.git tag::

        kernel:
          tag: v3.18

    To install ceph-client.git sha1::

        kernel:
          sha1: 275dd19ea4e84c34f985ba097f9cddb539f54a50

    To install from a koji build_id::

        kernel:
          koji: 416058

    To install from a koji task_id::

        kernel:
          koji_task: 9678206

    When installing from koji you also need to set the urls for koji hub
    and the koji root in your teuthology.yaml config file. These are shown
    below with their default values::

        kojihub_url: http://koji.fedoraproject.org/kojihub
        kojiroot_url: http://kojipkgs.fedoraproject.org/packages

    When installing from a koji task_id you also need to set koji_task_url,
    which is the base url used to download rpms from koji task results::

        koji_task_url: https://kojipkgs.fedoraproject.org/work/

    To install local rpm (target should be an rpm system)::

        kernel:
          rpm: /path/to/appropriately-named.rpm

    To install local deb (target should be a deb system)::

        kernel:
          deb: /path/to/appropriately-named.deb

    For rpm: or deb: to work it should be able to figure out sha1 from
    local kernel package basename, see get_sha1_from_pkg_name().  This
    means that you can't for example install a local tag - package built
    with upstream {rpm,deb}-pkg targets won't have a sha1 in its name.

    If you want to schedule a run and use a local kernel package, you
    have to copy the package over to a box teuthology workers are
    running on and specify a path to the package on that box.

    All of the above will install a specified kernel on all targets.
    You can specify different kernels for each role or for all roles of
    a certain type (more specific roles override less specific, see
    normalize_config() for details)::

        kernel:
          client:
            tag: v3.0
          osd:
            branch: btrfs_fixes
          client.1:
            branch: more_specific
          osd.3:
            branch: master

    To wait 3 minutes for hosts to reboot (default: 300)::

        kernel:
          timeout: 180

    To enable kdb::

        kernel:
          kdb: true

    :param ctx: Context
    :param config: Configuration
    """
    if config is None:
        config = {}
    assert isinstance(config, dict), \
        "task kernel only supports a dictionary for configuration"

    overrides = ctx.config.get('overrides', {}).get('kernel', {})
    config, timeout = normalize_and_apply_overrides(ctx, config, overrides)
    validate_config(ctx, config)
    log.info('config %s, timeout %d' % (config, timeout))

    need_install = {}  # sha1 to dl, or path to rpm or deb
    need_version = {}  # utsrelease or sha1
    kdb = {}

    for role, role_config in config.items():
        # gather information about this remote
        (role_remote,) = ctx.cluster.only(role).remotes.keys()
        system_type = role_remote.os.name
        if role_config.get('rpm') or role_config.get('deb'):
            # We only care about path - deb: vs rpm: is meaningless,
            # rpm: just happens to be parsed first.  Nothing is stopping
            # 'deb: /path/to/foo.rpm' and it will work provided remote's
            # os.package_type is 'rpm' and vice versa.
            path = role_config.get('rpm')
            if not path:
                path = role_config.get('deb')
            sha1 = get_sha1_from_pkg_name(path)
            assert sha1, "failed to extract commit hash from path %s" % path
            if need_to_install(ctx, role, sha1):
                need_install[role] = path
                need_version[role] = sha1
        elif role_config.get('sha1') == 'distro':
            version = need_to_install_distro(role_remote)
            if version:
                need_install[role] = 'distro'
                need_version[role] = version
        elif role_config.get("koji") or role_config.get('koji_task'):
            # installing a kernel from koji
            build_id = role_config.get("koji")
            task_id = role_config.get("koji_task")
            if role_remote.os.package_type != "rpm":
                msg = (
                    "Installing a kernel from koji is only supported "
                    "on rpm based systems. System type is {system_type}."
                )
                msg = msg.format(system_type=system_type)
                log.error(msg)
                ctx.summary["failure_reason"] = msg
                ctx.summary["status"] = "dead"
                raise ConfigError(msg)

            # FIXME: this install should probably happen somewhere else
            # but I'm not sure where, so we'll leave it here for now.
            install_package('koji', role_remote)

            if build_id:
                # get information about this build from koji
                build_info = get_koji_build_info(build_id, role_remote, ctx)
                version = "{ver}-{rel}.x86_64".format(
                    ver=build_info["version"],
                    rel=build_info["release"]
                )
            elif task_id:
                # get information about results of this task from koji
                task_result = get_koji_task_result(task_id, role_remote, ctx)
                # this is not really 'build_info', it's a dict of information
                # about the kernel rpm from the task results, but for the sake
                # of reusing the code below I'll still call it that.
                build_info = get_koji_task_rpm_info(
                    'kernel',
                    task_result['rpms']
                )
                # add task_id so we can know later that we're installing
                # from a task and not a build.
                build_info["task_id"] = task_id
                version = build_info["version"]

            if need_to_install(ctx, role, version):
                need_install[role] = build_info
                need_version[role] = version
        else:
            builder = get_builder_project()(
                "kernel",
                role_config,
                ctx=ctx,
                remote=role_remote,
            )
            sha1 = builder.sha1
            log.debug('sha1 for {role} is {sha1}'.format(role=role, sha1=sha1))
            ctx.summary['{role}-kernel-sha1'.format(role=role)] = sha1

            if need_to_install(ctx, role, sha1):
                if teuth_config.use_shaman:
                    version = builder.scm_version
                else:
                    version = builder.version
                if not version:
                    raise VersionNotFoundError(builder.base_url)
                need_install[role] = sha1
                need_version[role] = version

        # enable or disable kdb if specified, otherwise do not touch
        if role_config.get('kdb') is not None:
            kdb[role] = role_config.get('kdb')

    if need_install:
        install_firmware(ctx, need_install)
        download_kernel(ctx, need_install)
        install_and_reboot(ctx, need_install)
        wait_for_reboot(ctx, need_version, timeout)

    enable_disable_kdb(ctx, kdb)