Currently, VethFixture cleanup tries to delete veth from their
namespaces even if they don't exist anymore (without crashing the
cleanup). It implies an extra trace if an error is raised which can be
confusing.
This change avoids to try deleting a veth from a nonexistent namespace
in the fixture VethFixture.
Closes-Bug: #
1506862
Change-Id: I5d0192998d2f3f8d1a6f783769ae9bfcb4bae7f2
def destroy(self):
for port in self.ports:
ip_wrapper = ip_lib.IPWrapper(port.namespace)
- try:
- ip_wrapper.del_veth(port.name)
- break
- except RuntimeError:
- # NOTE(cbrandily): It seems a veth is automagically deleted
- # when a namespace owning a veth endpoint is deleted.
- pass
+ if ip_wrapper.netns.exists(port.namespace):
+ try:
+ ip_wrapper.del_veth(port.name)
+ break
+ except RuntimeError:
+ # NOTE(cbrandily): It seems a veth is automagically deleted
+ # when a namespace owning a veth endpoint is deleted.
+ pass
@staticmethod
def get_peer_name(name):