Example #1
0
def calculate_MTTR(path_to_git_repo, deploy_pattern, patch_pattern,
                   start_date):
    run = mk_run(path_to_git_repo)
    match_deploy = partial(fnmatch, pat=deploy_pattern)
    match_patch = partial(fnmatch, pat=patch_pattern)
    deploy_tags_author_date = fetch_tags_and_author_dates(
        run,
        match_deploy,
        start_date,
    )
    deploy_tags_commit_date = dict(fetch_tags_and_sha(run, match_deploy))
    patch_dates = set(date
                      for _tag, date in fetch_tags_and_sha(run, match_patch))
    deployments = []
    for deploy_tag, deploy_date in deploy_tags_author_date:
        is_patch = find_is_patch(deploy_tag, deploy_tags_commit_date,
                                 patch_dates)
        deployments.append(Deployment(is_patch, deploy_date))
    outages = find_outages(deployments)
    downtime = (end.time - start.time for start, end in outages)
    return statistics.mean(downtime)
def test_empty_tags_gives_empty_recoveries():
    results = find_outages([])
    assert results == []
def test_begin_with_patch():
    results = find_outages([patch_one, deployment_two, patch_three])
    assert results == [(deployment_two, patch_three)]
def test_two_outage_two_patches():
    results = find_outages(
        [deployment_zero, patch_one, deployment_two, patch_three])
    assert results == [(deployment_zero, patch_one),
                       (deployment_two, patch_three)]
def test_one_outage_two_patches():
    patch_two = Deployment(True, 2)
    results = find_outages([deployment_zero, patch_one, patch_two])
    assert results == [(deployment_zero, patch_two)]
def test_one_simple_outage():
    results = find_outages([deployment_zero, patch_one])
    assert results == [(deployment_zero, patch_one)]