From 635be2a3ae8925c639406961d02dadf7074afc6d Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 22 Feb 2020 10:53:04 -0600 Subject: [PATCH] Fix cleanup of symlink fixtures These aren't all getting cleaned up, which winds up breaking the second runs. Instead of doing addCleanup with a method that does the loop again, which can fail in the middle and not clean up subsequent files, add an individual cleanup when we add the symlink. This results in all of the symlinks consistently being cleaned. Change-Id: Id5a5b09c830ad2ad3bb0b77fb9dbdc494c629824 --- .../library/test_generate_manifest.py | 9 +-------- .../library/test_zuul_swift_upload.py | 9 +-------- .../library/test_zuul_google_storage_upload.py | 9 +-------- .../upload-logs-swift/library/test_zuul_swift_upload.py | 9 +-------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/roles/generate-zuul-manifest/library/test_generate_manifest.py b/roles/generate-zuul-manifest/library/test_generate_manifest.py index a239523da..69ce4a194 100644 --- a/roles/generate-zuul-manifest/library/test_generate_manifest.py +++ b/roles/generate-zuul-manifest/library/test_generate_manifest.py @@ -43,17 +43,10 @@ class SymlinkFixture(fixtures.Fixture): ] def _setUp(self): - self._cleanup() for (src, target) in self.links: path = os.path.join(FIXTURE_DIR, 'links', src) os.symlink(target, path) - self.addCleanup(self._cleanup) - - def _cleanup(self): - for (src, target) in self.links: - path = os.path.join(FIXTURE_DIR, 'links', src) - if os.path.exists(path): - os.unlink(path) + self.addCleanup(os.unlink, path) class TestFileList(testtools.TestCase): diff --git a/roles/test-upload-logs-swift/library/test_zuul_swift_upload.py b/roles/test-upload-logs-swift/library/test_zuul_swift_upload.py index 9b9053213..6577c31cc 100644 --- a/roles/test-upload-logs-swift/library/test_zuul_swift_upload.py +++ b/roles/test-upload-logs-swift/library/test_zuul_swift_upload.py @@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture): ] def _setUp(self): - self._cleanup() for (src, target) in self.links: path = os.path.join(FIXTURE_DIR, 'links', src) os.symlink(target, path) - self.addCleanup(self._cleanup) - - def _cleanup(self): - for (src, target) in self.links: - path = os.path.join(FIXTURE_DIR, 'links', src) - if os.path.exists(path): - os.unlink(path) + self.addCleanup(os.unlink, path) class TestFileList(testtools.TestCase): diff --git a/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py b/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py index 01fd71c7f..ed5c55627 100644 --- a/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py +++ b/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py @@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture): ] def _setUp(self): - self._cleanup() for (src, target) in self.links: path = os.path.join(FIXTURE_DIR, 'links', src) os.symlink(target, path) - self.addCleanup(self._cleanup) - - def _cleanup(self): - for (src, target) in self.links: - path = os.path.join(FIXTURE_DIR, 'links', src) - if os.path.exists(path): - os.unlink(path) + self.addCleanup(os.unlink, path) class TestFileList(testtools.TestCase): diff --git a/roles/upload-logs-swift/library/test_zuul_swift_upload.py b/roles/upload-logs-swift/library/test_zuul_swift_upload.py index 9b9053213..6577c31cc 100644 --- a/roles/upload-logs-swift/library/test_zuul_swift_upload.py +++ b/roles/upload-logs-swift/library/test_zuul_swift_upload.py @@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture): ] def _setUp(self): - self._cleanup() for (src, target) in self.links: path = os.path.join(FIXTURE_DIR, 'links', src) os.symlink(target, path) - self.addCleanup(self._cleanup) - - def _cleanup(self): - for (src, target) in self.links: - path = os.path.join(FIXTURE_DIR, 'links', src) - if os.path.exists(path): - os.unlink(path) + self.addCleanup(os.unlink, path) class TestFileList(testtools.TestCase):