Commit 6f3cb199 authored by Julien Muchembled's avatar Julien Muchembled

erp5testnode: fix clean up of old instance root folder under Python 3

This fixes commit ea4cb55b.

Our 'rmtree' helper has never been supposed to be called on a
non-existing folder: the ENOENT handling is an unrelated
implementation detail for Python 2.

Also drop erp5.util's rmtree and use the one from slapos.core,
which is a [testnode] dependency.
parent 0eeffeea
......@@ -31,11 +31,11 @@ import subprocess
import time
import xml_marshaller
import argparse
from six.moves import range
from slapos import client
from slapos.util import rmtree
from . import logger
from .Utils import createFolder, rmtree
from six.moves import range
from .Utils import createFolder
MAX_PARTITIONS = 10
MAX_SR_RETRIES = 3
......@@ -278,7 +278,8 @@ class SlapOSControler(object):
self._resetSoftware()
else:
createFolder(self.software_root)
rmtree(self.old_instance_root) # BBB
if os.path.exists(self.old_instance_root): # BBB
rmtree(self.old_instance_root)
instance_root = self.instance_root
# Delete any existing partition in order to not get its data (ex.
# MySQL DB content) from previous runs. To support changes of partition
......
......@@ -29,8 +29,7 @@ import os
import re
from . import logger
from .ProcessManager import SubprocessError
from .Utils import rmtree
from slapos.util import bytes2str, str2bytes
from slapos.util import bytes2str, str2bytes, rmtree
SVN_UP_REV = re.compile(r'^(?:At|Updated to) revision (\d+).$')
SVN_CHANGED_REV = re.compile(r'^Last Changed Rev.*:\s*(\d+)', re.MULTILINE)
......
import os
import stat
import shutil
import errno
import six
from six.moves import map
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, failed_path, exc_info):
"""Make sure the directories are executable and writable.
"""
# Depending on the Python version, the following items differ.
if six.PY3:
expected_error_type = PermissionError
expected_func = os.lstat
else:
expected_error_type = OSError
expected_func = os.listdir
e = exc_info[1]
if isinstance(e, expected_error_type):
if e.errno == errno.ENOENT:
# because we are calling again rmtree on listdir errors, this path might
# have been already deleted by the recursive call to rmtree.
return
if e.errno == errno.EACCES:
if func is expected_func:
os.chmod(failed_path, 0o700)
# corner case to handle errors in listing directories.
# https://bugs.python.org/issue8523
return shutil.rmtree(failed_path, onerror=chmod_retry)
# If parent directory is not writable, we still cannot delete the file.
# But make sure not to change the parent of the folder we are deleting.
if failed_path != path:
os.chmod(os.path.dirname(failed_path), 0o700)
return func(failed_path)
raise
shutil.rmtree(path, onerror=chmod_retry)
from slapos.util import rmtree
def createFolder(folder, clean=False):
if os.path.exists(folder):
......
......@@ -31,6 +31,7 @@ import logging
from six.moves.urllib.parse import urljoin
from contextlib import contextmanager
from slapos.slap.slap import ConnectionError
from slapos.util import rmtree
from . import logger, log_formatter
from .ProcessManager import SubprocessError, ProcessManager, CancellationError
from subprocess import CalledProcessError
......@@ -39,7 +40,6 @@ from .NodeTestSuite import NodeTestSuite, SlapOSInstance
from .ScalabilityTestRunner import ScalabilityTestRunner
from .UnitTestRunner import UnitTestRunner
from .Utils import deunicodeData
from .Utils import rmtree
from .. import taskdistribution
MAX_TEMP_TIME = 0.01 # time in days we should keep temp files
......
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