示例#1
0
def test_bug_str(lp_api):
    bug = lp_bug(5, lp_api)
    bug_str = "LP: #5 : This is the title of a bug\nHeat: 100"
    assert str(bug) == bug_str

    bug = lp_bug(6, lp_api)
    bug_str = "LP: #6 : This is the title of a bug\n"\
        "Heat: 100\n - systemd:\n   - " + ubuntu_devel + " : New (Critical)"
    assert str(bug) == bug_str
示例#2
0
def test_bug_dict(lp_api):
    bug = lp_bug(5, lp_api)
    bug_dict = {'id': 5,
                'title': 'This is the title of a bug',
                'packages': {}}

    assert bug.dict() == bug_dict
示例#3
0
def test_package_detail(lp_api):
    bug = lp_bug(3, lp_api)

    # test with a missing serie and make sure it defaults to ubuntu_devel
    assert bug.package_detail("glibc", 'Focal', "status") == "Incomplete"

    assert bug.package_detail("systemd", ubuntu_devel, "status") == "New"

    # test for detail that doesn't exist
    assert bug.package_detail("systemd", ubuntu_devel, "age") == ""
示例#4
0
def test_affected_versions(lp_api):
    bug = lp_bug(3, lp_api)

    versions = bug.affected_versions('systemd')
    assert versions == [ubuntu_version[ubuntu_devel], '20.04', '18.04']

    versions = bug.affected_versions('vim')
    assert versions == []

    versions = bug.affected_versions('glibc')
    assert versions == [ubuntu_version[ubuntu_devel], '20.04', '18.04']
示例#5
0
def sync_release(issue, jira, lp):
    if not issue or not jira:
        return False

    jira_key = issue['JIRA ID']
    lp_id = issue['LaunchPad ID']

    jira_issue = jira.issue(issue["JIRA ID"])

    # automation 1: check for release status over all series and move the
    # to Done if they are all Fix Released or Won't Fix
    released = False

    try:
        # Rather than going through the status in the json DB, we go directly
        # To the LP bug and go through all the affected packages
        # and if for all the packages and all the series it is either Fix
        # Released or Won't Fix, Well then it is DONE in JIRA
        bug = lp_bug(lp_id, lp)
        for pkg in bug.affected_packages:
            for serie in bug.affected_series(pkg):
                if bug.package_detail(
                        pkg,
                        serie,
                        "status") in ["Fix Released", "Won't Fix"]:
                    released = True
                else:
                    released = False
                    break
            if not released:
                break

        if released:
            if jira_issue.fields.status.name != 'Done':
                print(("\n[Status Sync] - Updating {} "
                       "status to Done per LP: #{}").format(jira_key, lp_id))

                comment = ('{{jira-bot}} Since all affected series of '
                           'the related LP: #%s are *Fix Released,* '
                           'moving this issue to '
                           '{color:#36B37E}*DONE*{color}') % (lp_id)

            jira.add_comment(jira_issue, comment)
            jira.transition_issue(jira_issue, transition='Done')
            return True

    except Exception:
        return False

    return False
示例#6
0
def test_affected_series(lp_api):

    bug = lp_bug(3, lp_api)

    # Simple default serie test
    series = bug.affected_series('systemd')

    assert series == [ubuntu_devel, 'Focal', 'Bionic']

    # Wrong Serie vim (Debian)
    series = bug.affected_series('vim')
    assert series == []

    # Ignore Bad serie glibc !@#$)
    series = bug.affected_series('glibc')
    assert series == [ubuntu_devel, 'Focal', 'Bionic']
示例#7
0
def test_affected_series_double(lp_api):
    bug = lp_bug(4, lp_api)

    series = bug.affected_series('casper')
    assert series == [ubuntu_devel]
示例#8
0
def test_bug_init_bad_lp_api():
    with pytest.raises(ValueError):
        return lp_bug(1234567, None)
示例#9
0
def test_affected_packages(lp_api):
    bug1 = lp_bug(1, lp_api)
    assert bug1.affected_packages == ['systemd', 'glibc']

    bug2 = lp_bug(2, lp_api)
    assert bug2.affected_packages == ['systemd']
示例#10
0
def test_default_init(lp_api):
    bug = lp_bug(1, lp_api)
    assert bug.id == 1
    assert bug.title == "This is the title of a bug"
    assert bug.description == "This is the longer description"
    assert bug.heat == "100"
示例#11
0
def test_bug_init_bad_bug_doesnt_exist(lp_api):
    with pytest.raises(KeyError):
        return lp_bug(123456789, lp_api)
示例#12
0
def test_bug_init_bad_type_bug(lp_api):
    with pytest.raises(ValueError):
        return lp_bug("bad", lp_api)
示例#13
0
def merge_lp_data_with_jira_issues(jira, lp, issues, sync=False):
    if not lp or not jira or not issues:
        return []

    for issue in list(issues):
        print("#", flush=True, end='')
        lpbug_importance = ""
        lpbug_devel = ""
        lpbug_jammy = ""
        lpbug_impish = ""
        lpbug_hirsute = ""
        lpbug_focal = ""
        lpbug_bionic = ""
        lpbug_xenial = ""
        lpbug_trusty = ""

        try:
            lpbug = lp_bug(issue['LaunchPad ID'], lp)
            # We will focus on the first package in the list of affected
            # packages, not ideal but not sure there's a better way
            # Maybe we should just ignore individual packages status...

            # setting default package to None in case bug is open against a
            # project rather than agasint a package
            pkg = "none"

            if lpbug.affected_packages:
                pkg = lpbug.affected_packages[0]

                if lpbug.affected_series(pkg):
                    lpbug_importance = lpbug.package_detail(
                        pkg,
                        lpbug.affected_series(pkg)[0],
                        "importance")

                    lpbug_devel = lpbug.package_detail(
                        pkg, ubuntu_devel, "status")
                    lpbug_jammy = lpbug.package_detail(
                        pkg, "Jammy", "status")
                    lpbug_impish = lpbug.package_detail(
                        pkg, "Impish", "status")
                    lpbug_hirsute = lpbug.package_detail(
                        pkg, "Hirsute", "status")
                    lpbug_focal = lpbug.package_detail(
                        pkg, "Focal", "status")
                    lpbug_bionic = lpbug.package_detail(
                        pkg, "Bionic", "status")
                    lpbug_xenial = lpbug.package_detail(
                        pkg, "Xenial", "status")
                    lpbug_trusty = lpbug.package_detail(
                        pkg, "Trusty", "status")

            issue['Heat'] = str(lpbug.heat)
            issue['Importance'] = lpbug_importance
            issue['Packages'] = pkg
            issue["Devel"] = lpbug_devel
            issue["Jammy"] = lpbug_jammy
            issue["Impish"] = lpbug_impish
            issue["Hirsute"] = lpbug_hirsute
            issue["Focal"] = lpbug_focal
            issue["Bionic"] = lpbug_bionic
            issue["Xenial"] = lpbug_xenial
            issue["Trusty"] = lpbug_trusty


            if sync:
                jira_key = issue["JIRA ID"]
                jira_issue = jira.issue(jira_key)
                if "DisableLPSync" in jira_issue.fields.labels:
                    print("\n[Sync]- Disabled by user for {}".format(
                        jira_key))
                    continue

                sync_title(issue, jira, lp)
                if sync_release(issue, jira, lp):
                    # Must remove the element as it is released
                    issues.remove(issue)

        except Exception:
            print("\nCouldn't find the Launchpad bug {}".format(issue['LaunchPad ID']))
    print()