예제 #1
0
def test_is_allowed_to_push_to_snap_store(channel, expected):
    assert is_allowed_to_push_to_snap_store(channel=channel) == expected

    context = MagicMock()
    context.task = {
        'scopes': ['project:releng:snapcraft:firefox:{}'.format(channel)]
    }
    assert is_allowed_to_push_to_snap_store(context=context) == expected
예제 #2
0
def push(context, snap_file_path, channel):
    if not task.is_allowed_to_push_to_snap_store(channel=channel):
        log.warn('Not allowed to push to Snap store. Skipping push...')
        # We don't raise an error because we still want green tasks on dev instances
        return

    macaroon_location = context.config['macaroons_locations'][channel]
    with _session(macaroon_location):
        push_kwargs = {
            'snap_filename': snap_file_path,
            'release_channels': [channel],
        }
        log.debug(
            'Calling snapcraft push with these kwargs: {}'.format(push_kwargs))
        snapcraft_store_client.push(**push_kwargs)
예제 #3
0
def push(context, snap_file_path, channel):
    if not task.is_allowed_to_push_to_snap_store(channel=channel):
        log.warn('Not allowed to push to Snap store. Skipping push...')
        # We don't raise an error because we still want green tasks on dev instances
        return

    # Snapcraft requires credentials to be stored at $CWD/.snapcraft/snapcraft.cfg. Let's store them
    # in a folder that gets purged at the end of the run.
    with tempfile.TemporaryDirectory() as temp_dir:
        _craft_credentials_file(context, channel, temp_dir)

        log.debug('Calling snapcraft push with these args: {}, {}'.format(
            snap_file_path, channel))
        with cwd(temp_dir):
            snapcraft_store_client.push(snap_file_path, channel)
예제 #4
0
def push(context, snap_file_path, channel):
    """ Publishes a snap onto a given channel.

    This function performs all the network actions to ensure `snap_file_path` is published on
    `channel`. If `channel` is not whitelisted to contact the Snap Store, then it just early
    returns (this allows staging tasks to not contact the Snap Store instance at all). If allowed,
    this function first connects to the Snap Store, then uploads the Snap onto it. No matter
    whether the snap has already been uploaded, it proceeds to the next step. If the snap is
    already released, then there's nothing to do and the function simply returns. Otherwise, the
    Snap must have a higher version (or build) number to overwrite the existing one. If the version
    number happens to be lower or the same one (while still being a different Snap), then the
    function bails out.

    Args:
        context (scriptworker.context.Context): the scriptworker context. It must define
            `context.config['macaroons_locations'][channel]`.
        snap_file_path (str): The full path to the snap file
        channel (str): The Snap Store channel.
    """
    if not task.is_allowed_to_push_to_snap_store(context.config,
                                                 channel=channel):
        log.warning("Not allowed to push to Snap store. Skipping push...")
        # We don't raise an error because we still want green tasks on dev instances
        return

    macaroon_location = context.config["macaroons_locations"][channel.split(
        "/", 1)[0]]
    with _store_session(macaroon_location) as store:
        try:
            log.debug("Calling snapcraft.push() with this file: {}".format(
                snap_file_path))
            # We don't call store.upload() because this push() does more
            snapcraft_store_client.push(snap_filename=snap_file_path)
        except StoreReviewError as e:
            if "A file with this exact same content has already been uploaded" in e.additional:
                log.warning(e)
            else:
                raise

        _release_if_needed(store, channel, snap_file_path)
예제 #5
0
def _log_warning_forewords(config, channel):
    if not task.is_allowed_to_push_to_snap_store(config, channel):
        log.warning(
            'You do not have the rights to reach Snap store. *All* requests will be mocked.'
        )
예제 #6
0
def test_is_allowed_to_push_to_snap_store(channel, push_to_store, expected):
    config = {"push_to_store": push_to_store}
    assert is_allowed_to_push_to_snap_store(config, channel) == expected