Log pyroute2 RuntimeError details
pyroute2 has a curious way of reporting details of RuntimeError raised when an IPDB transaction fails - it just sets the .debug property of the exception to a dictionary containing additional info. This is not printed by default, meaning that we end up with ambiguous RuntimeError in the logs when anything wrong happens. This commit improves this by making sure we print traceback included in that additional info. Change-Id: Id86a96a662c071533e187fa1b6d87783a844086a
This commit is contained in:
parent
1011502b57
commit
5eaafbc825
|
@ -22,6 +22,7 @@ from oslo_log import log as logging
|
|||
import pyroute2
|
||||
from stevedore import driver as stv_driver
|
||||
|
||||
from kuryr_kubernetes.cni import utils as cni_utils
|
||||
from kuryr_kubernetes import config
|
||||
from kuryr_kubernetes import constants
|
||||
from kuryr_kubernetes import utils
|
||||
|
@ -150,6 +151,7 @@ def _need_configure_l3(vif):
|
|||
return True
|
||||
|
||||
|
||||
@cni_utils.log_ipdb
|
||||
def connect(vif, instance_info, ifname, netns=None, report_health=None,
|
||||
is_default_gateway=True, container_id=None):
|
||||
driver = _get_binding_driver(vif)
|
||||
|
@ -161,6 +163,7 @@ def connect(vif, instance_info, ifname, netns=None, report_health=None,
|
|||
_configure_l3(vif, ifname, netns, is_default_gateway)
|
||||
|
||||
|
||||
@cni_utils.log_ipdb
|
||||
def disconnect(vif, instance_info, ifname, netns=None, report_health=None,
|
||||
container_id=None, **kwargs):
|
||||
driver = _get_binding_driver(vif)
|
||||
|
@ -170,6 +173,7 @@ def disconnect(vif, instance_info, ifname, netns=None, report_health=None,
|
|||
os_vif.unplug(vif, instance_info)
|
||||
|
||||
|
||||
@cni_utils.log_ipdb
|
||||
def cleanup(ifname, netns):
|
||||
with get_ipdb(netns) as c_ipdb:
|
||||
if ifname in c_ipdb.interfaces:
|
||||
|
|
|
@ -12,12 +12,19 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import functools
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
PROC_ONE_CGROUP_PATH = '/proc/1/cgroup'
|
||||
CONTAINER_RUNTIME_CGROUP_IDS = (
|
||||
'docker', # This is set by docker/moby
|
||||
'libpod', # This is set by podman
|
||||
)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def running_under_container_runtime(proc_one_cg_path=PROC_ONE_CGROUP_PATH):
|
||||
"""Returns True iff the CNI process is under a known container runtime."""
|
||||
|
@ -63,3 +70,19 @@ class CNIParameters(object):
|
|||
def __repr__(self):
|
||||
return repr({key: value for key, value in self.__dict__.items() if
|
||||
key.startswith('CNI_')})
|
||||
|
||||
|
||||
def log_ipdb(func):
|
||||
@functools.wraps(func)
|
||||
def with_logging(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except RuntimeError as e:
|
||||
try:
|
||||
LOG.error('Error when manipulating network interfaces')
|
||||
LOG.error(e.debug['traceback'])
|
||||
LOG.debug('Full debugging info: %s', e.debug)
|
||||
except AttributeError:
|
||||
pass
|
||||
raise
|
||||
return with_logging
|
||||
|
|
Loading…
Reference in New Issue