Factorize stuff in cleaning function to avoid repeating so much stuff

This commit is contained in:
Alexandre Aubin 2020-03-24 04:47:21 +01:00
parent 7e8a00b9dc
commit 94c066dc53

View file

@ -30,65 +30,31 @@ def clean():
os.system("mkdir -p /etc/ssowat/") os.system("mkdir -p /etc/ssowat/")
app_ssowatconf() app_ssowatconf()
# Gotta first remove break yo system test_apps = ["break_yo_system", "legacy_app", "legacy_app__2", "full_domain_app"]
# because some remaining stuff might
# make the other app_remove crashs ;P
if _is_installed("break_yo_system"):
app_remove("break_yo_system")
if _is_installed("legacy_app"): for test_app in test_apps:
app_remove("legacy_app")
if _is_installed("full_domain_app"): if _is_installed(test_app):
app_remove("full_domain_app") app_remove(test_app)
to_remove = [] for filepath in glob.glob("/etc/nginx/conf.d/*.d/*%s*" % test_app):
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*legacy*") os.remove(filepath)
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*full_domain*") for folderpath in glob.glob("/etc/yunohost/apps/*%s*" % test_app):
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*break_yo_system*") shutil.rmtree(folderpath, ignore_errors=True)
for filepath in to_remove: for folderpath in glob.glob("/var/www/*%s*" % test_app):
os.remove(filepath) shutil.rmtree(folderpath, ignore_errors=True)
to_remove = [] os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE %s' \"" % test_app)
to_remove += glob.glob("/etc/yunohost/apps/*legacy_app*") os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER %s@localhost'\"" % test_app)
to_remove += glob.glob("/etc/yunohost/apps/*full_domain_app*")
to_remove += glob.glob("/etc/yunohost/apps/*break_yo_system*")
to_remove += glob.glob("/var/www/*legacy*")
to_remove += glob.glob("/var/www/*full_domain*")
for folderpath in to_remove:
shutil.rmtree(folderpath, ignore_errors=True)
os.system("systemctl reset-failed nginx") # Reset failed quota for service to avoid running into start-limit rate ? os.system("systemctl reset-failed nginx") # Reset failed quota for service to avoid running into start-limit rate ?
os.system("systemctl start nginx") os.system("systemctl start nginx")
# Clean permission # Clean permissions
for permission_name in user_permission_list(short=True)["permissions"]: for permission_name in user_permission_list(short=True)["permissions"]:
if "legacy_app" in permission_name or \ if any(test_app in permission_name for test_app in test_apps):
"full_domain_app" in permission_name or \
"break_yo_system" in permission_name:
permission_delete(permission_name, force=True) permission_delete(permission_name, force=True)
# Clean database
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app' \"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app__2'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app__2@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app__3'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app__3@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain__2'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain__2@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain__3'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain__3@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system__2'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system__2@localhost'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system__3'\"")
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system__3@localhost'\"")
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def check_LDAP_db_integrity_call(): def check_LDAP_db_integrity_call():
check_LDAP_db_integrity() check_LDAP_db_integrity()