Exemplo n.º 1
0
def build_immovable_wombats(folder, jobs):

    config = "config/buildorama.yml"
    logger, tkonf = setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    agicen_konf = tkonf.topLevel('AgileCentral')
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)
    tkonf.add_to_container({
        'Folder': folder,
        'AgileCentral_Project': 'Static',
        'exclude': jobs[1]
    })
    tkonf.remove_from_container({'Folder': 'Parkour'})
    tkonf.remove_from_container({'View': 'Prairie'})
    tkonf.remove_from_container({'View': 'Shoreline'})
    tkonf.remove_from_container({'Job': 'troglodyte'})
    tkonf.remove_from_container({'Job': 'truculent elk medallions'})
    assert folder in [
        folder_rec['Folder'] for folder_rec in jenk_conf['Folders']
    ]

    for job in jobs:
        r = jsh.build(jenk_conf, jenkins_url, job, folder=folder)

    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()

    return jc
Exemplo n.º 2
0
def test_find_builds_of_two_jobs():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    job1 = "troblodyte{}".format(time.time())
    job2 = "fukebane{}".format(time.time())
    two_jobs = [job1, job2]
    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)

    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.create_job(jenk_conf, jenkins_url, job1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job1})

    r1 = jsh.create_job(jenk_conf, jenkins_url, job2)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job2})

    # create two build for the same job
    r2 = jsh.build(jenk_conf, jenkins_url, job1)
    assert r2.status_code in [200, 201]
    time.sleep(10)
    r2 = jsh.build(jenk_conf, jenkins_url, job2)
    assert r2.status_code in [200, 201]

    time.sleep(10)
    # find two builds
    target_job_builds = []
    time.sleep(10)
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)


    view = 'All'  # because we created the two jobs at the top level
    bkey = "%s::%s" % (view, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[bkey]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs = [job for job in target_builds if job.name in [job1, job2]]


    # for key, val in builds.items():
    #     print(key)
    #     # for k, v in val.items():
    #     #    print("...k: %s, v: %s" % (k, v))
    #     for builds in val.values():
    #         for build in builds:
    #             print("    %s" % build)

    assert len(build_jobs) == 2

    # delete the jobs
    for job_name in two_jobs:
        r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name)
        assert r3.status_code == 200
Exemplo n.º 3
0
def test_find_builds_of_two_jobs():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    job1 = "troblodyte{}".format(time.time())
    job2 = "fukebane{}".format(time.time())
    two_jobs = [job1, job2]
    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)

    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.create_job(jenk_conf, jenkins_url, job1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job1})

    r1 = jsh.create_job(jenk_conf, jenkins_url, job2)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job2})

    # create two build for the same job
    r2 = jsh.build(jenk_conf, jenkins_url, job1)
    assert r2.status_code in [200, 201]
    time.sleep(10)
    r2 = jsh.build(jenk_conf, jenkins_url, job2)
    assert r2.status_code in [200, 201]

    time.sleep(10)
    # find two builds
    target_job_builds = []
    time.sleep(10)
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)

    view = 'All'  # because we created the two jobs at the top level
    bkey = "%s::%s" % (view, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[
        bkey]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs = [job for job in target_builds if job.name in [job1, job2]]

    # for key, val in builds.items():
    #     print(key)
    #     # for k, v in val.items():
    #     #    print("...k: %s, v: %s" % (k, v))
    #     for builds in val.values():
    #         for build in builds:
    #             print("    %s" % build)

    assert len(build_jobs) == 2

    # delete the jobs
    for job_name in two_jobs:
        r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name)
        assert r3.status_code == 200
