From f2d4bcb353589ec76445501bad27172783c00f94 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Wed, 30 Oct 2019 04:23:20 +0100 Subject: [PATCH] Fix `wo info` and add tweaks to `wo stack upgrade` --- CHANGELOG.md | 3 ++ setup.cfg | 15 +++++++++- tests/travis.sh | 4 +-- wo/cli/plugins/info.py | 52 ++++++++++++++++++--------------- wo/cli/plugins/site.py | 26 ++++++++++------- wo/cli/plugins/stack.py | 1 + wo/cli/plugins/stack_pref.py | 38 ++++++++++++------------ wo/cli/plugins/stack_upgrade.py | 3 +- wo/core/download.py | 4 +-- wo/core/git.py | 10 ++++--- wo/core/services.py | 5 ++-- wo/core/variables.py | 6 ++-- 12 files changed, 98 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c48c4ea..e432c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### v3.9.x - [Unreleased] +### v3.10.0 - 2019-10-30 + #### Added - WordOps install is now installed with pip from PyPi (easier, cleaner and safer) inside a wheel @@ -35,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - force-ssl.conf not removed after removing a site - `wo clean --opcache` not working with invalid SSL certificate - `wo stack install --cheat` wasn't working properly previously +- `wo info` failure depending on php-fpm pool name. ConfigParser will now detect the section name. ### v3.9.9.4 - 2019-10-18 diff --git a/setup.cfg b/setup.cfg index 4ee5196..514f780 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,4 +12,17 @@ cover-html-dir=coverage_report/ where=tests/ [metadata] -license-file = LICENSE \ No newline at end of file +license-file = LICENSE + +[flake8] +ignore = F405,W504,S322,S404,S603,s607,s602 +exclude = + # No need to traverse our git directory + .git, + # There's no value in checking cache directories + __pycache__, + # This contains our built documentation + build, + # This contains builds of flake8 that we don't want to check + dist +max-complexity = 10 \ No newline at end of file diff --git a/tests/travis.sh b/tests/travis.sh index 1b386d2..3691727 100644 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -225,6 +225,7 @@ echo -e ' various informations ' echo -e "${CGREEN}#############################################${CEND}" wp --allow-root --info wo site info wp.net +wo info echo -e "${CGREEN}#############################################${CEND}" echo -e ' wo stack purge ' @@ -244,6 +245,3 @@ for stack in $stack_purge; do fi done -if [ -n "$1" ]; then - cat /var/log/wo/test.log | ccze -A -p syslog -fi diff --git a/wo/cli/plugins/info.py b/wo/cli/plugins/info.py index cb505fe..da52efc 100644 --- a/wo/cli/plugins/info.py +++ b/wo/cli/plugins/info.py @@ -79,20 +79,22 @@ class WOInfoController(CementBaseController): max_execution_time = config['PHP']['max_execution_time'] config.read('/etc/{0}/fpm/pool.d/www.conf'.format("php/7.2")) - www_listen = config['www-php72']['listen'] - www_ping_path = config['www-php72']['ping.path'] - www_pm_status_path = config['www-php72']['pm.status_path'] - www_pm = config['www-php72']['pm'] - www_pm_max_requests = config['www-php72']['pm.max_requests'] - www_pm_max_children = config['www-php72']['pm.max_children'] - www_pm_start_servers = config['www-php72']['pm.start_servers'] - www_pm_min_spare_servers = config['www-php72']['pm.min_spare_servers'] - www_pm_max_spare_servers = config['www-php72']['pm.max_spare_servers'] - www_request_terminate_time = (config['www-php72'] + wo_sec = (config.sections())[0] + www_listen = config[[wo_sec]]['listen'] + www_ping_path = config[[wo_sec]]['ping.path'] + www_pm_status_path = config[[wo_sec]]['pm.status_path'] + www_pm = config[[wo_sec]]['pm'] + www_pm_max_requests = config[[wo_sec]]['pm.max_requests'] + www_pm_max_children = config[[wo_sec]]['pm.max_children'] + www_pm_start_servers = config[[wo_sec]]['pm.start_servers'] + www_pm_min_spare_servers = config[[wo_sec]]['pm.min_spare_servers'] + www_pm_max_spare_servers = config[[wo_sec]]['pm.max_spare_servers'] + www_request_terminate_time = (config[[wo_sec]] ['request_terminate_timeout']) try: - www_xdebug = (config['www-php72']['php_admin_flag[xdebug.profiler_enable' - '_trigger]']) + www_xdebug = ( + config[[wo_sec]]['php_admin_flag[xdebug.profiler_enable' + '_trigger]']) except Exception as e: Log.debug(self, "{0}".format(e)) www_xdebug = 'off' @@ -156,19 +158,20 @@ class WOInfoController(CementBaseController): max_execution_time = config['PHP']['max_execution_time'] config.read('/etc/php/7.3/fpm/pool.d/www.conf') - www_listen = config['www-php73']['listen'] - www_ping_path = config['www-php73']['ping.path'] - www_pm_status_path = config['www-php73']['pm.status_path'] - www_pm = config['www-php73']['pm'] - www_pm_max_requests = config['www-php73']['pm.max_requests'] - www_pm_max_children = config['www-php73']['pm.max_children'] - www_pm_start_servers = config['www-php73']['pm.start_servers'] - www_pm_min_spare_servers = config['www-php73']['pm.min_spare_servers'] - www_pm_max_spare_servers = config['www-php73']['pm.max_spare_servers'] - www_request_terminate_time = (config['www-php73'] + wo_sec = (config.sections())[0] + www_listen = config[wo_sec]['listen'] + www_ping_path = config[wo_sec]['ping.path'] + www_pm_status_path = config[wo_sec]['pm.status_path'] + www_pm = config[wo_sec]['pm'] + www_pm_max_requests = config[wo_sec]['pm.max_requests'] + www_pm_max_children = config[wo_sec]['pm.max_children'] + www_pm_start_servers = config[wo_sec]['pm.start_servers'] + www_pm_min_spare_servers = config[wo_sec]['pm.min_spare_servers'] + www_pm_max_spare_servers = config[wo_sec]['pm.max_spare_servers'] + www_request_terminate_time = (config[wo_sec] ['request_terminate_timeout']) try: - www_xdebug = (config['www-php73'] + www_xdebug = (config[wo_sec] ['php_admin_flag[xdebug.profiler_enable' '_trigger]']) except Exception as e: @@ -266,7 +269,8 @@ class WOInfoController(CementBaseController): if self.app.pargs.nginx: if (WOAptGet.is_installed(self, 'nginx-custom') or - WOAptGet.is_installed(self, 'nginx-wo')): + WOAptGet.is_installed(self, 'nginx-wo') or + (os.path.exists('/usr/bin/nginx'))): self.info_nginx() else: Log.error(self, "Nginx is not installed") diff --git a/wo/cli/plugins/site.py b/wo/cli/plugins/site.py index 41ee7f3..3f04551 100644 --- a/wo/cli/plugins/site.py +++ b/wo/cli/plugins/site.py @@ -78,7 +78,7 @@ class WOSiteController(CementBaseController): Log.error(self, "service nginx reload failed. " "check issues with `nginx -t` command") else: - Log.error(self, "nginx configuration file does not exist") + Log.error(self, 'nginx configuration file does not exist') @expose(help="Disable site example.com") def disable(self): @@ -106,7 +106,7 @@ class WOSiteController(CementBaseController): if not os.path.isfile('/etc/nginx/sites-enabled/{0}' .format(wo_domain)): Log.debug(self, "Site {0} already disabled".format(wo_domain)) - Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]") + Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE + "]") else: WOFileUtils.remove_symlink(self, '/etc/nginx/sites-enabled/{0}' @@ -176,7 +176,7 @@ class WOSiteController(CementBaseController): dbname=wo_db_name, dbuser=wo_db_user, php_version=php_version, dbpass=wo_db_pass, - ssl=ssl, sslprovider=sslprovider, sslexpiry=sslexpiry, + ssl=ssl, sslprovider=sslprovider, sslexpiry=sslexpiry, type=sitetype + " " + cachetype + " ({0})" .format("enabled" if siteinfo.is_enabled else "disabled")) @@ -452,7 +452,7 @@ class WOSiteCreateController(CementBaseController): if stype == 'proxy': data = dict(site_name=wo_domain, www_domain=wo_www_domain, - static=True, basic=False, php73=False, wp=False, + static=True, basic=False, php73=False, wp=False, wpfc=False, wpsc=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot) @@ -463,7 +463,7 @@ class WOSiteCreateController(CementBaseController): if pargs.php73: data = dict(site_name=wo_domain, www_domain=wo_www_domain, - static=False, basic=False, php73=True, wp=False, + static=False, basic=False, php73=True, wp=False, wpfc=False, wpsc=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot) @@ -471,7 +471,7 @@ class WOSiteCreateController(CementBaseController): if stype in ['html', 'php']: data = dict(site_name=wo_domain, www_domain=wo_www_domain, - static=True, basic=False, php73=False, wp=False, + static=True, basic=False, php73=False, wp=False, wpfc=False, wpsc=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot) @@ -483,7 +483,7 @@ class WOSiteCreateController(CementBaseController): elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: data = dict(site_name=wo_domain, www_domain=wo_www_domain, - static=False, basic=True, wp=False, wpfc=False, + static=False, basic=True, wp=False, wpfc=False, wpsc=False, wpredis=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot, @@ -509,8 +509,7 @@ class WOSiteCreateController(CementBaseController): elif data: data['php73'] = False - if ((not pargs.wpfc) and - (not pargs.wpsc) and + if ((not pargs.wpfc) and (not pargs.wpsc) and (not pargs.wprocket) and (not pargs.wpce) and (not pargs.wpredis)): @@ -1131,7 +1130,7 @@ class WOSiteUpdateController(CementBaseController): if stype == 'php': data = dict( site_name=wo_domain, www_domain=wo_www_domain, - static=False, basic=True, wp=False, wpfc=False, + static=False, basic=True, wp=False, wpfc=False, wpsc=False, wpredis=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot, currsitetype=oldsitetype, currcachetype=oldcachetype) @@ -1140,7 +1139,7 @@ class WOSiteUpdateController(CementBaseController): data = dict( site_name=wo_domain, www_domain=wo_www_domain, - static=False, basic=True, wp=False, wpfc=False, + static=False, basic=True, wp=False, wpfc=False, wpsc=False, wpredis=False, wprocket=False, wpce=False, multisite=False, wpsubdir=False, webroot=wo_site_webroot, wo_db_name='', wo_db_user='', wo_db_pass='', @@ -1294,6 +1293,11 @@ class WOSiteUpdateController(CementBaseController): letsencrypt = False acme_subdomain = False acme_wildcard = False + else: + data['letsencrypt'] = False + letsencrypt = False + acme_subdomain = False + acme_wildcard = False if not (acme_subdomain is True): if letsencrypt is check_ssl: diff --git a/wo/cli/plugins/stack.py b/wo/cli/plugins/stack.py index 46681d7..b21257e 100644 --- a/wo/cli/plugins/stack.py +++ b/wo/cli/plugins/stack.py @@ -539,6 +539,7 @@ class WOStackController(CementBaseController): Log.info(self, "Successfully installed packages") else: return self.msg + return 0 @expose(help="Remove packages") def remove(self): diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index d55f1d2..91f8233 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -814,14 +814,14 @@ def post_pref(self, apt_packages, packages, upgrade=False): "/etc/mysql/my.cnf.default-pkg") wo_ram = psutil.virtual_memory().total / (1024 * 1024) # set InnoDB variable depending on the RAM available - wo_ram_innodb = int(wo_ram*0.3) - wo_ram_log_buffer = int(wo_ram_innodb*0.25) - wo_ram_log_size = int(wo_ram_log_buffer*0.5) + wo_ram_innodb = int(wo_ram * 0.3) + wo_ram_log_buffer = int(wo_ram_innodb * 0.25) + wo_ram_log_size = int(wo_ram_log_buffer * 0.5) if (wo_ram < 2000): wo_innodb_instance = int(1) tmp_table_size = int(32) elif (wo_ram > 2000) and (wo_ram < 64000): - wo_innodb_instance = int(wo_ram/1000) + wo_innodb_instance = int(wo_ram / 1000) tmp_table_size = int(128) elif (wo_ram > 64000): wo_innodb_instance = int(64) @@ -1015,24 +1015,26 @@ def post_pref(self, apt_packages, packages, upgrade=False): if wo_ram < 1024: Log.debug(self, "Setting maxmemory variable to " "{0} in redis.conf" - .format(int(wo_ram*1024*1024*0.1))) - WOFileUtils.searchreplace(self, - "/etc/redis/redis.conf", - "# maxmemory ", - "maxmemory {0}" - .format - (int(wo_ram*1024*1024*0.1))) + .format(int(wo_ram * 1024 * 1024 * 0.1))) + WOFileUtils.searchreplace + (self, + "/etc/redis/redis.conf", + "# maxmemory ", + "maxmemory {0}" + .format + (int(wo_ram * 1024 * 1024 * 0.1))) else: Log.debug(self, "Setting maxmemory variable to {0} " "in redis.conf" - .format(int(wo_ram*1024*1024*0.2))) - WOFileUtils.searchreplace(self, - "/etc/redis/redis.conf", - "# maxmemory ", - "maxmemory {0}" - .format - (int(wo_ram*1024*1024*0.2))) + .format(int(wo_ram * 1024 * 1024 * 0.2))) + WOFileUtils.searchreplace( + self, + "/etc/redis/redis.conf", + "# maxmemory ", + "maxmemory {0}" + .format + (int(wo_ram * 1024 * 1024 * 0.2))) Log.debug( self, "Setting maxmemory-policy variable to " diff --git a/wo/cli/plugins/stack_upgrade.py b/wo/cli/plugins/stack_upgrade.py index 976aa75..accc0cf 100644 --- a/wo/cli/plugins/stack_upgrade.py +++ b/wo/cli/plugins/stack_upgrade.py @@ -3,7 +3,7 @@ import shutil from cement.core.controller import CementBaseController, expose -from wo.cli.plugins.stack_pref import post_pref, pre_pref +from wo.cli.plugins.stack_pref import post_pref, pre_pref, pre_stack from wo.core.aptget import WOAptGet from wo.core.download import WODownload from wo.core.extract import WOExtract @@ -178,6 +178,7 @@ class WOStackUpgradeController(CementBaseController): if ((not (apt_packages)) and (not(packages))): self.app.args.print_help() else: + pre_stack(self) if (apt_packages): if (("php7.2-fpm" not in apt_packages) and ("php7.3-fpm" not in apt_packages) and diff --git a/wo/core/download.py b/wo/core/download.py index bd7a725..da4fe4f 100644 --- a/wo/core/download.py +++ b/wo/core/download.py @@ -27,8 +27,8 @@ class WODownload(): if req.encoding is None: req.encoding = 'utf-8' out_file.write(req.content) - Log.info(self, "{0}".format("[" + Log.ENDC + "Done" - + Log.OKBLUE + "]")) + Log.info(self, "{0}".format("[" + Log.ENDC + "Done" + + Log.OKBLUE + "]")) except requests.RequestException as e: Log.debug(self, "[{err}]".format(err=str(e.reason))) Log.error(self, "Unable to download file, {0}" diff --git a/wo/core/git.py b/wo/core/git.py index a157282..5bf903f 100644 --- a/wo/core/git.py +++ b/wo/core/git.py @@ -21,7 +21,7 @@ class WOGit: git = git.bake("--git-dir={0}/.git".format(path), "--work-tree={0}".format(path)) if os.path.isdir(path): - if not os.path.isdir(path+"/.git"): + if not os.path.isdir(path + "/.git"): try: Log.debug(self, "WOGit: git init at {0}" .format(path)) @@ -67,11 +67,13 @@ class WOGit: git = git.bake("--git-dir={0}/.git".format(path), "--work-tree={0}".format(path)) if os.path.isdir(path): - if not os.path.isdir(path+"/.git"): - Log.error(self, "Unable to find a git repository at {0}" + if not os.path.isdir(path + "/.git"): + Log.error( + self, "Unable to find a git repository at {0}" .format(path)) try: - Log.debug(self, "WOGit: git stash --include-untracked at {0}" + Log.debug( + self, "WOGit: git stash --include-untracked at {0}" .format(path)) git.stash("push", "--include-untracked", "-m {0}" .format(msg)) diff --git a/wo/core/services.py b/wo/core/services.py index 7b4d748..1c59e63 100644 --- a/wo/core/services.py +++ b/wo/core/services.py @@ -43,7 +43,8 @@ class WOService(): return True else: Log.debug(self, "{0}".format(retcode[1])) - Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]") + Log.info(self, "[" + Log.FAIL + + "Failed" + Log.OKBLUE + "]") return False except OSError as e: Log.debug(self, "{0}".format(e)) @@ -65,7 +66,7 @@ class WOService(): return True else: Log.debug(self, "{0}".format(retcode[1])) - Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]") + Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE + "]") return False except OSError as e: Log.debug(self, "{0}".format(e)) diff --git a/wo/core/variables.py b/wo/core/variables.py index 0bafd50..d0b45ff 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -64,7 +64,7 @@ class WOVar(): # WordOps git configuration management config = configparser.ConfigParser() - config.read(os.path.expanduser("~")+'/.gitconfig') + config.read(os.path.expanduser("~") + '/.gitconfig') try: wo_user = config['user']['name'] wo_email = config['user']['email'] @@ -90,7 +90,7 @@ class WOVar(): git.config("--global", "user.email", "{0}".format(wo_email)) if not os.path.isfile('/root/.gitconfig'): - copy2(os.path.expanduser("~")+'/.gitconfig', '/root/.gitconfig') + copy2(os.path.expanduser("~") + '/.gitconfig', '/root/.gitconfig') # MySQL hostname wo_mysql_host = "" @@ -98,7 +98,7 @@ class WOVar(): if os.path.exists('/etc/mysql/conf.d/my.cnf'): cnfpath = "/etc/mysql/conf.d/my.cnf" else: - cnfpath = os.path.expanduser("~")+"/.my.cnf" + cnfpath = os.path.expanduser("~") + "/.my.cnf" if [cnfpath] == config.read(cnfpath): try: wo_mysql_host = config.get('client', 'host')