diff --git a/compute/compute/snippets/requirements-test.txt b/compute/compute/snippets/requirements-test.txt index 19762f901f56..6c0e2549b44f 100644 --- a/compute/compute/snippets/requirements-test.txt +++ b/compute/compute/snippets/requirements-test.txt @@ -1,2 +1,3 @@ pytest==6.2.5 +flaky==3.7.0 google-cloud-storage==1.43.0 \ No newline at end of file diff --git a/compute/compute/snippets/test_sample_default_values.py b/compute/compute/snippets/test_sample_default_values.py index 231e00675dba..23182e0777b4 100644 --- a/compute/compute/snippets/test_sample_default_values.py +++ b/compute/compute/snippets/test_sample_default_values.py @@ -15,6 +15,7 @@ import typing import uuid +from flaky import flaky import google.auth import google.cloud.storage as storage import pytest @@ -38,6 +39,7 @@ def temp_bucket(): bucket.delete(force=True) +@flaky(max_runs=3) def test_set_usage_export_bucket_default( capsys: typing.Any, temp_bucket: storage.Bucket ) -> None: diff --git a/compute/compute/snippets/test_sample_firewall.py b/compute/compute/snippets/test_sample_firewall.py index 8148febbbcf8..d7bd68b952ae 100644 --- a/compute/compute/snippets/test_sample_firewall.py +++ b/compute/compute/snippets/test_sample_firewall.py @@ -14,6 +14,7 @@ import time import uuid +import google.api_core.exceptions import google.auth from google.cloud import compute_v1 import pytest @@ -52,8 +53,15 @@ def firewall_rule(): yield firewall_client.get(project=PROJECT, firewall=firewall_rule.name) - op = firewall_client.delete(project=PROJECT, firewall=firewall_rule.name) - op_client.wait(project=PROJECT, operation=op.name) + try: + op = firewall_client.delete(project=PROJECT, firewall=firewall_rule.name) + op_client.wait(project=PROJECT, operation=op.name) + except google.api_core.exceptions.BadRequest as err: + if err.code == 400 and "is not ready" in err.message: + # This means GCE enforcer has already deleted that rule. + pass + else: + raise err def test_create_delete():