Launcher: clean tempdir at start
If we shutdown while working on image uploads, we can leave files in the tempdir. Empty the tempdir at startup to avoid filling the disk, or leaving files that would conflict with future re-attempts of uploads. This adds an extra level, "zuul-launcher", to the temp dir, so that if users use the default of "/tmp", we will write images to "/tmp/zuul-launcher/..." and only attempt to delete files from that directory. The tests are updated to set the temp dir under the test root so that the tests use the correct filesystem and are cleaned up appropriately. Change-Id: I22bb1baee3ad00132ef7b764f607f9de0c7788fa
This commit is contained in:
@@ -2501,6 +2501,7 @@ class ZuulTestCase(BaseTestCase):
|
||||
self.config.set(
|
||||
'launcher', 'command_socket',
|
||||
os.path.join(self.test_root, 'launcher.socket'))
|
||||
self.config.set('launcher', 'temp_dir', self.test_root)
|
||||
|
||||
self.statsd = FakeStatsd()
|
||||
if self.config.has_section('statsd'):
|
||||
|
||||
@@ -1089,8 +1089,10 @@ class Launcher:
|
||||
self.zk_client, COMPONENT_REGISTRY.registry, self.component_info,
|
||||
self.wake_event.set, self.connection_filter)
|
||||
|
||||
self.temp_dir = get_default(self.config, 'launcher', 'temp_dir',
|
||||
'/tmp', expand_user=True)
|
||||
temp_root = get_default(self.config, 'launcher', 'temp_dir',
|
||||
'/tmp', expand_user=True)
|
||||
self.temp_dir = os.path.join(temp_root, 'zuul-launcher')
|
||||
os.makedirs(self.temp_dir, exist_ok=True)
|
||||
|
||||
self.command_map = {
|
||||
commandsocket.StopCommand.name: self.stop,
|
||||
@@ -2227,7 +2229,22 @@ class Launcher:
|
||||
return provider
|
||||
raise Exception(f"Unable to find {provider_cname}")
|
||||
|
||||
def _cleanTempdir(self):
|
||||
try:
|
||||
for f in os.listdir(self.temp_dir):
|
||||
path = os.path.join(self.temp_dir, f)
|
||||
if os.path.isfile(path):
|
||||
try:
|
||||
os.unlink(path)
|
||||
except Exception:
|
||||
self.log.exception("Error deleting %s", path)
|
||||
self.log.info("Deleted %s", path)
|
||||
except Exception:
|
||||
self.log.exception("Error cleanning temp dir")
|
||||
|
||||
def start(self):
|
||||
self.log.debug("Cleaning up temp dir")
|
||||
self._cleanTempdir()
|
||||
self.log.debug("Starting command processor")
|
||||
self._command_running = True
|
||||
self.command_socket.start()
|
||||
|
||||
Reference in New Issue
Block a user