Fix catched exception after transition to OpenStackSDK.
Recently, we moved from neutron client to openstacksdk in case of getting subnet (see kuryr_kubernetes.utils.get_subnet function), but exceptions thrown by neutron client in vif module remains. In this patch we fix that. Closes-Bug: 1856000 Change-Id: Ic783c2a40b85d17f897a8b83ec541e9c66922f43
This commit is contained in:
@@ -20,7 +20,7 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from neutronclient.common import exceptions as n_exc
|
from neutronclient.common import exceptions as n_exc
|
||||||
from openstack import exceptions as o_exc
|
from openstack import exceptions as os_exc
|
||||||
from openstack.load_balancer.v2 import l7_policy as o_l7p
|
from openstack.load_balancer.v2 import l7_policy as o_l7p
|
||||||
from openstack.load_balancer.v2 import l7_rule as o_l7r
|
from openstack.load_balancer.v2 import l7_rule as o_l7r
|
||||||
from openstack.load_balancer.v2 import listener as o_lis
|
from openstack.load_balancer.v2 import listener as o_lis
|
||||||
@@ -378,18 +378,24 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
# support
|
# support
|
||||||
worker_subnet_id = CONF.pod_vif_nested.worker_nodes_subnet
|
worker_subnet_id = CONF.pod_vif_nested.worker_nodes_subnet
|
||||||
if worker_subnet_id:
|
if worker_subnet_id:
|
||||||
worker_subnet_cidr = utils.get_subnet_cidr(worker_subnet_id)
|
try:
|
||||||
neutron.create_security_group_rule({
|
worker_subnet_cidr = utils.get_subnet_cidr(
|
||||||
'security_group_rule': {
|
worker_subnet_id)
|
||||||
'direction': 'ingress',
|
neutron.create_security_group_rule({
|
||||||
'port_range_min': listener.port,
|
'security_group_rule': {
|
||||||
'port_range_max': listener.port,
|
'direction': 'ingress',
|
||||||
'protocol': listener.protocol,
|
'port_range_min': listener.port,
|
||||||
'security_group_id': sg_id,
|
'port_range_max': listener.port,
|
||||||
'remote_ip_prefix': worker_subnet_cidr,
|
'protocol': listener.protocol,
|
||||||
'description': listener.name,
|
'security_group_id': sg_id,
|
||||||
},
|
'remote_ip_prefix': worker_subnet_cidr,
|
||||||
})
|
'description': listener.name,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
except os_exc.ResourceNotFound:
|
||||||
|
LOG.exception('Failed when creating security group rule '
|
||||||
|
'due to nonexistent worker_subnet_id: %s',
|
||||||
|
worker_subnet_id)
|
||||||
except n_exc.NeutronClientException as ex:
|
except n_exc.NeutronClientException as ex:
|
||||||
if ex.status_code != requests.codes.conflict:
|
if ex.status_code != requests.codes.conflict:
|
||||||
LOG.exception('Failed when creating security group rule '
|
LOG.exception('Failed when creating security group rule '
|
||||||
@@ -695,7 +701,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
result = create(obj)
|
result = create(obj)
|
||||||
LOG.debug("Created %(obj)s", {'obj': result})
|
LOG.debug("Created %(obj)s", {'obj': result})
|
||||||
return result
|
return result
|
||||||
except o_exc.HttpException as e:
|
except os_exc.HttpException as e:
|
||||||
if e.status_code not in okay_codes:
|
if e.status_code not in okay_codes:
|
||||||
raise
|
raise
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
@@ -728,9 +734,9 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
try:
|
try:
|
||||||
delete(*args, **kwargs)
|
delete(*args, **kwargs)
|
||||||
return
|
return
|
||||||
except (o_exc.ConflictException, o_exc.BadRequestException):
|
except (os_exc.ConflictException, os_exc.BadRequestException):
|
||||||
self._wait_for_provisioning(loadbalancer, remaining)
|
self._wait_for_provisioning(loadbalancer, remaining)
|
||||||
except o_exc.NotFoundException:
|
except os_exc.NotFoundException:
|
||||||
return
|
return
|
||||||
|
|
||||||
raise k_exc.ResourceNotReady(obj)
|
raise k_exc.ResourceNotReady(obj)
|
||||||
@@ -761,7 +767,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
for remaining in self._provisioning_timer(timeout, interval):
|
for remaining in self._provisioning_timer(timeout, interval):
|
||||||
try:
|
try:
|
||||||
lbaas.get_load_balancer(loadbalancer.id)
|
lbaas.get_load_balancer(loadbalancer.id)
|
||||||
except o_exc.NotFoundException:
|
except os_exc.NotFoundException:
|
||||||
return
|
return
|
||||||
|
|
||||||
def _provisioning_timer(self, timeout,
|
def _provisioning_timer(self, timeout,
|
||||||
@@ -808,7 +814,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
lbaas = clients.get_loadbalancer_client()
|
lbaas = clients.get_loadbalancer_client()
|
||||||
try:
|
try:
|
||||||
response = lbaas.get_load_balancer(lb_uuid)
|
response = lbaas.get_load_balancer(lb_uuid)
|
||||||
except o_exc.NotFoundException:
|
except os_exc.NotFoundException:
|
||||||
LOG.debug("Couldn't find loadbalancer with uuid=%s", lb_uuid)
|
LOG.debug("Couldn't find loadbalancer with uuid=%s", lb_uuid)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -935,7 +941,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||||||
lbaas.update_l7_rule(
|
lbaas.update_l7_rule(
|
||||||
l7_rule.id, l7_rule.l7policy_id,
|
l7_rule.id, l7_rule.l7policy_id,
|
||||||
value=new_value)
|
value=new_value)
|
||||||
except o_exc.SDKException:
|
except os_exc.SDKException:
|
||||||
LOG.exception("Failed to update l7_rule- id=%s ", l7_rule.id)
|
LOG.exception("Failed to update l7_rule- id=%s ", l7_rule.id)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import netaddr
|
import netaddr
|
||||||
|
|
||||||
from oslo_log import log as logging
|
|
||||||
|
|
||||||
from neutronclient.common import exceptions as n_exc
|
from neutronclient.common import exceptions as n_exc
|
||||||
|
from openstack import exceptions as os_exc
|
||||||
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from kuryr_kubernetes import clients
|
from kuryr_kubernetes import clients
|
||||||
from kuryr_kubernetes import config
|
from kuryr_kubernetes import config
|
||||||
@@ -195,7 +195,8 @@ class NetworkPolicyDriver(base.NetworkPolicyDriver):
|
|||||||
|
|
||||||
# Add default rules to allow traffic from host and svc subnet
|
# Add default rules to allow traffic from host and svc subnet
|
||||||
self._add_default_np_rules(sg_id)
|
self._add_default_np_rules(sg_id)
|
||||||
except (n_exc.NeutronClientException, exceptions.ResourceNotReady):
|
except (n_exc.NeutronClientException, exceptions.ResourceNotReady,
|
||||||
|
os_exc.ResourceNotFound):
|
||||||
LOG.exception("Error creating security group for network policy "
|
LOG.exception("Error creating security group for network policy "
|
||||||
" %s", policy['metadata']['name'])
|
" %s", policy['metadata']['name'])
|
||||||
# If there's any issue creating sg rules, remove them
|
# If there's any issue creating sg rules, remove them
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutronclient.common import exceptions as n_exc
|
from neutronclient.common import exceptions as n_exc
|
||||||
|
from openstack import exceptions as os_exc
|
||||||
from oslo_cache import core as cache
|
from oslo_cache import core as cache
|
||||||
from oslo_config import cfg as oslo_cfg
|
from oslo_config import cfg as oslo_cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@@ -94,7 +95,7 @@ class VIFHandler(k8s_base.ResourceEventHandler):
|
|||||||
if not state:
|
if not state:
|
||||||
try:
|
try:
|
||||||
subnets = self._drv_subnets.get_subnets(pod, project_id)
|
subnets = self._drv_subnets.get_subnets(pod, project_id)
|
||||||
except (n_exc.NotFound, k_exc.K8sResourceNotFound):
|
except (os_exc.ResourceNotFound, k_exc.K8sResourceNotFound):
|
||||||
LOG.warning("Subnet does not exists. If namespace driver is "
|
LOG.warning("Subnet does not exists. If namespace driver is "
|
||||||
"used, probably the namespace for the pod is "
|
"used, probably the namespace for the pod is "
|
||||||
"already deleted. So this pod does not need to "
|
"already deleted. So this pod does not need to "
|
||||||
|
Reference in New Issue
Block a user