Esempio n. 1
0
def test_fetch_flowcell_pdc_retrieval_failed(
    mock_store,
    mock_pdc,
    mock_flowcell,
    mock_check_processing,
    mock_maximum_flowcells_ondisk,
    caplog,
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we are going to retrieve a flowcell from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )
    backup_api.check_processing.return_value = True
    backup_api.maximum_flowcells_ondisk.return_value = False

    # WHEN the retrieval process fails
    mock_pdc.retrieve_flowcell.side_effect = subprocess.CalledProcessError(1, "echo")
    with pytest.raises(subprocess.CalledProcessError):
        backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN the failure to retrieve is logged
    assert "retrieval failed" in caplog.text
Esempio n. 2
0
def test_fetch_flowcell_retrieve_specified_flowcell(
    mock_store,
    mock_pdc,
    mock_flowcell,
    mock_check_processing,
    mock_maximum_flowcells_ondisk,
    caplog,
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we want to retrieve a specific flowcell from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )
    backup_api.check_processing.return_value = True
    backup_api.maximum_flowcells_ondisk.return_value = False

    result = backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN the process to retrieve the flowcell from PDC is started
    assert "retrieving from PDC" in caplog.text

    # AND when done the status of that flowcell is set to "retrieved"
    assert f'Status for flowcell {mock_flowcell.name} set to "retrieved"' in caplog.text
    assert mock_flowcell.status == "retrieved"

    # AND status-db is updated with the new status
    assert mock_store.commit.called

    # AND the elapsed time of the retrieval process is returned
    assert result > 0
Esempio n. 3
0
def test_fetch_flowcell_no_flowcells_requested(
    mock_store,
    mock_pdc,
    mock_check_processing,
    mock_maximum_flowcells_ondisk,
    mock_pop_flowcell,
    caplog,
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we check if a flowcell needs to be retrieved from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )

    # WHEN no flowcells are requested
    mock_pop_flowcell.return_value = None
    backup_api.check_processing.return_value = True
    backup_api.maximum_flowcells_ondisk.return_value = False

    # AND no flowcell has been specified
    mock_flowcell = None

    result = backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN no flowcell will be fetched and a log message indicates that no flowcells have been
    # requested
    assert result is None
    assert "no flowcells requested" in caplog.text
Esempio n. 4
0
def test_fetch_flowcell_max_flowcells_ondisk(
    mock_store,
    mock_pdc,
    mock_flowcell,
    mock_check_processing,
    mock_maximum_flowcells_ondisk,
    caplog,
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we check if a flowcell needs to be retrieved from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )

    # WHEN the processing queue is not full but the number of flowcells on disk is greater than the
    # maximum
    backup_api.check_processing.return_value = True
    backup_api.maximum_flowcells_ondisk.return_value = True

    result = backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN no flowcell will be fetched and a log message indicates that maximum number of flowcells
    # has been reached
    assert result is None
    assert "maximum flowcells ondisk reached" in caplog.text
Esempio n. 5
0
def fetch_flowcell(context: click.Context, dry_run: bool, flowcell: str):
    """Fetch the first flowcell in the requested queue from backup."""
    status_api = Store(context.obj["database"])
    max_flowcells_on_disk = context.obj.get("max_flowcells",
                                            MAX_FLOWCELLS_ON_DISK)
    pdc_api = PdcApi()
    backup_api = BackupApi(status=status_api,
                           pdc_api=pdc_api,
                           max_flowcells_on_disk=max_flowcells_on_disk)
    if flowcell:
        flowcell_obj = status_api.flowcell(flowcell)
        if flowcell_obj is None:
            LOG.error(f"{flowcell}: not found in database")
            context.abort()
    else:
        flowcell_obj = None

    retrieval_time = backup_api.fetch_flowcell(flowcell_obj=flowcell_obj,
                                               dry_run=dry_run)

    if retrieval_time:
        hours = retrieval_time / 60 / 60
        LOG.info(f"Retrieval time: {hours:.1}h")
        return

    if not flowcell:
        return

    if not dry_run:
        LOG.info(f"{flowcell}: updating flowcell status to requested")
        flowcell_obj.status = "requested"
        status_api.commit()
Esempio n. 6
0
def test_fetch_flowcell_retrieve_next_flowcell(
    mock_store,
    mock_pdc,
    mock_check_processing,
    mock_maximum_flowcells_ondisk,
    mock_pop_flowcell,
    caplog,
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we check if a flowcell needs to be retrieved from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )

    # WHEN no flowcells is specified, but a flowcell in status-db has the status "requested"
    mock_flowcell = None
    mock_pop_flowcell.return_value = mock_store.add_flowcell(
        status="requested",
    )
    backup_api.check_processing.return_value = True
    backup_api.maximum_flowcells_ondisk.return_value = False

    result = backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN the process to retrieve the flowcell from PDC is started
    assert "retrieving from PDC" in caplog.text

    # AND when done the status of that flowcell is set to "retrieved"
    assert (
        f'Status for flowcell {mock_pop_flowcell.return_value.name} set to "retrieved"'
        in caplog.text
    )
    assert mock_pop_flowcell.return_value.status == "retrieved"

    # AND status-db is updated with the new status
    assert mock_store.commit.called

    # AND the elapsed time of the retrieval process is returned
    assert result > 0
Esempio n. 7
0
def test_fetch_flowcell_processing_queue_full(
    mock_store, mock_pdc, mock_flowcell, mock_check_processing, caplog
):
    """tests the fetch_flowcell method of the backup API"""

    caplog.set_level(logging.INFO)

    # GIVEN we check if a flowcell needs to be retrieved from PDC
    backup_api = BackupApi(
        mock_store, mock_pdc, max_flowcells_on_disk=1250, root_dir="/path/to/root_dir"
    )

    # WHEN the processing queue is full
    backup_api.check_processing.return_value = False
    result = backup_api.fetch_flowcell(mock_flowcell, dry_run=False)

    # THEN no flowcell will be fetched and a log message indicates that the processing queue is
    # full
    assert result is None
    assert "processing queue is full" in caplog.text