Commit 7546ae07 authored by Jérome Perrin's avatar Jérome Perrin

testnode: support chmod'ed files during directories cleanups

Because some tests or softwares can chmod'ed some files to make them
readonly, testnode should try to chmod the files to deletable state if
deleting them fail in the first place.
parent b22ed36e
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
import errno import errno
import os import os
import re import re
import shutil
from . import logger from . import logger
from .ProcessManager import SubprocessError from .ProcessManager import SubprocessError
from .Utils import rmtree
SVN_UP_REV = re.compile(r'^(?:At|Updated to) revision (\d+).$') SVN_UP_REV = re.compile(r'^(?:At|Updated to) revision (\d+).$')
SVN_CHANGED_REV = re.compile(r'^Last Changed Rev.*:\s*(\d+)', re.MULTILINE) SVN_CHANGED_REV = re.compile(r'^Last Changed Rev.*:\s*(\d+)', re.MULTILINE)
...@@ -149,7 +149,7 @@ class Updater(object): ...@@ -149,7 +149,7 @@ class Updater(object):
def deleteRepository(self): def deleteRepository(self):
logger.info("Wrong repository or wrong url, deleting repos %s", logger.info("Wrong repository or wrong url, deleting repos %s",
self.repository_path) self.repository_path)
shutil.rmtree(self.repository_path) rmtree(self.repository_path)
def checkRepository(self): def checkRepository(self):
# make sure that the repository is like we expect # make sure that the repository is like we expect
......
import os import os
import stat
import shutil import shutil
def rmtree(path):
"""Delete a path recursively.
Like shutil.rmtree, but supporting the case that some files or folder
might have been marked read only. """
def chmod_retry(func, path, _):
"""Make sure the file is writeable / the directory is executable.
"""
os.chmod(path, 0o777)
func(path)
shutil.rmtree(path, onerror=chmod_retry)
def createFolder(folder, clean=False): def createFolder(folder, clean=False):
if os.path.exists(folder): if os.path.exists(folder):
if not clean: if not clean:
return return
shutil.rmtree(folder) rmtree(folder)
os.mkdir(folder) os.mkdir(folder)
def deunicodeData(data): def deunicodeData(data):
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
import os import os
import json import json
import time import time
import shutil
import logging import logging
from contextlib import contextmanager from contextlib import contextmanager
from slapos.slap.slap import ConnectionError from slapos.slap.slap import ConnectionError
...@@ -39,6 +38,7 @@ from .NodeTestSuite import NodeTestSuite, SlapOSInstance ...@@ -39,6 +38,7 @@ from .NodeTestSuite import NodeTestSuite, SlapOSInstance
from .ScalabilityTestRunner import ScalabilityTestRunner from .ScalabilityTestRunner import ScalabilityTestRunner
from .UnitTestRunner import UnitTestRunner from .UnitTestRunner import UnitTestRunner
from .Utils import deunicodeData from .Utils import deunicodeData
from .Utils import rmtree
from .. import taskdistribution from .. import taskdistribution
MAX_LOG_TIME = 15 # time in days we should keep logs that we can see through MAX_LOG_TIME = 15 # time in days we should keep logs that we can see through
...@@ -74,7 +74,7 @@ class TestNode(object): ...@@ -74,7 +74,7 @@ class TestNode(object):
self.node_test_suite_dict.pop(reference, None) self.node_test_suite_dict.pop(reference, None)
logger.info("testnode.purgeOldTestSuite, DELETING : %r", fpath) logger.info("testnode.purgeOldTestSuite, DELETING : %r", fpath)
if os.path.isdir(fpath): if os.path.isdir(fpath):
shutil.rmtree(fpath) rmtree(fpath)
else: else:
os.remove(fpath) os.remove(fpath)
...@@ -218,7 +218,7 @@ shared = true ...@@ -218,7 +218,7 @@ shared = true
if os.path.isdir(folder_path): if os.path.isdir(folder_path):
if os.stat(folder_path).st_mtime < prune_time: if os.stat(folder_path).st_mtime < prune_time:
logger.debug("deleting log directory %r", folder_path) logger.debug("deleting log directory %r", folder_path)
shutil.rmtree(folder_path) rmtree(folder_path)
def _cleanupTemporaryFiles(self): def _cleanupTemporaryFiles(self):
""" """
...@@ -237,7 +237,7 @@ shared = true ...@@ -237,7 +237,7 @@ shared = true
if stat.st_uid == user_id and stat.st_mtime < prune_time: if stat.st_uid == user_id and stat.st_mtime < prune_time:
logger.debug("deleting temp directory %r", folder_path) logger.debug("deleting temp directory %r", folder_path)
if os.path.isdir(folder_path): if os.path.isdir(folder_path):
shutil.rmtree(folder_path) rmtree(folder_path)
else: else:
os.remove(folder_path) os.remove(folder_path)
except OSError: except OSError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment