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

Commit

Permalink
test: Making firewall test tolerant of GCE Enforcer. (#162)
Browse files Browse the repository at this point in the history
* docs(samples): Making firewall test tolerant of GCE Enforcer.

* 馃 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 馃 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* docs(samples): Marking the default values test as flaky.

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people committed Dec 1, 2021
1 parent 8b373af commit 4e7953e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==6.2.5
flaky==3.7.0
google-cloud-storage==1.43.0
2 changes: 2 additions & 0 deletions samples/snippets/test_sample_default_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import typing
import uuid

from flaky import flaky
import google.auth
import google.cloud.storage as storage
import pytest
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions samples/snippets/test_sample_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import time
import uuid

import google.api_core.exceptions
import google.auth
from google.cloud import compute_v1
import pytest
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 4e7953e

Please sign in to comment.