Skip to content

add retries for subnetwork not ready errors #9523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dataproc/snippets/create_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import uuid

import backoff
from google.api_core.exceptions import (InternalServerError, NotFound,
from google.api_core.exceptions import (InternalServerError, InvalidArgument, NotFound,
ServiceUnavailable)
from google.cloud import dataproc_v1 as dataproc
import pytest
Expand Down Expand Up @@ -50,7 +50,8 @@ def teardown():
print("Cluster already deleted")


@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
# InvalidArgument is thrown when the subnetwork is not ready
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable, InvalidArgument), max_tries=5)
def test_cluster_create(capsys):
# Wrapper function for client library function
create_cluster.create_cluster(PROJECT_ID, REGION, CLUSTER_NAME)
Expand Down
25 changes: 15 additions & 10 deletions dataproc/snippets/submit_job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import uuid

import backoff
from google.api_core.exceptions import (InternalServerError, NotFound,
from google.api_core.exceptions import (InternalServerError, InvalidArgument, NotFound,
ServiceUnavailable)
from google.cloud import dataproc_v1 as dataproc
import pytest
Expand All @@ -38,22 +38,22 @@

@pytest.fixture(autouse=True)
def setup_teardown():
try:
cluster_client = dataproc.ClusterControllerClient(
client_options={
"api_endpoint": "{}-dataproc.googleapis.com:443".format(REGION)
}
)
cluster_client = dataproc.ClusterControllerClient(
client_options={
"api_endpoint": "{}-dataproc.googleapis.com:443".format(REGION)
}
)

# Retry on InvalidArgument subnetwork not ready error
@backoff.on_exception(backoff.expo, (InvalidArgument), max_tries=3)
def setup():
# Create the cluster.
operation = cluster_client.create_cluster(
request={"project_id": PROJECT_ID, "region": REGION, "cluster": CLUSTER}
)
operation.result()

yield

finally:
def teardown():
try:
operation = cluster_client.delete_cluster(
request={
Expand All @@ -66,6 +66,11 @@ def setup_teardown():

except NotFound:
print("Cluster already deleted")
try:
setup()
yield
finally:
teardown()


@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
Expand Down
14 changes: 10 additions & 4 deletions dataproc/snippets/update_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import uuid

import backoff
from google.api_core.exceptions import (InternalServerError, NotFound,
from google.api_core.exceptions import (InternalServerError, InvalidArgument, NotFound,
ServiceUnavailable)
from google.cloud.dataproc_v1.services.cluster_controller.client import \
ClusterControllerClient
Expand Down Expand Up @@ -51,15 +51,16 @@ def cluster_client():

@pytest.fixture(autouse=True)
def setup_teardown(cluster_client):
try:
# InvalidArgument is thrown when the subnetwork is not ready
@backoff.on_exception(backoff.expo, (InvalidArgument), max_tries=3)
def setup():
# Create the cluster.
operation = cluster_client.create_cluster(
request={"project_id": PROJECT_ID, "region": REGION, "cluster": CLUSTER}
)
operation.result()

yield
finally:
def teardown():
try:
operation = cluster_client.delete_cluster(
request={
Expand All @@ -71,6 +72,11 @@ def setup_teardown(cluster_client):
operation.result()
except NotFound:
print("Cluster already deleted")
try:
setup()
yield
finally:
teardown()


@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
Expand Down