Exemplo n.º 1
0
        artifact_name = package + "-" + re.sub("[\-\.]*redhat\-\d+", "", version) + sufix

        #WA for subfolder builds (? in SCM url)
        if "?" in scm_repo_url:
            folder = scm_repo_url[scm_repo_url.index('?')+1:]
            scm_repo_url = scm_repo_url[:scm_repo_url.index('?')]
            if 'maven_options' not in art_params['options'].keys():
                art_params['options']['maven_options'] = []
            art_params['options']['maven_options'].append("-f./"+folder+"/pom.xml")
            if 'properties' not in art_params['options'].keys():
                art_params['options']['properties'] = {}
            art_params['options']['properties']['exec_folder'] = folder

        #Lookup or create a Project
        try:
            project = projects.get_project_raw(name=project_name)
        except ValueError:
            logging.debug('No project ' + project_name + ". Creating a new one")
            project = projects.create_project_raw(name=project_name)
        logging.debug(artifact_name + ":")
        logging.debug(project.id)

        #Lookup or update or create Build Config
        build_config = get_build_configuration_by_name(artifact_name)
        if subartifact in look_up_only_list:
            if build_config == None:
                pprint("Look up of an existing Build Configuration failed. No build configuration with name " + artifact_name + " found.")
        else:
            if build_config == None:
                logging.debug('No build config with name ' + artifact_name)
                build_config = create_build_configuration(environment, bc_set, product_version_id, art_params, scm_repo_url,
Exemplo n.º 2
0
def make_mead_impl(config, run_build, environment, suffix, product_name,
                   product_version, look_up_only, clean_group):
    if not validate_input_parameters(config, product_name, product_version):
        return 1

    try:
        config_reader = ConfigReader(config)
    except NoSectionError as e:
        logging.error('Missing config in %s (%r)', config, e)
        return 1
    except Error as err:
        logging.error(err)
        return 1

    ids = dict()
    (subarts, deps_dict) = config_reader.get_dependency_structure()
    packages = config_reader.get_packages_and_dependencies()
    logging.debug(packages)
    logging.debug(subarts)
    logging.debug(deps_dict)

    product_version_id = get_product_version(product_name, product_version)
    if product_version_id is None:
        return 1

    # Get environment
    env = environments.get_environment_raw(environment)
    if not env:
        logging.error('Environment with id %d not found', environment)
        return 1

    #Create a list for look-up-only
    look_up_only_list = look_up_only.split(",")

    #Lookup or create Build Configuration Set
    target_name = product_name + "-" + product_version + "-all" + suffix
    try:
        bc_set = buildconfigurationsets.get_build_configuration_set_raw(
            name=target_name)
        if clean_group:
            for bc_id in bc_set.build_configuration_ids:
                buildconfigurationsets.remove_build_configuration_from_set_raw(
                    set_id=bc_set.id, config_id=bc_id)
    except ValueError:
        bc_set = buildconfigurationsets.create_build_configuration_set_raw(
            name=target_name, product_version_id=product_version_id)
    logging.debug(target_name + ":")
    logging.debug(bc_set.id)

    #Iterate through all sections in configuration file
    for subartifact in subarts:
        art_params = config_reader.get_config(subartifact)
        logging.debug(art_params)
        artifact = art_params['artifact']
        if 'pnc.projectName' in art_params.keys():
            logging.debug("Overriding project name with " +
                          art_params['pnc.projectName'])
            project_name = art_params['pnc.projectName']
        else:
            logging.debug("Using default project name " + artifact)
            project_name = artifact

        logging.debug(art_params)
        package = art_params['package']
        version = art_params['version']
        scm_url = art_params['scmURL']
        (scm_repo_url, scm_revision) = scm_url.split("#", 2)
        artifact_name = package + "-" + re.sub("[\-\.]*redhat\-\d+", "",
                                               version) + suffix

        #WA for subfolder builds (? in SCM url)
        if "?" in scm_repo_url:
            folder = scm_repo_url[scm_repo_url.index('?') + 1:]
            scm_repo_url = scm_repo_url[:scm_repo_url.index('?')]
            if 'maven_options' not in art_params['options'].keys():
                art_params['options']['maven_options'] = []
            art_params['options']['maven_options'].append("-f./" + folder +
                                                          "/pom.xml")
            if 'properties' not in art_params['options'].keys():
                art_params['options']['properties'] = {}
            art_params['options']['properties']['exec_folder'] = folder

        # If scm_repo_url starts with git+https protocol, use https protocol instead
        # recent versions of git don't seem to understand 'git+https' anymore
        scm_repo_url = _git_url_use_https_only(scm_repo_url)

        #Lookup or create a Project
        try:
            project = projects.get_project_raw(name=project_name)
        except ValueError:
            logging.debug('No project ' + project_name +
                          ". Creating a new one")
            project = projects.create_project_raw(name=project_name)
        logging.debug(artifact_name + ":")
        logging.debug(project.id)

        #Lookup or update or create Build Config
        build_config = get_build_configuration_by_name(artifact_name)
        if subartifact in look_up_only_list:
            if build_config == None:
                logging.warn(
                    "Look up of an existing Build Configuration failed. No build configuration with name "
                    + artifact_name + " found.")
        else:
            if build_config == None:
                logging.debug('No build config with name ' + artifact_name)
                build_config = create_build_configuration(
                    env, bc_set, product_version_id, art_params, scm_repo_url,
                    scm_revision, artifact_name, project)
            else:
                build_config = update_build_configuration(
                    env, product_version_id, art_params, scm_repo_url,
                    scm_revision, artifact_name, project)

        # Make sure existing configs are added the group
        if build_config is not None and build_config.id not in bc_set.build_configuration_ids:
            buildconfigurationsets.add_build_configuration_to_set(
                set_id=bc_set.id, config_id=build_config.id)

        if build_config == None:
            return 10

        ids[artifact] = build_config
        logging.debug(build_config.id)

    #Construct dependency tree of Build Configs
    logging.debug(ids)
    for package, dependencies in packages.iteritems():
        for artifact in dependencies:
            bc_id = ids[package]
            subid = ids[artifact]
            logging.debug(bc_id.id, subid.id)
            buildconfigurations.add_dependency(id=bc_id.id,
                                               dependency_id=subid.id)

    #Run build if requested
    if run_build:
        build_record = buildconfigurationsets.build_set_raw(id=bc_set.id)
        logging.info("Build started with id %d", build_record.id)

    return utils.format_json(bc_set)
Exemplo n.º 3
0
            folder = scm_repo_url[scm_repo_url.index('?')+1:]
            scm_repo_url = scm_repo_url[:scm_repo_url.index('?')]
            if 'maven_options' not in art_params['options'].keys():
                art_params['options']['maven_options'] = []
            art_params['options']['maven_options'].append("-f./"+folder+"/pom.xml")
            if 'properties' not in art_params['options'].keys():
                art_params['options']['properties'] = {}
            art_params['options']['properties']['exec_folder'] = folder

        # If scm_repo_url starts with git+https protocol, use https protocol instead
        # recent versions of git don't seem to understand 'git+https' anymore
        scm_repo_url = _git_url_use_https_only(scm_repo_url)

        #Lookup or create a Project
        try:
            project = projects.get_project_raw(name=project_name)
        except ValueError:
            logging.debug('No project ' + project_name + ". Creating a new one")
            project = projects.create_project_raw(name=project_name)
        logging.debug(artifact_name + ":")
        logging.debug(project.id)

        #Lookup or update or create Build Config
        build_config = get_build_configuration_by_name(artifact_name)
        if subartifact in look_up_only_list:
            if build_config == None:
                logging.warn("Look up of an existing Build Configuration failed. No build configuration with name " + artifact_name + " found.")
        else:
            if build_config == None:
                logging.debug('No build config with name ' + artifact_name)
                build_config = create_build_configuration(env, bc_set, product_version_id, art_params, scm_repo_url,
Exemplo n.º 4
0
def test_get_project_name(mock_projects_api, mock_get_specific, mock_set_id):
    result = projects.get_project_raw(name='testerino')
    mock_set_id.assert_called_once_with(mock_projects_api, None, 'testerino')
    mock_get_specific.assert_called_once_with(id=1)
    assert result == 'SUCCESS'
Exemplo n.º 5
0
def test_get_project_id(mock_projects_api, mock_get_specific, mock_set_id):
    result = projects.get_project_raw(id=1)
    mock_set_id.assert_called_once_with(mock_projects_api, 1, None)
    mock_get_specific.assert_called_once_with(id=1)
    assert result == 'SUCCESS'
Exemplo n.º 6
0
def make_mead_impl(config, run_build, environment, suffix, product_name, product_version, look_up_only, clean_group):
    if not validate_input_parameters(config, product_name, product_version):
        return 1

    try:
        config_reader = ConfigReader(config)
    except NoSectionError as e:
        logging.error('Missing config in %s (%r)', config, e)
        return 1
    except Error as err:
        logging.error(err)
        return 1

    ids = dict()
    (subarts, deps_dict) = config_reader.get_dependency_structure()
    packages = config_reader.get_packages_and_dependencies()
    logging.debug(packages)
    logging.debug(subarts)
    logging.debug(deps_dict)

    product_version_id = get_product_version(product_name, product_version)
    if product_version_id is None:
        return 1

    # Get environment
    env = environments.get_environment_raw(environment)
    if not env:
        logging.error('Environment with id %d not found', environment)
        return 1

    #Create a list for look-up-only
    look_up_only_list = look_up_only.split(",")

    #Lookup or create Build Configuration Set
    target_name = product_name + "-" + product_version + "-all" + suffix
    try:
        bc_set = buildconfigurationsets.get_build_configuration_set_raw(name=target_name)
        if clean_group:
            for bc_id in bc_set.build_configuration_ids:
                buildconfigurationsets.remove_build_configuration_from_set_raw(set_id=bc_set.id, config_id=bc_id)
    except ValueError:
        bc_set = buildconfigurationsets.create_build_configuration_set_raw(name=target_name, product_version_id=product_version_id)
    logging.debug(target_name + ":")
    logging.debug(bc_set.id)

    #Iterate through all sections in configuration file
    for subartifact in subarts:
        art_params = config_reader.get_config(subartifact)
        logging.debug(art_params)
        artifact = art_params['artifact']
        if 'pnc.projectName' in art_params.keys():
            logging.debug("Overriding project name with " + art_params['pnc.projectName'])
            project_name = art_params['pnc.projectName']
        else:
            logging.debug("Using default project name " + artifact)
            project_name = artifact

        logging.debug(art_params)
        package = art_params['package']
        version = art_params['version']
        scm_url = art_params['scmURL']
        (scm_repo_url, scm_revision) = scm_url.split("#", 2)
        artifact_name = package + "-" + re.sub("[\-\.]*redhat\-\d+", "", version) + suffix

        #WA for subfolder builds (? in SCM url)
        if "?" in scm_repo_url:
            folder = scm_repo_url[scm_repo_url.index('?')+1:]
            scm_repo_url = scm_repo_url[:scm_repo_url.index('?')]
            if 'maven_options' not in art_params['options'].keys():
                art_params['options']['maven_options'] = []
            art_params['options']['maven_options'].append("-f./"+folder+"/pom.xml")
            if 'properties' not in art_params['options'].keys():
                art_params['options']['properties'] = {}
            art_params['options']['properties']['exec_folder'] = folder

        # If scm_repo_url starts with git+https protocol, use https protocol instead
        # recent versions of git don't seem to understand 'git+https' anymore
        scm_repo_url = _git_url_use_https_only(scm_repo_url)

        #Lookup or create a Project
        try:
            project = projects.get_project_raw(name=project_name)
        except ValueError:
            logging.debug('No project ' + project_name + ". Creating a new one")
            project = projects.create_project_raw(name=project_name)
        logging.debug(artifact_name + ":")
        logging.debug(project.id)

        #Lookup or update or create Build Config
        build_config = get_build_configuration_by_name(artifact_name)
        if subartifact in look_up_only_list:
            if build_config == None:
                logging.warn("Look up of an existing Build Configuration failed. No build configuration with name " + artifact_name + " found.")
        else:
            if build_config == None:
                logging.debug('No build config with name ' + artifact_name)
                build_config = create_build_configuration(env, bc_set, product_version_id, art_params, scm_repo_url,
                                                          scm_revision, artifact_name, project)
            else:
                build_config = update_build_configuration(env, product_version_id, art_params, scm_repo_url,
                                                          scm_revision, artifact_name, project)

        # Make sure existing configs are added the group
        if build_config is not None and build_config.id not in bc_set.build_configuration_ids:
            buildconfigurationsets.add_build_configuration_to_set(set_id=bc_set.id, config_id=build_config.id)

        if build_config == None:
            return 10

        ids[artifact] = build_config
        logging.debug(build_config.id)

    #Construct dependency tree of Build Configs
    logging.debug(ids)
    for package, dependencies in packages.iteritems():
        for artifact in dependencies:
            bc_id = ids[package]
            subid = ids[artifact]
            logging.debug(bc_id.id, subid.id)
            buildconfigurations.add_dependency(id=bc_id.id, dependency_id=subid.id)

    #Run build if requested
    if run_build:
        build_record = buildconfigurationsets.build_set_raw(id=bc_set.id)
        logging.info("Build started with id %d",build_record.id)

    return utils.format_json(bc_set)
Exemplo n.º 7
0
def test_get_project_name(mock_projects_api, mock_get_specific, mock_set_id):
    result = projects.get_project_raw(name='testerino')
    mock_set_id.assert_called_once_with(mock_projects_api, None, 'testerino')
    mock_get_specific.assert_called_once_with(id=1)
    assert result == 'SUCCESS'
Exemplo n.º 8
0
def test_get_project_id(mock_projects_api, mock_get_specific, mock_set_id):
    result = projects.get_project_raw(id=1)
    mock_set_id.assert_called_once_with(mock_projects_api, 1, None)
    mock_get_specific.assert_called_once_with(id=1)
    assert result == 'SUCCESS'