Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

samples.snippets.samples_test.TestContainerAnalysisSamples: test_poll_discovery_occurrence failed #78

Closed
@flaky-bot

Description

@flaky-bot

This test failed!

To configure my behavior, see the Build Cop Bot documentation.

If I'm commenting on this issue too often, add the buildcop: quiet label and
I will stop commenting.


commit: d236cfc
buildURL: Build Status, Sponge
status: failed

Test output
self = 
def test_poll_discovery_occurrence(self):
    # try with no discovery occurrence
    try:
        samples.poll_discovery_finished(self.image_url, 5, PROJECT_ID)
    except RuntimeError:
        pass
    else:
        # we expect timeout error
        assert False

    # create discovery occurrence
    note_id = 'discovery-note-{}'.format(uuid.uuid4())
    client = containeranalysis_v1.ContainerAnalysisClient()
    grafeas_client = client.get_grafeas_client()
    note = {
        'discovery': {
            'analysis_kind': NoteKind.DISCOVERY
        }
    }
    grafeas_client.\
        create_note(parent=f"projects/{PROJECT_ID}", note_id=note_id, note=note)
    occurrence = {
        'note_name': f"projects/{PROJECT_ID}/notes/{note_id}",
        'resource_uri': self.image_url,
        'discovery': {
            'analysis_status': DiscoveryOccurrence.AnalysisStatus
                                                  .FINISHED_SUCCESS
        }
    }
    created = grafeas_client.\
        create_occurrence(parent=f"projects/{PROJECT_ID}",
                          occurrence=occurrence)

    # poll again
  disc = samples.poll_discovery_finished(self.image_url, 10, PROJECT_ID)

samples_test.py:224:


resource_url = 'add9004e-d237-4b11-8b73-e3f66b7ce531.test_poll_discovery_occurrence'
timeout_seconds = 10, project_id = 'python-docs-samples-tests'

def poll_discovery_finished(resource_url, timeout_seconds, project_id):
    """Returns the discovery occurrence for a resource once it reaches a
    terminal state."""
    # resource_url = 'https://gcr.io/my-project/my-image@sha256:123'
    # timeout_seconds = 20
    # project_id = 'my-gcp-project'

    import time
    from grafeas.grafeas_v1 import DiscoveryOccurrence
    from google.cloud.devtools import containeranalysis_v1

    deadline = time.time() + timeout_seconds

    client = containeranalysis_v1.ContainerAnalysisClient()
    grafeas_client = client.get_grafeas_client()
    project_name = f"projects/{project_id}"

    discovery_occurrence = None
    while discovery_occurrence is None:
        time.sleep(1)
        filter_str = 'resourceUrl="{}" \
                      AND noteProjectId="goog-analysis" \
                      AND noteId="PACKAGE_VULNERABILITY"'.format(resource_url)
        # [END containeranalysis_poll_discovery_occurrence_finished]
        # The above filter isn't testable, since it looks for occurrences in a
        # locked down project fall back to a more permissive filter for testing
        filter_str = 'kind="DISCOVERY" AND resourceUrl="{}"'\
            .format(resource_url)
        # [START containeranalysis_poll_discovery_occurrence_finished]
        result = grafeas_client.list_occurrences(parent=project_name, filter=filter_str)
        # only one occurrence should ever be returned by ListOccurrences
        # and the given filter
        for item in result:
            discovery_occurrence = item
        if time.time() > deadline:
          raise RuntimeError('timeout while retrieving discovery occurrence')

E RuntimeError: timeout while retrieving discovery occurrence

samples.py:318: RuntimeError

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: containeranalysisIssues related to the googleapis/python-containeranalysis API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.samplesIssues that are directly related to samples.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions