예제 #1
0
def test_very_long_job_name():
    config_path = 'config/nebuchadnezzar.yml'
    config_name = config_path.replace('config/', '')
    config_lookback = 0  # in minutes
    args = [config_name]
    runner = BuildConnectorRunner(args)
    config = runner.getConfiguration(config_path)

    connector = BLDConnector(config, runner.log)
    agicen = connector.agicen_conn

    # see if a BuildDefinition exists in AgileCentral whose Name contains '/job/Marduk-apla-iddina%20II/'
    # if so, delete it
    funky_job_name = '/job/Marduk-apla-iddina%20II/'
    response = agicen.agicen.get('BuildDefinition', query='Name contains "%s"' % funky_job_name)
    for build_def in response:
        agicen.agicen.delete('BuildDefinition', build_def.ObjectID)

    project = 'Dunder Donut'
    path = 'http://tiema03-u183073.ca.com:8080/job/Zoolander/job/Apatosaurus/job/Brachiosaurus/job/Compsognathus/job/TorturedCircularLogicThatIsOrbulentAndVeryRoundishlyCircular/job/Babylon/job/Nebuchadnezzar%20III/job/AndHisKids-Shmeb-Dolly-PollyanaBillyJoe-Zukobnitsche/job/Marduk-apla-iddina%20II/'
    scm = 'git'
    build_defn = agicen.ensureBuildDefinitionExists(path, project, scm)
    print(path[-40:])
    print(build_defn.Name[-40:])
    assert build_defn
    assert build_defn.Name.endswith(funky_job_name)
    assert len(build_defn.Name) == 256
    print(build_defn.Name)

    build_defn2 = agicen.ensureBuildDefinitionExists(path, project, scm)
    assert build_defn2.oid == build_defn.oid

    response = agicen.agicen.get('BuildDefinition', query='Name contains "%s"' % funky_job_name)
    for build_def in response:
        agicen.agicen.delete('BuildDefinition', build_def.ObjectID)
예제 #2
0
def get_bld_connector(config_file):
    try:
        config_path = 'config/%s' % config_file
        config_name = config_path.replace('config/', '')
        args = [config_name]
        runner = BuildConnectorRunner(args)
        config = runner.getConfiguration(config_path)
        connector = BLDConnector(config, runner.log)
        return connector
    except Exception as msg:
        print('Oh noes! %s' % msg)
        raise
예제 #3
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
예제 #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
예제 #5
0
def test_existing_job():
    ref_time = datetime.utcnow() - timedelta(minutes=2)
    config_file = "koalas.yml"
    folder = "koalas"
    my_job = "lunch"
    other_job = "dinner"
    conf = read_config(config_file)
    jenk_conf = conf['JenkinsBuildConnector']['Jenkins']
    jenk_url  = construct_jenkins_url(jenk_conf)

    r1 = build(jenk_conf, jenk_url, my_job, folder=folder)
    assert r1.status_code in [200, 201]
    time.sleep(15)

    args = [config_file]
    runner = BuildConnectorRunner(args)
    assert runner.first_config == config_file
    config_path = "config/{}".format(config_file)
    config = runner.getConfiguration(config_path)

    assert config_file in runner.config_file_names

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

    jenk_builds = connector.bld_conn.getRecentBuilds(ref_time.utctimetuple())

    jobs_snarfed = []
    jenk_builds_snarfed = []
    for container_proj, build_info in jenk_builds.items():
        print (container_proj)
        for job, builds in build_info.items():
            jobs_snarfed.append(job)
            jenk_builds_snarfed.extend(builds)
            print (builds)

    job_names = [job.name for job in jobs_snarfed]
    assert my_job in job_names
    assert other_job in job_names

    jenk_build_names = [build.name for build in jenk_builds_snarfed]
    assert not other_job in jenk_build_names
    assert my_job in job_names
예제 #6
0
def test_existing_job():
    ref_time = datetime.utcnow() - timedelta(minutes=2)
    config_file = "koalas.yml"
    folder = "koalas"
    my_job = "lunch"
    other_job = "dinner"
    conf = read_config(config_file)
    jenk_conf = conf['JenkinsBuildConnector']['Jenkins']
    jenk_url = construct_jenkins_url(jenk_conf)

    r1 = build(jenk_conf, jenk_url, my_job, folder=folder)
    assert r1.status_code in [200, 201]
    time.sleep(15)

    args = [config_file]
    runner = BuildConnectorRunner(args)
    assert runner.first_config == config_file
    config_path = "config/{}".format(config_file)
    config = runner.getConfiguration(config_path)

    assert config_file in runner.config_file_names

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

    jenk_builds = connector.bld_conn.getRecentBuilds(ref_time.utctimetuple())

    jobs_snarfed = []
    jenk_builds_snarfed = []
    for container_proj, build_info in jenk_builds.items():
        print(container_proj)
        for job, builds in build_info.items():
            jobs_snarfed.append(job)
            jenk_builds_snarfed.extend(builds)
            print(builds)

    job_names = [job.name for job in jobs_snarfed]
    assert my_job in job_names
    assert other_job in job_names

    jenk_build_names = [build.name for build in jenk_builds_snarfed]
    assert not other_job in jenk_build_names
    assert my_job in job_names
예제 #7
0
def test_very_long_job_name():
    config_path = 'config/nebuchadnezzar.yml'
    config_name = config_path.replace('config/', '')
    config_lookback = 0  # in minutes
    args = [config_name]
    runner = BuildConnectorRunner(args)
    config = runner.getConfiguration(config_path)

    connector = BLDConnector(config, runner.log)
    agicen = connector.agicen_conn

    # see if a BuildDefinition exists in AgileCentral whose Name contains '/job/Marduk-apla-iddina%20II/'
    # if so, delete it
    funky_job_name = '/job/Marduk-apla-iddina%20II/'
    response = agicen.agicen.get('BuildDefinition',
                                 query='Name contains "%s"' % funky_job_name)
    for build_def in response:
        agicen.agicen.delete('BuildDefinition', build_def.ObjectID)

    project = 'Dunder Donut'
    path = 'http://tiema03-u183073.ca.com:8080/job/Zoolander/job/Apatosaurus/job/Brachiosaurus/job/Compsognathus/job/TorturedCircularLogicThatIsOrbulentAndVeryRoundishlyCircular/job/Babylon/job/Nebuchadnezzar%20III/job/AndHisKids-Shmeb-Dolly-PollyanaBillyJoe-Zukobnitsche/job/Marduk-apla-iddina%20II/'
    scm = 'git'
    build_defn = agicen.ensureBuildDefinitionExists(path, project, scm)
    print(path[-40:])
    print(build_defn.Name[-40:])
    assert build_defn
    assert build_defn.Name.endswith(funky_job_name)
    assert len(build_defn.Name) == 256
    print(build_defn.Name)

    build_defn2 = agicen.ensureBuildDefinitionExists(path, project, scm)
    assert build_defn2.oid == build_defn.oid

    response = agicen.agicen.get('BuildDefinition',
                                 query='Name contains "%s"' % funky_job_name)
    for build_def in response:
        agicen.agicen.delete('BuildDefinition', build_def.ObjectID)