[enh] Avoid to modify untestable migrations

This commit is contained in:
ljf 2019-08-14 17:37:43 +02:00
parent fac44f44d0
commit 0a2ba102c8

View file

@ -25,54 +25,54 @@ class MyMigration(Migration):
dependencies = ["migrate_to_stretch"] dependencies = ["migrate_to_stretch"]
def run(self): def run(self):
try: # Get list of php5 pool files
# Get list of php5 pool files php5_pool_files = glob.glob("{}/*.conf".format(PHP5_POOLS))
php5_pool_files = glob.glob("{}/*.conf".format(PHP5_POOLS))
# Keep only basenames # Keep only basenames
php5_pool_files = [os.path.basename(f) for f in php5_pool_files] php5_pool_files = [os.path.basename(f) for f in php5_pool_files]
# Ignore the "www.conf" (default stuff, probably don't want to touch it ?) # Ignore the "www.conf" (default stuff, probably don't want to touch it ?)
php5_pool_files = [f for f in php5_pool_files if f != "www.conf"] php5_pool_files = [f for f in php5_pool_files if f != "www.conf"]
for f in php5_pool_files: for f in php5_pool_files:
# Copy the files to the php7 pool # Copy the files to the php7 pool
src = "{}/{}".format(PHP5_POOLS, f) src = "{}/{}".format(PHP5_POOLS, f)
dest = "{}/{}".format(PHP7_POOLS, f) dest = "{}/{}".format(PHP7_POOLS, f)
copy2(src, dest) copy2(src, dest)
# Replace the socket prefix if it's found # Replace the socket prefix if it's found
c = "sed -i -e 's@{}@{}@g' {}".format(PHP5_SOCKETS_PREFIX, PHP7_SOCKETS_PREFIX, dest) c = "sed -i -e 's@{}@{}@g' {}".format(PHP5_SOCKETS_PREFIX, PHP7_SOCKETS_PREFIX, dest)
os.system(c) os.system(c)
# Also add a comment that it was automatically moved from php5 # Also add a comment that it was automatically moved from php5
# (for human traceability and backward migration) # (for human traceability and backward migration)
c = "sed -i '1i {}' {}".format(MIGRATION_COMMENT, dest) c = "sed -i '1i {}' {}".format(MIGRATION_COMMENT, dest)
os.system(c) os.system(c)
# Some old comments starting with '#' instead of ';' are not # Some old comments starting with '#' instead of ';' are not
# compatible in php7 # compatible in php7
c = "sed -i 's/^#/;#/g' {}".format(dest) c = "sed -i 's/^#/;#/g' {}".format(dest)
os.system(c) os.system(c)
# Reload/restart the php pools # Reload/restart the php pools
_run_service_command("restart", "php7.0-fpm") _run_service_command("restart", "php7.0-fpm")
_run_service_command("enable", "php7.0-fpm") _run_service_command("enable", "php7.0-fpm")
os.system("systemctl stop php5-fpm") os.system("systemctl stop php5-fpm")
os.system("systemctl disable php5-fpm") os.system("systemctl disable php5-fpm")
os.system("rm /etc/logrotate.d/php5-fpm") # We remove this otherwise the logrotate cron will be unhappy os.system("rm /etc/logrotate.d/php5-fpm") # We remove this otherwise the logrotate cron will be unhappy
# Get list of nginx conf file # Get list of nginx conf file
nginx_conf_files = glob.glob("/etc/nginx/conf.d/*.d/*.conf") nginx_conf_files = glob.glob("/etc/nginx/conf.d/*.d/*.conf")
for f in nginx_conf_files: for f in nginx_conf_files:
# Replace the socket prefix if it's found # Replace the socket prefix if it's found
c = "sed -i -e 's@{}@{}@g' {}".format(PHP5_SOCKETS_PREFIX, PHP7_SOCKETS_PREFIX, f) c = "sed -i -e 's@{}@{}@g' {}".format(PHP5_SOCKETS_PREFIX, PHP7_SOCKETS_PREFIX, f)
os.system(c) os.system(c)
# Reload nginx # Reload nginx
_run_service_command("reload", "nginx") _run_service_command("reload", "nginx")
except Exception:
def backward(self):
# Get list of php7 pool files # Get list of php7 pool files
php7_pool_files = glob.glob("{}/*.conf".format(PHP7_POOLS)) php7_pool_files = glob.glob("{}/*.conf".format(PHP7_POOLS))
@ -97,4 +97,3 @@ class MyMigration(Migration):
# Reload nginx # Reload nginx
_run_service_command("reload", "nginx") _run_service_command("reload", "nginx")
raise