Esempio n. 1
0
def create_date_based_data(ptm, monkeypatch, dates=None):
    """Store and process some good and some error blobs on specified dates"""

    if not dates:
        dates = [
            utils.get_day_range(5)["start"],
            utils.get_day_range(4)["start"],
            utils.get_day_range(3)["start"],
        ]

    # 5 days ago
    mocknow = dates[0]

    def mock_now():
        return mocknow

    monkeypatch.setattr(utils, 'get_now_timestamp', mock_now)

    # store the error blob
    blob = perftest_json(
        testrun={"date": dates[0]},
        test_build={"name": "one"},
    )
    badblob = "{0}fooo".format(blob)
    ptm.store_test_data(badblob, error="badness")

    # 4 days ago
    mocknow = dates[1]
    # store the good blobs
    blobs = [
        perftest_json(
            testrun={"date": dates[1]},
            test_build={"name": "one"},
        ),
        perftest_json(
            testrun={"date": dates[1]},
            test_build={"name": "three"},
        ),
    ]

    # 3 days ago
    mocknow = dates[2]

    # store another error blob
    blob = perftest_json(
        testrun={"date": dates[2]},
        test_build={"name": "four"},
    )
    badblob = "{0}fooo".format(blob)
    ptm.store_test_data(badblob, error="Malformed JSON")

    for blob in blobs:
        ptm.store_test_data(blob)

    # now process all of them
    ptm.process_objects(4)
Esempio n. 2
0
def create_date_based_data(ptm, monkeypatch, dates=None):
    """Store and process some good and some error blobs on specified dates"""

    if not dates:
        dates = [
            utils.get_day_range(5)["start"],
            utils.get_day_range(4)["start"],
            utils.get_day_range(3)["start"],
            ]

    # 5 days ago
    mocknow = dates[0]
    def mock_now():
        return mocknow
    monkeypatch.setattr(utils, 'get_now_timestamp', mock_now)

    # store the error blob
    blob = perftest_json(
        testrun={"date": dates[0]},
        test_build={"name": "one"},
        )
    badblob = "{0}fooo".format(blob)
    ptm.store_test_data(badblob, error="badness")

    # 4 days ago
    mocknow = dates[1]
    # store the good blobs
    blobs = [
        perftest_json(
            testrun={"date": dates[1]},
            test_build={"name": "one"},
            ),
        perftest_json(
            testrun={"date": dates[1]},
            test_build={"name": "three"},
            ),
        ]

    # 3 days ago
    mocknow = dates[2]

    # store another error blob
    blob = perftest_json(
        testrun={"date": dates[2]},
        test_build={"name": "four"},
        )
    badblob = "{0}fooo".format(blob)
    ptm.store_test_data(badblob, error="Malformed JSON")

    for blob in blobs:
        ptm.store_test_data(blob)

    # now process all of them
    ptm.process_objects(4)
def test_get_runs_by_branch_show_test_runs_false(ptm, client, monkeypatch):
    """
    Test that with show_runs not present that you get the counts only
    """
    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
        ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/perftest/runs_by_branch/?days_ago=6".format(ptm.project)
    response = client.get(url)

    exp = ["count"]
    assert response.json["Mozilla-Aurora"].keys() == exp
Esempio n. 4
0
def get_range(request):
    """Utility function to extract the date range from the request."""

    days_ago = int(request.GET.get("days_ago"))
    numdays = int(request.GET.get("numdays", 0))

    return utils.get_day_range(days_ago, numdays)
Esempio n. 5
0
def get_range(request):
    """Utility function to extract the date range from the request."""

    days_ago = int(request.GET.get("days_ago"))
    numdays = int(request.GET.get("numdays", 0))

    return utils.get_day_range(days_ago, numdays)
def test_get_not_referenced(ptm, client, monkeypatch):
    """
    Test that get_not_referenced uses the right dates without branches
    """
    def mock_get_not_referenced(project, startdate, enddate, branches):
        return {
            "project": project,
            "startdate": startdate,
            "enddate": enddate,
            "branches": branches,
            }
    monkeypatch.setattr(
        pushlog_refdata,
        'get_not_referenced',
        mock_get_not_referenced,
        )

    date_range = utils.get_day_range(6)

    url = ("/{0}/refdata/pushlog/not_referenced/?"
        "days_ago=6").format(ptm.project)
    response = client.get(url)

    exp = {
        "project": ptm.project,
        "startdate": date_range["start"],
        "enddate": date_range["stop"],
        "branches": None,
        }

    assert response.json == exp
