def test_build_versioned_for_set_name(mock_sets_api, mock_audited_rest,
                                      mock_fill_audited, mock_get_revision,
                                      mock_build_versioned, mock_get_entity,
                                      mock_set_id):
    result = buildconfigurationsets.build_set_raw(
        name='hello',
        force=True,
        tempbuild=True,
        id_revisions=['1:1', '2:2', '3:3'])
    mock_set_id.assert_called_once_with(mock_sets_api, None, 'hello')
    mock_get_entity.assert_called_once_with(mock_sets_api, 1)
    parsed_calls = [call(1, 1), call(2, 2), call(3, 3)]
    mock_get_revision.assert_has_calls(parsed_calls)
    mock_audited_rest.assert_called_once_with()
    mock_fill_audited.assert_called_once_with(
        'BuildConfigSWithAuditedBody', 'BuildConfiguration',
        ['parsed_revision', 'parsed_revision', 'parsed_revision'])
    mock_build_versioned.assert_called_once_with(
        id=1,
        temporary_build=True,
        force_rebuild=True,
        timestamp_alignment=False,
        body='FilledBuildConfigSWithAuditedBody',
        rebuild_mode=common.REBUILD_MODES_DEFAULT)
    assert result == 'SUCCESS'
def test_build_set_name(mock_sets_api, mock_build, mock_set_id):
    result = buildconfigurationsets.build_set_raw(name='testerino')
    mock_set_id.assert_called_once_with(mock_sets_api, None, 'testerino')
    mock_build.assert_called_once_with(id=1,
                                       force_rebuild=False,
                                       temporary_build=False,
                                       timestamp_alignment=False)
    assert result == 'SUCCESS'
def test_build_set_id(mock_sets_api, mock_build, mock_set_id):
    result = buildconfigurationsets.build_set_raw(id=1)
    mock_set_id.assert_called_once_with(mock_sets_api, 1, None)
    mock_build.assert_called_once_with(
        id=1,
        force_rebuild=False,
        temporary_build=False,
        timestamp_alignment=False,
        rebuild_mode=common.REBUILD_MODES_DEFAULT)
    assert result == 'SUCCESS'
def test_build_versioned_for_set_name(mock_sets_api, mock_audited_rest, mock_fill_audited,
                                    mock_get_revision, mock_build_versioned, mock_get_entity, mock_set_id):
    result = buildconfigurationsets.build_set_raw(name='hello', force=True, tempbuild=True, id_revisions=['1:1', '2:2', '3:3'])
    mock_set_id.assert_called_once_with(mock_sets_api, None, 'hello')
    mock_get_entity.assert_called_once_with(mock_sets_api, 1)
    parsed_calls = [call(1, 1), call(2, 2), call(3, 3)]
    mock_get_revision.assert_has_calls(parsed_calls)
    mock_audited_rest.assert_called_once_with()
    mock_fill_audited.assert_called_once_with('BuildConfigSWithAuditedBody', 'BuildConfiguration',
                                              ['parsed_revision', 'parsed_revision', 'parsed_revision'])
    mock_build_versioned.assert_called_once_with(id=1, temporary_build=True, force_rebuild=True, timestamp_alignment=False, body='FilledBuildConfigSWithAuditedBody', rebuild_mode=common.REBUILD_MODES_DEFAULT)
    assert result == 'SUCCESS'
def test_build_set_id(mock_sets_api, mock_build, mock_set_id):
    result = buildconfigurationsets.build_set_raw(id=1)
    mock_set_id.assert_called_once_with(mock_sets_api, 1, None)
    mock_build.assert_called_once_with(id=1, force_rebuild=False, temporary_build=False, timestamp_alignment=False, rebuild_mode=common.REBUILD_MODES_DEFAULT)
    assert result == 'SUCCESS'
Пример #6
0
            
        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)
        pprint(build_record)

    return utils.format_json(bc_set)

def validate_input_parameters(config, product_name, product_version):
    if config is None:
        logging.error('Config file --config is not specified.')
        return 1

    if product_name is None:
        logging.error('Product Name --product-name is not specified.')
        return 1

    if product_version is None:
        logging.error('Product Version --product-version is not specified.')
Пример #7
0
        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)

def get_product_version(product_name, product_version):
    products_version = None
    try:
        products_versions = products.list_versions_for_product_raw(name=product_name)
        if products_versions:
            for product in products_versions:
                if product.version == product_version:
                    products_version = product.id
        else:
            logging.debug('Product does not have any versions')
    except ValueError:
Пример #8
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)
def test_build_set_id(mock_sets_api, mock_build, mock_set_id):
    result = buildconfigurationsets.build_set_raw(id=1)
    mock_set_id.assert_called_once_with(mock_sets_api, 1, None)
    mock_build.assert_called_once_with(id=1)
    assert result == 'SUCCESS'
def test_build_set_name(mock_sets_api, mock_build, mock_set_id):
    result = buildconfigurationsets.build_set_raw(name='testerino')
    mock_set_id.assert_called_once_with(mock_sets_api, None, 'testerino')
    mock_build.assert_called_once_with(id=1)
    assert result == 'SUCCESS'
Пример #11
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)