# Path: teuthology/packaging.py
# _PACKAGE_MAP = {
#     'sqlite': {'deb': 'sqlite3', 'rpm': None}
# }
# _SERVICE_MAP = {
#     'httpd': {'deb': 'apache2', 'rpm': 'httpd'}
# }
# def get_package_name(pkg, rem):
# def get_service_name(service, rem):
# def install_package(package, remote):
# def remove_package(package, remote):
# def get_koji_task_result(task_id, remote, ctx):
# def get_koji_task_rpm_info(package, task_rpms):
# def _find_koji_task_result(package, rpm_list):
# def _get_koji_task_result_package_name(path):
# def get_koji_build_info(build_id, remote, ctx):
# def _run_python_command(py_cmd, remote, ctx):
# def get_kojiroot_base_url(build_info, arch="x86_64"):
# def get_koji_package_name(package, build_info, arch="x86_64"):
# def get_package_version(remote, package):
# def _get_config_value_for_remote(ctx, remote, config, key):
# def _get_response(url, wait=False, sleep=15, tries=10):
#     def __init__(self, project, job_config, ctx=None, remote=None):
#     def _init_from_remote(self):
#     def _init_from_config(self):
#     def sha1(self):
#     def version(self):
#     def base_url(self):
#     def uri_reference(self):
#     def _get_dist_release(self):
#     def _parse_version(version):
#     def _get_distro(cls, distro=None, version=None, codename=None):
#     def _get_version(self):
#     def _get_uri_reference(self):
#     def _choose_reference(self):
#         def warn(attrname):
#     def _get_base_url(self):
#     def _get_package_version(self):
#     def _get_package_sha1(self):
#     def install_repo(self):
#     def _install_rpm_repo(self):
#     def _install_deb_repo(self):
#     def remove_repo(self):
#     def _remove_rpm_repo(self):
#     def _remove_deb_repo(self):
#     def __init__(self, project, job_config, ctx=None, remote=None):
#     def _get_base_url(self):
#     def _result(self):
#     def _search(self):
#     def _search_uri(self):
#     def _tag_to_sha1(self):
#         def get_sha1(url):
#     def assert_result(self):
#     def _get_distro(cls, distro=None, version=None, codename=None):
#     def _get_package_sha1(self):
#     def _get_package_version(self):
#     def scm_version(self):
#     def repo_url(self):
#     def build_complete(self):
#     def _get_repo(self):
#     def _install_rpm_repo(self):
#     def _install_deb_repo(self):
#     def _remove_rpm_repo(self):
# def get_builder_project():
# class GitbuilderProject(object):
# class ShamanProject(GitbuilderProject):


import pytest
from unittest.mock import patch, Mock
from teuthology import packaging
from teuthology.exceptions import VersionNotFoundError
    def test_get_koji_task_rpm_info_success(self, m_config):
        m_config.koji_task_url = "http://kojihub.com/work"
        expected = dict(
            base_url="http://kojihub.com/work/tasks/6745/9666745/",
            version="4.1.0-0.rc2.git2.1.fc23.x86_64",
            rpm_name="kernel-4.1.0-0.rc2.git2.1.fc23.x86_64.rpm",
            package_name="kernel",
        )
        result = packaging.get_koji_task_rpm_info('kernel', KOJI_TASK_RPMS)
        assert expected == result

    @patch("teuthology.packaging.config")
    def test_get_koji_task_rpm_info_fail(self, m_config):
        m_config.koji_task_url = "http://kojihub.com/work"
        with pytest.raises(RuntimeError):
            packaging.get_koji_task_rpm_info('ceph', KOJI_TASK_RPMS)

    def test_get_package_version_deb_found(self):
        remote = Mock()
        remote.os.package_type = "deb"
        proc = Mock()
        proc.exitstatus = 0
        proc.stdout.getvalue.return_value = "2.2"
        remote.run.return_value = proc
        result = packaging.get_package_version(remote, "apache2")
        assert result == "2.2"

    def test_get_package_version_deb_command(self):
        remote = Mock()
        remote.os.package_type = "deb"

