Skip to content

Commit

Permalink
add ForbiddenError to the retry list and add default exceptions to a …
Browse files Browse the repository at this point in the history
…few calls (RedHatQE#1058)

* add ForbiddenError to the retry list

* add default exceptions to a few calls
  • Loading branch information
dbasunag authored Jan 12, 2023
1 parent ea38637 commit a2987a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
22 changes: 20 additions & 2 deletions ocp_resources/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
from openshift.dynamic.exceptions import NotFoundError
from urllib3.exceptions import ProtocolError
from kubernetes.dynamic.exceptions import ForbiddenError
from openshift.dynamic.exceptions import (
InternalServerError,
NotFoundError,
ServerTimeoutError,
)
from urllib3.exceptions import MaxRetryError, ProtocolError


DEFAULT_CLUSTER_RETRY_EXCEPTIONS = {
MaxRetryError: [],
ConnectionAbortedError: [],
ConnectionResetError: [],
InternalServerError: [
"etcdserver: leader changed",
"etcdserver: request timed out",
"Internal error occurred: failed calling webhook",
"rpc error:",
],
ServerTimeoutError: [],
ForbiddenError: ["context deadline exceeded"],
}
PROTOCOL_ERROR_EXCEPTION_DICT = {ProtocolError: []}
NOT_FOUND_ERROR_EXCEPTION_DICT = {NotFoundError: []}
TIMEOUT_1MINUTE = 60
Expand Down
28 changes: 7 additions & 21 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
import yaml
from kubernetes.dynamic.exceptions import ForbiddenError, MethodNotAllowedError
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import (
ConflictError,
InternalServerError,
NotFoundError,
ServerTimeoutError,
)
from openshift.dynamic.exceptions import ConflictError, NotFoundError
from openshift.dynamic.resource import ResourceField
from packaging.version import Version
from urllib3.exceptions import MaxRetryError

from ocp_resources.constants import (
DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
NOT_FOUND_ERROR_EXCEPTION_DICT,
PROTOCOL_ERROR_EXCEPTION_DICT,
TIMEOUT_1MINUTE,
Expand All @@ -35,19 +30,6 @@
)


DEFAULT_CLUSTER_RETRY_EXCEPTIONS = {
MaxRetryError: [],
ConnectionAbortedError: [],
ConnectionResetError: [],
InternalServerError: [
"etcdserver: leader changed",
"etcdserver: request timed out",
"Internal error occurred: failed calling webhook",
"rpc error:",
],
ServerTimeoutError: [],
}

LOGGER = get_logger(__name__)
MAX_SUPPORTED_API_VERSION = "v2"

Expand Down Expand Up @@ -586,6 +568,7 @@ def wait(self, timeout=TIMEOUT_4MINUTES, sleep=1):
exceptions_dict={
**PROTOCOL_ERROR_EXCEPTION_DICT,
**NOT_FOUND_ERROR_EXCEPTION_DICT,
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
},
func=lambda: self.exists,
)
Expand Down Expand Up @@ -652,7 +635,10 @@ def wait_for_status(
samples = TimeoutSampler(
wait_timeout=timeout,
sleep=sleep,
exceptions_dict=PROTOCOL_ERROR_EXCEPTION_DICT,
exceptions_dict={
**PROTOCOL_ERROR_EXCEPTION_DICT,
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
},
func=self.api.get,
field_selector=f"metadata.name=={self.name}",
namespace=self.namespace,
Expand Down
11 changes: 9 additions & 2 deletions ocp_resources/virtual_machine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-


from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES
from ocp_resources.constants import (
DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
PROTOCOL_ERROR_EXCEPTION_DICT,
TIMEOUT_4MINUTES,
)
from ocp_resources.resource import NamespacedResource
from ocp_resources.utils import TimeoutSampler
from ocp_resources.virtual_machine_instance import VirtualMachineInstance
Expand Down Expand Up @@ -109,7 +113,10 @@ def wait_for_ready_status(self, status, timeout=TIMEOUT_4MINUTES, sleep=1):
samples = TimeoutSampler(
wait_timeout=timeout,
sleep=sleep,
exceptions_dict=PROTOCOL_ERROR_EXCEPTION_DICT,
exceptions_dict={
**PROTOCOL_ERROR_EXCEPTION_DICT,
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
},
func=self.api.get,
field_selector=f"metadata.name=={self.name}",
namespace=self.namespace,
Expand Down

0 comments on commit a2987a2

Please sign in to comment.