Update exceptions handling for openstacksdk.

Implements: blueprint switch-to-openstacksdk
Change-Id: I6d9ce11af7e24533ee52e2f50af9a4eb0294c3a1
This commit is contained in:
Roman Dobosz 2020-01-29 09:07:21 +01:00
parent 381af76bf8
commit 19d55152bb
5 changed files with 18 additions and 12 deletions

View File

@ -25,7 +25,6 @@ from kuryr_kubernetes import constants
from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes import utils
from neutronclient.common import exceptions as n_exc
OPERATORS_WITH_VALUES = [constants.K8S_OPERATOR_IN,
constants.K8S_OPERATOR_NOT_IN]
@ -422,7 +421,7 @@ def tag_neutron_resources(resources):
for res in resources:
try:
os_net.set_tags(res, tags=tags)
except n_exc.NeutronClientException:
except os_exc.SDKException:
LOG.warning("Failed to tag %s with %s. Ignoring, but this is "
"still unexpected.", res, tags, exc_info=True)

View File

@ -15,6 +15,7 @@
import eventlet
import time
from openstack import exceptions as os_exc
from oslo_cache import core as cache
from oslo_config import cfg as oslo_cfg
from oslo_log import log as logging
@ -28,8 +29,6 @@ from kuryr_kubernetes import exceptions
from kuryr_kubernetes.handlers import k8s_base
from kuryr_kubernetes import utils
from neutronclient.common import exceptions as n_exc
from openstack import exceptions as os_exc
LOG = logging.getLogger(__name__)
@ -115,7 +114,7 @@ class NamespaceHandler(k8s_base.ResourceEventHandler):
try:
net_crd_sg = self._drv_sg.create_namespace_sg(ns_name, project_id,
net_crd_spec)
except n_exc.NeutronClientException:
except os_exc.SDKException:
LOG.exception("Error creating security group for the namespace. "
"Rolling back created network resources.")
self._drv_subnets.rollback_network_resources(net_crd_spec, ns_name)

View File

@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from neutronclient.common import exceptions as n_exc
from openstack import exceptions as o_exc
from openstack import exceptions as os_exc
from oslo_cache import core as cache
from oslo_config import cfg as oslo_cfg
from oslo_log import log as logging
@ -120,7 +119,7 @@ class NetworkPolicyHandler(k8s_base.ResourceEventHandler):
oslo_cfg.OptGroup('neutron_defaults'))
try:
self._drv_vif_pool.update_vif_sgs(pod, pod_sgs)
except (n_exc.NotFound, o_exc.NotFoundException):
except os_exc.NotFoundException:
LOG.debug("Fail to update pod sgs."
" Retrying policy deletion.")
raise exceptions.ResourceNotReady(policy)

View File

@ -18,8 +18,7 @@ import threading
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler
from six.moves.socketserver import ThreadingUnixStreamServer
from neutronclient.common import exceptions as n_exc
from openstack import exceptions as os_exc
from oslo_config import cfg as oslo_cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
@ -165,11 +164,11 @@ class RequestHandler(BaseHTTPRequestHandler):
try:
drv_vif_pool.force_populate_pool(
trunk_ip, project_id, subnets, security_groups, num_ports)
except n_exc.Conflict:
except os_exc.ConflictException:
LOG.error("VLAN Id conflict (already in use) at trunk %s",
trunk_ip)
raise
except n_exc.NeutronClientException:
except os_exc.SDKException:
LOG.exception("Error happened during subports addition at "
"trunk: %s", trunk_ip)
raise

View File

@ -17,6 +17,7 @@ import itertools
import time
from neutronclient.common import exceptions as n_exc
from openstack import exceptions as os_exc
from oslo_log import log as logging
from oslo_utils import excutils
@ -78,9 +79,18 @@ class Retry(base.EventHandler):
self._handler(event)
break
except n_exc.OverQuotaClient:
# NOTE(gryf): this exception handling should be removed after
# nested_macvlan_driver convertion to OpenStackSDK.
with excutils.save_and_reraise_exception() as ex:
if self._sleep(deadline, attempt, ex.value):
ex.reraise = False
except os_exc.ConflictException as ex:
if ex.details.startswith('Quota exceeded for resources'):
with excutils.save_and_reraise_exception() as ex:
if self._sleep(deadline, attempt, ex.value):
ex.reraise = False
else:
raise
except self._exceptions:
with excutils.save_and_reraise_exception() as ex:
if self._sleep(deadline, attempt, ex.value):