Exemplo n.º 4
0
def test_identify_unrecorded_builds():
    config_path = 'config/dupes.yml'
    config_name = config_path.replace('config/', '')
    config_lookback = 0  # in minutes
    last_run_zulu = create_time_file(config_name, minutes=1)
    t = int(time.mktime(time.strptime(
        last_run_zulu, '%Y-%m-%d %H:%M:%S Z'))) - config_lookback
    last_run_minus_lookback_zulu = time.strftime('%Y-%m-%dT%H:%M:%SZ',
                                                 time.localtime(t))
    args = [config_name]
    runner = BuildConnectorRunner(args)
    config = runner.getConfiguration(config_path)

    job_name = 'black-swan-2'
    folder1 = 'Parkour'
    folder2 = 'abacab/job/bontamy'
    jenk_conf = config.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.build(jenk_conf, jenkins_url, job_name)
    assert r1.status_code in [200, 201]
    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r2.status_code in [200, 201]
    r3 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r3.status_code in [200, 201]
    time.sleep(45)

    connector = BLDConnector(config, runner.log)
    connector.validate()

    print("our ref time: %s" % last_run_minus_lookback_zulu)
    agicen_ref_time = bld_ref_time = time.localtime(t)
    recent_agicen_builds = connector.agicen_conn.getRecentBuilds(
        agicen_ref_time, connector.target_projects)
    recent_bld_builds = connector.bld_conn.getRecentBuilds(bld_ref_time)
    unrecorded_builds = connector._identifyUnrecordedBuilds(
        recent_agicen_builds, recent_bld_builds)
    runner.log.info("unrecorded Builds count: %d" % len(unrecorded_builds))

    # sort the unrecorded_builds into build chrono order, oldest to most recent, then project and job
    unrecorded_builds.sort(key=lambda build_info: (build_info[
        1].timestamp, build_info[2], build_info[1]))
    paths = []
    for job, build, project, view in unrecorded_builds:
        print("build %s" % build)
        paths.append(job.fully_qualified_path())

    assert 'tiema03-u183073.ca.com:8080/job/abacab/job/bontamy/view/dark flock/job/black-swan-2' in paths
    assert 'tiema03-u183073.ca.com:8080/job/black-swan-2' in paths
    assert 'tiema03-u183073.ca.com:8080/job/Parkour/job/black-swan-2' in paths
Exemplo n.º 5
0
def test_identify_unrecorded_builds():
    config_path = 'config/dupes.yml'
    config_name = config_path.replace('config/', '')
    config_lookback = 0 # in minutes
    last_run_zulu = create_time_file(config_name, minutes=1)
    t = int(time.mktime(time.strptime(last_run_zulu, '%Y-%m-%d %H:%M:%S Z'))) - config_lookback
    last_run_minus_lookback_zulu = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(t))
    args = [config_name]
    runner = BuildConnectorRunner(args)
    config = runner.getConfiguration(config_path)

    job_name = 'black-swan-2'
    folder1 = 'Parkour'
    folder2 = 'abacab/job/bontamy'
    jenk_conf = config.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.build(jenk_conf, jenkins_url, job_name)
    assert r1.status_code in [200, 201]
    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r2.status_code in [200, 201]
    r3 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r3.status_code in [200, 201]
    time.sleep(45)

    connector = BLDConnector(config, runner.log)
    connector.validate()

    print("our ref time: %s" % last_run_minus_lookback_zulu)
    agicen_ref_time = bld_ref_time = time.localtime(t)
    recent_agicen_builds = connector.agicen_conn.getRecentBuilds(agicen_ref_time, connector.target_projects)
    recent_bld_builds = connector.bld_conn.getRecentBuilds(bld_ref_time)
    unrecorded_builds = connector._identifyUnrecordedBuilds(recent_agicen_builds, recent_bld_builds)
    runner.log.info("unrecorded Builds count: %d" % len(unrecorded_builds))

    # sort the unrecorded_builds into build chrono order, oldest to most recent, then project and job
    unrecorded_builds.sort(key=lambda build_info: (build_info[1].timestamp, build_info[2], build_info[1]))
    paths = []
    for job, build, project, view in unrecorded_builds:
        print ("build %s" % build)
        paths.append(job.fully_qualified_path())

    assert 'tiema03-u183073.ca.com:8080/job/abacab/job/bontamy/view/dark flock/job/black-swan-2' in paths
    assert 'tiema03-u183073.ca.com:8080/job/black-swan-2' in paths
    assert 'tiema03-u183073.ca.com:8080/job/Parkour/job/black-swan-2' in paths
