X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Fvpp_pg_interface.py;h=01f10fccfc956c562750eb0283bdd0b5a7cd3cb5;hb=b23ffd7ef216463c35b75c831e6a27e58971f4ec;hp=567b81de7c08bf6f46d42edc941df662c869999f;hpb=8ccc6b350703d3390633636d2b1c2f578f37cb21;p=vpp.git diff --git a/test/vpp_pg_interface.py b/test/vpp_pg_interface.py index 567b81de7c0..01f10fccfc9 100644 --- a/test/vpp_pg_interface.py +++ b/test/vpp_pg_interface.py @@ -5,6 +5,7 @@ import struct import time from traceback import format_exc, format_stack +from config import config import scapy.compat from scapy.utils import wrpcap, rdpcap, PcapReader from scapy.plist import PacketList @@ -133,9 +134,20 @@ class VppPGInterface(VppInterface): self._cap_name = "pcap%u-sw_if_index-%s" % ( self.pg_index, self.sw_if_index) - def rename_old_pcap_file(self, path, counter): + def handle_old_pcap_file(self, path, counter): filename = os.path.basename(path) + + if not config.keep_pcaps: + try: + self.test.logger.debug(f"Removing {path}") + os.remove(path) + except OSError: + self.test.logger.debug(f"OSError: Could not remove {path}") + return + + # keep try: + if os.path.isfile(path): name = "%s/history.[timestamp:%f].[%s-counter:%04d].%s" % \ (self.test.tempdir, @@ -143,8 +155,7 @@ class VppPGInterface(VppInterface): self.name, counter, filename) - self.test.logger.debug("Renaming %s->%s" % - (path, name)) + self.test.logger.debug("Renaming %s->%s" % (path, name)) os.rename(path, name) except OSError: self.test.logger.debug("OSError: Could not rename %s %s" % @@ -157,7 +168,7 @@ class VppPGInterface(VppInterface): """ # disable the capture to flush the capture self.disable_capture() - self.rename_old_pcap_file(self.out_path, self.out_history_counter) + self.handle_old_pcap_file(self.out_path, self.out_history_counter) # FIXME this should be an API, but no such exists atm self.test.vapi.cli(self.capture_cli) self._pcap_reader = None