# Path: teuthology/packaging.py
# _PACKAGE_MAP = {
#     'sqlite': {'deb': 'sqlite3', 'rpm': None}
# }
# _SERVICE_MAP = {
#     'httpd': {'deb': 'apache2', 'rpm': 'httpd'}
# }
# def get_package_name(pkg, rem):
# def get_service_name(service, rem):
# def install_package(package, remote):
# def remove_package(package, remote):
# def get_koji_task_result(task_id, remote, ctx):
# def get_koji_task_rpm_info(package, task_rpms):
# def _find_koji_task_result(package, rpm_list):
# def _get_koji_task_result_package_name(path):
# def get_koji_build_info(build_id, remote, ctx):
# def _run_python_command(py_cmd, remote, ctx):
# def get_kojiroot_base_url(build_info, arch="x86_64"):
# def get_koji_package_name(package, build_info, arch="x86_64"):
# def get_package_version(remote, package):
# def _get_config_value_for_remote(ctx, remote, config, key):
# def _get_response(url, wait=False, sleep=15, tries=10):
#     def __init__(self, project, job_config, ctx=None, remote=None):
#     def _init_from_remote(self):
#     def _init_from_config(self):
#     def sha1(self):
#     def version(self):
#     def base_url(self):
#     def uri_reference(self):
#     def _get_dist_release(self):
#     def _parse_version(version):
#     def _get_distro(cls, distro=None, version=None, codename=None):
#     def _get_version(self):
#     def _get_uri_reference(self):
#     def _choose_reference(self):
#         def warn(attrname):
#     def _get_base_url(self):
#     def _get_package_version(self):
#     def _get_package_sha1(self):
#     def install_repo(self):
#     def _install_rpm_repo(self):
#     def _install_deb_repo(self):
#     def remove_repo(self):
#     def _remove_rpm_repo(self):
#     def _remove_deb_repo(self):
#     def __init__(self, project, job_config, ctx=None, remote=None):
#     def _get_base_url(self):
#     def _result(self):
#     def _search(self):
#     def _search_uri(self):
#     def _tag_to_sha1(self):
#         def get_sha1(url):
#     def assert_result(self):
#     def _get_distro(cls, distro=None, version=None, codename=None):
#     def _get_package_sha1(self):
#     def _get_package_version(self):
#     def scm_version(self):
#     def repo_url(self):
#     def build_complete(self):
#     def _get_repo(self):
#     def _install_rpm_repo(self):
#     def _install_deb_repo(self):
#     def _remove_rpm_repo(self):
# def get_builder_project():
# class GitbuilderProject(object):
# class ShamanProject(GitbuilderProject):


# Path: teuthology/test/test_packaging.py
import pytest
from unittest.mock import patch, Mock
from teuthology import packaging
from teuthology.exceptions import VersionNotFoundError

    def test_get_koji_task_rpm_info_success(self, m_config):
        m_config.koji_task_url = "http://kojihub.com/work"
        expected = dict(
            base_url="http://kojihub.com/work/tasks/6745/9666745/",
            version="4.1.0-0.rc2.git2.1.fc23.x86_64",
            rpm_name="kernel-4.1.0-0.rc2.git2.1.fc23.x86_64.rpm",
            package_name="kernel",
        )
        result = packaging.get_koji_task_rpm_info('kernel', KOJI_TASK_RPMS)
        assert expected == result

    @patch("teuthology.packaging.config")
    def test_get_koji_task_rpm_info_fail(self, m_config):
        m_config.koji_task_url = "http://kojihub.com/work"
        with pytest.raises(RuntimeError):
            packaging.get_koji_task_rpm_info('ceph', KOJI_TASK_RPMS)

    def test_get_package_version_deb_found(self):
        remote = Mock()
        remote.os.package_type = "deb"
        proc = Mock()
        proc.exitstatus = 0
        proc.stdout.getvalue.return_value = "2.2"
        remote.run.return_value = proc
        result = packaging.get_package_version(remote, "apache2")
        assert result == "2.2"

    def test_get_package_version_deb_command(self):
        remote = Mock()
        remote.os.package_type = "deb"

        packaging.get_package_version(remote, "apache2")