Exemplo n.º 6
0
def test_folder_config():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    folder = "A{}".format(time.time())
    job_name = "frog"

    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    # create a jenkins folder and a job in the folder
    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r1.status_code in [200, 201]

    # build in jenkins
    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    tkonf.topLevel(
        'Jenkins')['AgileCentral_DefaultBuildProject'] = 'Dunder Donut'
    tkonf.add_to_container({'Folder': folder})
    assert tkonf.has_item('Folder', folder)

    jenk_conf = tkonf.topLevel('Jenkins')
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)
    bkey = "%s::%s" % (folder, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[
        bkey]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs = [job for job in target_builds if job.name == job_name]
    assert len(build_jobs) == 1

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder)
    assert r3.status_code == 200
Exemplo n.º 7
0
def test_folder_config():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    folder = "A{}".format(time.time())
    job_name = "frog"

    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    # create a jenkins folder and a job in the folder
    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r1.status_code in [200, 201]

    # build in jenkins
    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    tkonf.topLevel('Jenkins')['AgileCentral_DefaultBuildProject'] = 'Dunder Donut'
    tkonf.add_to_container({'Folder': folder})
    assert tkonf.has_item('Folder', folder)

    jenk_conf = tkonf.topLevel('Jenkins')
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)
    bkey = "%s::%s" % (folder, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[bkey]   # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs = [job for job in target_builds if job.name == job_name]
    assert len(build_jobs) == 1

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder)
    assert r3.status_code == 200
Exemplo n.º 8
0
def jenkins_job_lifecycle(job_name, config, view="All", folder=None):
    """
       Given a job name and a config dictionary, create a Job for the job name,
       simulate a build, run the part of the bldeif connector that will detect the job
       and then delete the job.
    """
    logger, konf = sh.setup_config(config)
    assert konf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = konf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, view, folder)
    assert r1.status_code in  [200, 201]

    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r2.status_code in  [200, 201]

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r3.status_code == 200

    return True
Exemplo n.º 9
0
def jenkins_job_lifecycle(job_name, config, view="All", folder=None):
    """
       Given a job name and a config dictionary, create a Job for the job name,
       simulate a build, run the part of the bldeif connector that will detect the job
       and then delete the job.
    """
    logger, konf = sh.setup_config(config)
    assert konf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = konf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, view, folder)
    assert r1.status_code in [200, 201]

    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r2.status_code in [200, 201]

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder)
    assert r3.status_code == 200

    return True
Exemplo n.º 10
0
def build_immovable_wombats(folder, jobs):

    config = "config/buildorama.yml"
    logger, tkonf = setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    agicen_konf = tkonf.topLevel('AgileCentral')
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)
    tkonf.add_to_container({'Folder': folder, 'AgileCentral_Project': 'Static', 'exclude': jobs[1]})
    tkonf.remove_from_container({'Folder': 'Parkour'})
    tkonf.remove_from_container({'View': 'Prairie'})
    tkonf.remove_from_container({'View': 'Shoreline'})
    tkonf.remove_from_container({'Job': 'troglodyte'})
    tkonf.remove_from_container({'Job': 'truculent elk medallions'})
    assert folder in [folder_rec['Folder'] for folder_rec in jenk_conf['Folders']]

    for job in jobs:
        r = jsh.build(jenk_conf, jenkins_url, job, folder=folder)

    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()

    return jc