Esempio n. 7
0
    def handle_project(self, project, **options):
        """Report pushlogs not referenced with tests in the project."""

        self.stdout.write("Processing project {0}\n".format(project))

        days_ago = options.get("days_ago")
        if not days_ago:
            raise CommandError("You must supply days_ago.")
        numdays = options.get("numdays")
        branches = options.get("branches")

        range = utils.get_day_range(days_ago, numdays)
        if branches:
            branches = branches.split(",")
        else:
            branches = pushlog_refdata.get_all_branches()

        stats = pushlog_refdata.get_not_referenced(
            project,
            range["start"],
            range["stop"],
            branches,
        )
        print json.dumps(stats, indent=4)
        return
Esempio n. 8
0
def test_get_not_referenced(ptm, client, monkeypatch):
    """
    Test that get_not_referenced uses the right dates without branches
    """
    def mock_get_not_referenced(project, startdate, enddate, branches):
        return {
            "project": project,
            "startdate": startdate,
            "enddate": enddate,
            "branches": branches,
        }

    monkeypatch.setattr(
        pushlog_refdata,
        'get_not_referenced',
        mock_get_not_referenced,
    )

    date_range = utils.get_day_range(6)

    url = ("/{0}/refdata/pushlog/not_referenced/?"
           "days_ago=6").format(ptm.project)
    response = client.get(url)

    exp = {
        "project": ptm.project,
        "startdate": date_range["start"],
        "enddate": date_range["stop"],
        "branches": None,
    }

    assert response.json == exp
def test_get_error_list(ptm):
    """Test the get_error_list method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_list(
        ptm.project,
        date_range["start"],
        date_range["stop"],
        )
    exp = (
        {
            'id': 1L,
            'test_run_id': None,
            'worker_id': None,
            'processed_flag': u'ready',
            'error_msg': u'badness'
            },
        {
            'id': 2L,
            'test_run_id': None,
            'worker_id': None,
            'processed_flag': u'ready',
            'error_msg': u'Malformed JSON',
            })
Esempio n. 10
0
    def handle_project(self, project, **options):
        """Report pushlogs not referenced with tests in the project."""

        self.stdout.write("Processing project {0}\n".format(project))

        days_ago = options.get("days_ago")
        if not days_ago:
            raise CommandError(
                "You must supply days_ago."
            )
        numdays = options.get("numdays")
        branches = options.get("branches")

        range = utils.get_day_range(days_ago, numdays)
        if branches:
            branches = branches.split(",")
        else:
            branches = pushlog_refdata.get_all_branches()


        stats = pushlog_refdata.get_not_referenced(
            project,
            range["start"],
            range["stop"],
            branches,
            )
        print json.dumps(stats, indent=4)
        return
Esempio n. 11
0
def test_get_runs_by_branch_show_test_runs_true(ptm, plm, client, monkeypatch):
    """
    Test that with show_runs=True that you get the runs and counts
    """
    def mock_plm():
        return plm
    monkeypatch.setattr(factory, 'get_plm', mock_plm)

    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
        ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/perftest/runs_by_branch/?show_test_runs=True&days_ago=6".format(ptm.project)
    response = client.get(url)

    exp = set(["count", "limit", "total_count", "test_runs"])
    assert set(response.json["Mozilla-Aurora"].keys()) == exp
def test_get_error_list(ptm, client, monkeypatch):
    """Get a list of errors from the objectstore in a date range."""

    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
        ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/error_list/?days_ago=4".format(ptm.project)
    response = client.get(url)

    exp = [{
            u"date_loaded": dates[2],
            u"id": 2,
            u"test_run_id": None,
            u"worker_id": None,
            u"processed_flag": u"ready",
            u"error_msg": u"Malformed JSON"
            }]
    assert response.json == exp
def test_get_error_list(ptm, client, monkeypatch):
    """Get a list of errors from the objectstore in a date range."""

    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
    ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/error_list/?days_ago=4".format(ptm.project)
    response = client.get(url)

    exp = [{
        u"date_loaded": dates[2],
        u"id": 2,
        u"test_run_id": None,
        u"worker_id": None,
        u"processed_flag": u"ready",
        u"error_msg": u"Malformed JSON"
    }]
    assert response.json == exp
def test_get_error_count(ptm, client, monkeypatch):
    """Get a count of errors from the objectstore in a date range."""

    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
    ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/error_count/?days_ago=6".format(
        ptm.project)
    response = client.get(url)

    exp = [{
        "count": 1,
        "message": "Malformed JSON"
    }, {
        "count": 1,
        "message": "Other"
    }]

    assert response.json == exp
def test_get_error_count(ptm):
    """Test the get_error_count method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_count(
        ptm.project,
        date_range["start"],
        date_range["stop"],
        )
    exp = (
        {'count': 1L, 'message': u'Malformed JSON'},
        {'count': 1L, 'message': u'Other'},
        )
