Beispiel #1
0
def get_next_version_available_for_upgrade(current_tag):
    """
    This function returns the tag built after the current_version

    Args:
        current_tag (str): Current build tag from which to search the next one
            build tag.

    Returns:
        str: tag for downstream image from quay registry built after
            the current_tag.

    Raises:
        TagNotFoundException: In case no tag suitable for upgrade found

    """
    req = requests.get(
        constants.OPERATOR_CS_QUAY_API_QUERY.format(tag_limit=100))
    if current_tag == 'latest':
        return 'latest'
    tags = req.json()['tags']
    for index, tag in enumerate(tags):
        if tag['name'] == current_tag:
            if index < 2:
                raise TagNotFoundException(f"Couldn't find tag for upgrade!")
            if tags[index - 1]['name'] != 'latest':
                return tags[index - 1]['name']
            else:
                return tags[index - 2]['name']
    raise TagNotFoundException(f"Couldn't find any tag!")
Beispiel #2
0
def get_latest_ds_olm_tag(upgrade=False):
    """
    This function returns latest tag of OCS downstream registry or one before
    latest if upgrade parameter is True

    Args:
        upgrade (str): If True then it returns one version of the build before
            the latest.

    Returns:
        str: latest tag for downstream image from quay registry

    Raises:
        TagNotFoundException: In case no tag found

    """
    _req = requests.get(
        constants.OPERATOR_CS_QUAY_API_QUERY.format(tag_limit=3))
    latest_image = None
    tags = _req.json()['tags']
    for tag in tags:
        if tag['name'] == 'latest':
            latest_image = tag['image_id']
            break
    if not latest_image:
        raise TagNotFoundException(f"Couldn't find latest tag!")
    for tag in tags:
        if not upgrade:
            if tag['name'] != 'latest' and tag['image_id'] == latest_image:
                return tag['name']
        if upgrade:
            if tag['name'] != 'latest' and tag['image_id'] != latest_image:
                return tag['name']
    raise TagNotFoundException(f"Couldn't find any desired tag!")
Beispiel #3
0
def get_next_version_available_for_upgrade(current_tag):
    """
    This function returns the tag built after the current_version

    Args:
        current_tag (str): Current build tag from which to search the next one
            build tag.

    Returns:
        str: tag for downstream image from quay registry built after
            the current_tag.

    Raises:
        TagNotFoundException: In case no tag suitable for upgrade found

    """
    req = requests.get(
        constants.OPERATOR_CS_QUAY_API_QUERY.format(tag_limit=100))
    if current_tag in constants.LATEST_TAGS:
        return current_tag
    tags = req.json()['tags']
    current_tag_index = None
    for index, tag in enumerate(tags):
        if tag['name'] == current_tag:
            if index < 2:
                raise TagNotFoundException(f"Couldn't find tag for upgrade!")
            current_tag_index = index
            break
    sliced_reversed_tags = tags[:current_tag_index]
    sliced_reversed_tags.reverse()
    for tag in sliced_reversed_tags:
        if tag['name'] not in constants.LATEST_TAGS and "rc" in tag['name']:
            return tag['name']
    raise TagNotFoundException(f"Couldn't find any tag!")
Beispiel #4
0
def get_latest_ds_olm_tag(upgrade=False, latest_tag=None):
    """
    This function returns latest tag of OCS downstream registry or one before
    latest if upgrade parameter is True

    Args:
        upgrade (str): If True then it returns one version of the build before
            the latest.
        latest_tag (str): Tag of the latest build. If not specified
            config.DEPLOYMENT['default_latest_tag'] or 'latest' will be used.

    Returns:
        str: latest tag for downstream image from quay registry

    Raises:
        TagNotFoundException: In case no tag found

    """
    latest_tag = latest_tag or config.DEPLOYMENT.get(
        'default_latest_tag', 'latest'
    )
    _req = requests.get(
        constants.OPERATOR_CS_QUAY_API_QUERY.format(tag_limit=100)
    )
    latest_image = None
    tags = _req.json()['tags']
    for tag in tags:
        if tag['name'] == latest_tag:
            latest_image = tag['image_id']
            break
    if not latest_image:
        raise TagNotFoundException(f"Couldn't find latest tag!")
    latest_tag_found = False
    for tag in tags:
        if not upgrade:
            if (
                tag['name'] not in constants.LATEST_TAGS
                and tag['image_id'] == latest_image
            ):
                return tag['name']
        if upgrade:
            if not latest_tag_found and tag['name'] == latest_tag:
                latest_tag_found = True
                continue
            if not latest_tag_found:
                continue
            if (
                tag['name'] not in constants.LATEST_TAGS
                and tag['image_id'] != latest_image and "rc" in tag['name']
            ):
                return tag['name']
    raise TagNotFoundException(f"Couldn't find any desired tag!")
Beispiel #5
0
def get_latest_ds_olm_tag():
    """
    This function returns latest tag of OCS downstream registry

    Returns:
        str: latest tag for downstream image from quay registry

    Raises:
        TagNotFoundException: In case no tag found

    """
    _req = requests.get(constants.OPERATOR_CS_QUAY_API_QUERY)
    req = list(filter(lambda x: x['name'] != 'latest', _req.json()['tags']))
    if len(req) != 1:
        raise TagNotFoundException(f"Couldn't find any tag!")
    return req[0]['name']