Exemplo n.º 11
0
def test_find_builds_in_different_containers():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    folder1 = "friendly amphibian{}".format(time.time())
    folder2 = "unfriendly amphibian{}".format(time.time())

    job1 = "naked-troblodyte{}".format(time.time())
    job2 = "foldered-fukebane{}".format(time.time())
    job3 = "ignore-it{}".format(time.time())

    three_jobs = [job1, job2, job3]
    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)

    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder1)
    assert r0.status_code in [200, 201]

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder2)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job1})

    r1 = jsh.create_job(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Folder': folder1})

    # create a job in a folder in Jenkins but do not add this folder name to config
    r1 = jsh.create_job(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r1.status_code in [200, 201]

    # check if new containers were added
    assert tkonf.has_item('Folder', folder1)
    #assert tkonf.has_item('Folder', folder2)

    # create two builds for the same job
    r2 = jsh.build(jenk_conf, jenkins_url, job1)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    # find two builds: a build for job3 should not be found
    target_job_builds = []
    time.sleep(10)
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)

    view = 'All'

    bkey1 = "%s::%s" % (view, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[bkey1]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs1 = [job for job in target_builds if job.name == job1]

    bkey2 = "%s::%s" % (folder1, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[bkey2]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs2 = [job for job in target_builds if job.name == job2]

    bkey3 = "%s::%s" % (folder2, jenk_conf['AgileCentral_DefaultBuildProject'])
    assert bkey3 not in builds
    #target_builds = builds[bkey3]  # target_builds is a dict keyed by a JenkinsJob instance
    #build_jobs3 = [job for job in target_builds if job.name == job3]


    # for key, val in builds.items():
    #     print("key: %s, val: %s" % (key, val))
    #     print(key)
    #     # for k, v in val.items():
    #     #    print("...k: %s, v: %s" % (k, v))
    #     for builds in val.values():
    #         for build in builds:
    #             print("    %s" % build)

    assert len(build_jobs1) == 1
    assert len(build_jobs2) == 1

    # delete the jobs

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder2)
    assert r3.status_code == 200
Exemplo n.º 12
0
def test_same_name_jobs_in_diff_folders():
    folder1 = "A1{}".format(time.time())
    folder2 = "A2{}".format(time.time())
    job_name = "frog"

    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    agicen_konf = tkonf.topLevel('AgileCentral')
    agicen_konf['Workspace'] = 'Alligators BLD Unigrations'
    tkonf.topLevel('Jenkins')['AgileCentral_DefaultBuildProject'] = 'Jenkins'
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder1)
    assert r0.status_code in [200, 201]
    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder2)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r1.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r1.status_code in [200, 201]

    tkonf.add_to_container({
        'Folder': folder1,
        'AgileCentral_Project': 'Dunder Donut'
    })
    tkonf.add_to_container({
        'Folder': folder2,
        'AgileCentral_Project': 'Corral'
    })
    tkonf.remove_from_container({'Folder': 'Parkour'})
    tkonf.remove_from_container({'View': 'Shoreline'})
    tkonf.remove_from_container({'Job': 'truculent elk medallions'})

    assert tkonf.has_item('Folder', folder1)
    assert tkonf.has_item('Folder', folder2)
    assert tkonf.has_item('Folder', 'Parkour') == False

    ref_time = datetime.now() - timedelta(minutes=5)

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r1.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    assert folder1 in [
        folder_rec['Folder'] for folder_rec in jenk_conf['Folders']
    ]
    assert folder2 in [
        folder_rec['Folder'] for folder_rec in jenk_conf['Folders']
    ]
    assert 'Parkour' not in [
        folder_rec['Folder'] for folder_rec in jenk_conf['Folders']
    ]

    # find two builds
    target_job_builds = []
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    jenkins_builds = jc.getRecentBuilds(ref_time.utctimetuple())

    bc = bsh.BLDConnector(tkonf, logger)
    query = ['CreationDate >= %s' % ref_time.isoformat()]
    for view_proj, build_view in jenkins_builds.items():
        print(view_proj)
        for builds in build_view.values():
            for bld in builds:
                print("    %s" % bld)
                project = view_proj.split('::')[1]
                print("PROJECT %s" % project)
                build_defn = bc.agicen_conn.ensureBuildDefinitionExists(
                    job_name, project, bld.url)
                assert build_defn.Project.Name == project
                agicen_build, status = bc.postBuildToAgileCentral(
                    build_defn, bld, [], job_name)
                assert agicen_build is not None
                assert agicen_build.BuildDefinition.Project.Name == project
                ac_response = bc.agicen_conn._retrieveBuilds(project, query)
                for build in ac_response:
                    print("    %24.24s Job Name: %24.24s build number: %s " %
                          (build.BuildDefinition.Project.Name,
                           build.BuildDefinition.Name, build.Number))
                    if build.BuildDefinition.Project.Name != project:
                        for proj in bc.agicen_conn.build_def.keys():
                            print("build_defn project: %s" % proj)
                            project_jobs = bc.agicen_conn.build_def[proj].keys(
                            )
                            for job in project_jobs:
                                print("    %s:   %s" %
                                      (job, bc.agicen_conn.build_def[proj]
                                       [job].Project.Name))
                    assert (build.BuildDefinition.Project.Name) == project
                    assert (build.BuildDefinition.Name) == job_name

    # delete the jobs

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder2)
    assert r3.status_code == 200