def test_get_error_count(ptm, client, monkeypatch):
    """Get a count of errors from the objectstore in a date range."""

    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
        ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/error_count/?days_ago=6".format(ptm.project)
    response = client.get(url)

    exp = [
        {
            "count": 1,
            "message": "Malformed JSON"
            },
        {
            "count": 1,
            "message": "Other"
            }]

    assert response.json == exp
def test_get_error_detail_count(ptm):
    """Test get_error_detail_count method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_detail_count(
        ptm.project,
        date_range["start"],
        date_range["stop"],
        )
    exp = {
        'four - Mozilla-Aurora - 14.0a2': 1,
        'one - Mozilla-Aurora - 14.0a2': 1,
        }

    assert result == exp
Esempio n. 18
0
def test_get_error_detail_count(ptm):
    """Test get_error_detail_count method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_detail_count(
        ptm.project,
        date_range["start"],
        date_range["stop"],
    )
    exp = {
        'four - Mozilla-Aurora - 14.0a2': 1,
        'one - Mozilla-Aurora - 14.0a2': 1,
    }

    assert result == exp
Esempio n. 19
0
def test_get_error_count(ptm):
    """Test the get_error_count method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_count(
        ptm.project,
        date_range["start"],
        date_range["stop"],
    )
    exp = (
        {
            'count': 1L,
            'message': u'Malformed JSON'
        },
        {
            'count': 1L,
            'message': u'Other'
        },
    )
    def handle_project(self, project, **options):
        """Count errors of the project grouped by name, branch and version."""

        self.stdout.write("Processing project {0}\n".format(project))

        days_ago = options.get("days_ago")
        if not days_ago:
            raise CommandError(
                "You must supply days_ago."
            )
        numdays = options.get("numdays")

        range = utils.get_day_range(days_ago, numdays)
        if options.get("show_list"):
            err_list = objectstore_refdata.get_error_list(
                project,
                range["start"],
                range["stop"],
                )
            self.stdout.write(json.dumps(err_list, indent=4))

        if options.get("show_simple_count"):
            err_count = objectstore_refdata.get_error_count(
                project,
                range["start"],
                range["stop"],
                )
            self.stdout.write(json.dumps(err_count, indent=4))


        if options.get("show_detail_count"):
            err_count = objectstore_refdata.get_error_detail_count(
                project,
                range["start"],
                range["stop"],
                )
            ptm.disconnect()
            self.stdout.write(json.dumps(err_count, indent=4))
Esempio n. 21
0
def test_get_error_list(ptm):
    """Test the get_error_list method."""

    store_and_process_2_good_2_error_blobs(ptm)
    date_range = get_day_range(1)
    result = objectstore_refdata.get_error_list(
        ptm.project,
        date_range["start"],
        date_range["stop"],
    )
    exp = ({
        'id': 1L,
        'test_run_id': None,
        'worker_id': None,
        'processed_flag': u'ready',
        'error_msg': u'badness'
    }, {
        'id': 2L,
        'test_run_id': None,
        'worker_id': None,
        'processed_flag': u'ready',
        'error_msg': u'Malformed JSON',
    })
Esempio n. 22
0
    def handle_project(self, project, **options):
        """Count errors of the project grouped by name, branch and version."""

        self.stdout.write("Processing project {0}\n".format(project))

        days_ago = options.get("days_ago")
        if not days_ago:
            raise CommandError("You must supply days_ago.")
        numdays = options.get("numdays")

        range = utils.get_day_range(days_ago, numdays)
        if options.get("show_list"):
            err_list = objectstore_refdata.get_error_list(project, range["start"], range["stop"])
            self.stdout.write(json.dumps(err_list, indent=4))

        if options.get("show_simple_count"):
            err_count = objectstore_refdata.get_error_count(project, range["start"], range["stop"])
            self.stdout.write(json.dumps(err_count, indent=4))

        if options.get("show_detail_count"):
            err_count = objectstore_refdata.get_error_detail_count(project, range["start"], range["stop"])
            ptm.disconnect()
            self.stdout.write(json.dumps(err_count, indent=4))
def test_get_json_blob(ptm, client, monkeypatch):
    """Fetch JSON for an ID that has good JSON."""
    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
    ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/json_blob/3/".format(ptm.project)
    response = client.get(url)

    exp_tm = {
        u"platform": u"x86_64",
        u"osversion": u"Ubuntu 11.10",
        u"os": u"linux",
        u"name": u"qm-pxp01"
    }

    exp_tb = {
        u"version": u"14.0a2",
        u"revision": u"785345035a3b",
        u"name": u"one",
        u"branch": u"Mozilla-Aurora",
    }
    exp_tr = {
        u"date": dates[1],
        u"suite": u"Talos tp5r",
        u"options": {
            u"responsiveness": u"false",
            u"tpmozafterpaint": u"false",
            u"tpdelay": u"",
            u"tpchrome": u"true",
            u"tppagecycles": u"1",
            u"tpcycles": u"3",
            u"tprender": u"false",
            u"shutdown": u"true",
            u"rss": u"true"
        }
    }
    exp_ra = {
        u"three.com": [789.0, 705.0, 739.0],
        u"one.com": [789.0, 705.0, 739.0],
        u"two.com": [789.0, 705.0, 739.0]
    }
    exp_res = {
        u"three.com": [789.0, 705.0, 739.0],
        u"one.com": [789.0, 705.0, 739.0],
        u"two.com": [789.0, 705.0, 739.0]
    }

    rj = response.json

    assert rj['json_blob']['test_machine'] == exp_tm

    # these ids can vary
    del (rj['json_blob']['test_build']['id'])

    assert rj['json_blob']['test_build'] == exp_tb
    assert rj['json_blob']['testrun'] == exp_tr
    assert rj['json_blob']['results_aux'] == exp_ra
    assert rj['json_blob']['results'] == exp_res
def test_get_json_blob(ptm, client, monkeypatch):
    """Fetch JSON for an ID that has good JSON."""
    dates = [
        utils.get_day_range(5)["start"],
        utils.get_day_range(4)["start"],
        utils.get_day_range(3)["start"],
        ]
    create_date_based_data(ptm, monkeypatch, dates)
    url = "/{0}/refdata/objectstore/json_blob/3/".format(ptm.project)
    response = client.get(url)

    exp_tm = {
        u"platform": u"x86_64",
        u"osversion": u"Ubuntu 11.10",
        u"os": u"linux",
        u"name": u"qm-pxp01"
        }

    exp_tb = {
        u"version": u"14.0a2",
        u"revision": u"785345035a3b",
        u"name": u"one",
        u"branch": u"Mozilla-Aurora",
        }
    exp_tr = {
        u"date": dates[1],
        u"suite": u"Talos tp5r",
        u"options": {
            u"responsiveness": u"false",
            u"tpmozafterpaint": u"false",
            u"tpdelay": u"",
            u"tpchrome": u"true",
            u"tppagecycles": u"1",
            u"tpcycles": u"3",
            u"tprender": u"false",
            u"shutdown": u"true",
            u"rss": u"true"
        }}
    exp_ra = {
        u"three.com": [
            789.0,
            705.0,
            739.0
        ],
        u"one.com": [
            789.0,
            705.0,
            739.0
        ],
        u"two.com": [
            789.0,
            705.0,
            739.0
        ]}
    exp_res = {
        u"three.com": [
            789.0,
            705.0,
            739.0
        ],
        u"one.com": [
            789.0,
            705.0,
            739.0
        ],
        u"two.com": [
            789.0,
            705.0,
            739.0
        ]}

    rj = response.json

    assert rj['json_blob']['test_machine'] == exp_tm

    # these ids can vary
    del(rj['json_blob']['test_build']['id'])

    assert rj['json_blob']['test_build'] == exp_tb
    assert rj['json_blob']['testrun'] == exp_tr
    assert rj['json_blob']['results_aux'] == exp_ra
    assert rj['json_blob']['results'] == exp_res