Exemplo n.º 13
0
def test_same_name_jobs_in_diff_folders():
    folder1  = "A1{}".format(time.time())
    folder2  = "A2{}".format(time.time())
    job_name = "frog"

    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    agicen_konf =  tkonf.topLevel('AgileCentral')
    agicen_konf['Workspace'] = 'Alligators BLD Unigrations'
    tkonf.topLevel('Jenkins')['AgileCentral_DefaultBuildProject'] = 'Jenkins'
    jenk_conf = tkonf.topLevel('Jenkins')
    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder1)
    assert r0.status_code in [200, 201]
    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder2)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r1.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r1.status_code in [200, 201]

    tkonf.add_to_container({'Folder': folder1, 'AgileCentral_Project': 'Dunder Donut'})
    tkonf.add_to_container({'Folder': folder2, 'AgileCentral_Project': 'Corral'})
    tkonf.remove_from_container({'Folder' : 'Parkour'})
    tkonf.remove_from_container({'View': 'Shoreline'})
    tkonf.remove_from_container({'Job': 'truculent elk medallions'})

    assert tkonf.has_item('Folder', folder1)
    assert tkonf.has_item('Folder', folder2)
    assert tkonf.has_item('Folder', 'Parkour') == False

    ref_time = datetime.now() - timedelta(minutes=5)

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r1 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r1.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    assert folder1 in [folder_rec['Folder'] for folder_rec  in jenk_conf['Folders']]
    assert folder2 in [folder_rec['Folder'] for folder_rec  in jenk_conf['Folders']]
    assert 'Parkour' not in [folder_rec['Folder'] for folder_rec  in jenk_conf['Folders']]

    # find two builds
    target_job_builds = []
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    jenkins_builds = jc.getRecentBuilds(ref_time.utctimetuple())

    bc = bsh.BLDConnector(tkonf, logger)
    query = ['CreationDate >= %s' % ref_time.isoformat()]
    for view_proj, build_view in jenkins_builds.items():
        print(view_proj)
        for builds in build_view.values():
            for bld in builds:
                print("    %s" % bld)
                project = view_proj.split('::')[1]
                print ("PROJECT %s" %project)
                build_defn = bc.agicen_conn.ensureBuildDefinitionExists(job_name, project, bld.url)
                assert build_defn.Project.Name == project
                agicen_build, status = bc.postBuildToAgileCentral(build_defn, bld, [], job_name)
                assert agicen_build is not None
                assert agicen_build.BuildDefinition.Project.Name == project
                ac_response = bc.agicen_conn._retrieveBuilds(project, query)
                for build in ac_response:
                    print("    %24.24s Job Name: %24.24s build number: %s " % (build.BuildDefinition.Project.Name, build.BuildDefinition.Name, build.Number))
                    if build.BuildDefinition.Project.Name != project:
                        for proj in bc.agicen_conn.build_def.keys():
                            print("build_defn project: %s" % proj)
                            project_jobs = bc.agicen_conn.build_def[proj].keys()
                            for job in project_jobs:
                                print("    %s:   %s" % (job, bc.agicen_conn.build_def[proj][job].Project.Name))
                    assert (build.BuildDefinition.Project.Name) == project
                    assert (build.BuildDefinition.Name) == job_name

    # delete the jobs

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job_name, folder=folder2)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder2)
    assert r3.status_code == 200
Exemplo n.º 14
0
def test_find_builds_in_different_containers():
    t = datetime.now() - timedelta(minutes=60)
    ref_time = t.utctimetuple()
    folder1 = "friendly amphibian{}".format(time.time())
    folder2 = "unfriendly amphibian{}".format(time.time())

    job1 = "naked-troblodyte{}".format(time.time())
    job2 = "foldered-fukebane{}".format(time.time())
    job3 = "ignore-it{}".format(time.time())

    three_jobs = [job1, job2, job3]
    config = "config/buildorama.yml"
    logger, tkonf = sh.setup_test_config(config)

    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    jenk_conf = tkonf.topLevel('Jenkins')

    jenkins_url = jsh.construct_jenkins_url(jenk_conf)

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder1)
    assert r0.status_code in [200, 201]

    r0 = jsh.create_folder(jenk_conf, jenkins_url, folder2)
    assert r0.status_code in [200, 201]

    r1 = jsh.create_job(jenk_conf, jenkins_url, job1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Job': job1})

    r1 = jsh.create_job(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r1.status_code in [200, 201]
    tkonf.add_to_container({'Folder': folder1})

    # create a job in a folder in Jenkins but do not add this folder name to config
    r1 = jsh.create_job(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r1.status_code in [200, 201]

    # check if new containers were added
    assert tkonf.has_item('Folder', folder1)
    #assert tkonf.has_item('Folder', folder2)

    # create two builds for the same job
    r2 = jsh.build(jenk_conf, jenkins_url, job1)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    r2 = jsh.build(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r2.status_code in [200, 201]
    time.sleep(10)

    # find two builds: a build for job3 should not be found
    target_job_builds = []
    time.sleep(10)
    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    jc.validate()
    builds = jc.getRecentBuilds(ref_time)

    view = 'All'

    bkey1 = "%s::%s" % (view, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[
        bkey1]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs1 = [job for job in target_builds if job.name == job1]

    bkey2 = "%s::%s" % (folder1, jenk_conf['AgileCentral_DefaultBuildProject'])
    target_builds = builds[
        bkey2]  # target_builds is a dict keyed by a JenkinsJob instance
    build_jobs2 = [job for job in target_builds if job.name == job2]

    bkey3 = "%s::%s" % (folder2, jenk_conf['AgileCentral_DefaultBuildProject'])
    assert bkey3 not in builds
    #target_builds = builds[bkey3]  # target_builds is a dict keyed by a JenkinsJob instance
    #build_jobs3 = [job for job in target_builds if job.name == job3]

    # for key, val in builds.items():
    #     print("key: %s, val: %s" % (key, val))
    #     print(key)
    #     # for k, v in val.items():
    #     #    print("...k: %s, v: %s" % (k, v))
    #     for builds in val.values():
    #         for build in builds:
    #             print("    %s" % build)

    assert len(build_jobs1) == 1
    assert len(build_jobs2) == 1

    # delete the jobs

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job2, folder=folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, job3, folder=folder2)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder1)
    assert r3.status_code == 200

    r3 = jsh.delete_job(jenk_conf, jenkins_url, folder2)
    assert r3.status_code == 200