mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
admins: bunch of fixes
This commit is contained in:
parent
888f1d8e55
commit
3758611d13
4 changed files with 31 additions and 24 deletions
|
@ -19,6 +19,8 @@ class MyMigration(Migration):
|
||||||
introduced_in_version = "11.1" # FIXME?
|
introduced_in_version = "11.1" # FIXME?
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
|
ldap_migration_started = False
|
||||||
|
|
||||||
@Migration.ldap_migration
|
@Migration.ldap_migration
|
||||||
def run(self, *args):
|
def run(self, *args):
|
||||||
|
|
||||||
|
@ -48,9 +50,10 @@ yunohost tools migrations run""",
|
||||||
raw_msg=True
|
raw_msg=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.ldap_migration_started = True
|
||||||
|
|
||||||
stuff_to_delete = [
|
stuff_to_delete = [
|
||||||
"cn=admin,ou=sudo",
|
"cn=admin,ou=sudo",
|
||||||
"cn=admins,ou=sudo"
|
|
||||||
"cn=admin",
|
"cn=admin",
|
||||||
"cn=admins,ou=groups",
|
"cn=admins,ou=groups",
|
||||||
]
|
]
|
||||||
|
@ -75,7 +78,7 @@ yunohost tools migrations run""",
|
||||||
{
|
{
|
||||||
"cn": ["admins"],
|
"cn": ["admins"],
|
||||||
"objectClass": ["top", "posixGroup", "groupOfNamesYnh", "mailGroup"],
|
"objectClass": ["top", "posixGroup", "groupOfNamesYnh", "mailGroup"],
|
||||||
"gidNumber": [4001],
|
"gidNumber": ["4001"],
|
||||||
"mail": ["root", "admin", "admins", "webmaster", "postmaster", "abuse"],
|
"mail": ["root", "admin", "admins", "webmaster", "postmaster", "abuse"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from yunohost.authenticators.ldap_admin import Authenticator as LDAPAuth
|
from yunohost.authenticators.ldap_admin import Authenticator as LDAPAuth
|
||||||
from yunohost.tools import tools_adminpw
|
from yunohost.tools import tools_rootpw
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
@ -13,7 +13,7 @@ def setup_function(function):
|
||||||
if os.system("systemctl is-active slapd") != 0:
|
if os.system("systemctl is-active slapd") != 0:
|
||||||
os.system("systemctl start slapd && sleep 3")
|
os.system("systemctl start slapd && sleep 3")
|
||||||
|
|
||||||
tools_adminpw("yunohost", check_strength=False)
|
tools_rootpw("yunohost", check_strength=False)
|
||||||
|
|
||||||
|
|
||||||
def test_authenticate():
|
def test_authenticate():
|
||||||
|
@ -47,7 +47,7 @@ def test_authenticate_change_password():
|
||||||
|
|
||||||
LDAPAuth().authenticate_credentials(credentials="yunohost")
|
LDAPAuth().authenticate_credentials(credentials="yunohost")
|
||||||
|
|
||||||
tools_adminpw("plopette", check_strength=False)
|
tools_rootpw("plopette", check_strength=False)
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
LDAPAuth().authenticate_credentials(credentials="yunohost")
|
LDAPAuth().authenticate_credentials(credentials="yunohost")
|
||||||
|
|
|
@ -11,7 +11,6 @@ from yunohost.user import (
|
||||||
user_import,
|
user_import,
|
||||||
user_export,
|
user_export,
|
||||||
FIELDS_FOR_IMPORT,
|
FIELDS_FOR_IMPORT,
|
||||||
FIRST_ALIASES,
|
|
||||||
user_group_list,
|
user_group_list,
|
||||||
user_group_create,
|
user_group_create,
|
||||||
user_group_delete,
|
user_group_delete,
|
||||||
|
@ -175,7 +174,6 @@ def test_import_user(mocker):
|
||||||
|
|
||||||
def test_export_user(mocker):
|
def test_export_user(mocker):
|
||||||
result = user_export()
|
result = user_export()
|
||||||
aliases = ",".join([alias + maindomain for alias in FIRST_ALIASES])
|
|
||||||
should_be = (
|
should_be = (
|
||||||
"username;firstname;lastname;password;mail;mail-alias;mail-forward;mailbox-quota;groups\r\n"
|
"username;firstname;lastname;password;mail;mail-alias;mail-forward;mailbox-quota;groups\r\n"
|
||||||
f"alice;Alice;White;;alice@{maindomain};{aliases};;0;dev\r\n"
|
f"alice;Alice;White;;alice@{maindomain};{aliases};;0;dev\r\n"
|
||||||
|
|
40
src/tools.py
40
src/tools.py
|
@ -30,7 +30,7 @@ from typing import List
|
||||||
from moulinette import Moulinette, m18n
|
from moulinette import Moulinette, m18n
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
from moulinette.utils.process import call_async_output
|
from moulinette.utils.process import call_async_output
|
||||||
from moulinette.utils.filesystem import read_yaml, write_to_yaml, cp, mkdir, rm
|
from moulinette.utils.filesystem import read_yaml, write_to_yaml, cp, mkdir, rm, chown
|
||||||
|
|
||||||
from yunohost.app import app_upgrade, app_list
|
from yunohost.app import app_upgrade, app_list
|
||||||
from yunohost.app_catalog import (
|
from yunohost.app_catalog import (
|
||||||
|
@ -965,22 +965,28 @@ class Migration:
|
||||||
try:
|
try:
|
||||||
run(self, backup_folder)
|
run(self, backup_folder)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(
|
if self.ldap_migration_started:
|
||||||
m18n.n("migration_ldap_migration_failed_trying_to_rollback")
|
logger.warning(
|
||||||
)
|
m18n.n("migration_ldap_migration_failed_trying_to_rollback")
|
||||||
os.system("systemctl stop slapd")
|
)
|
||||||
# To be sure that we don't keep some part of the old config
|
os.system("systemctl stop slapd")
|
||||||
rm("/etc/ldap/slapd.d", force=True, recursive=True)
|
# To be sure that we don't keep some part of the old config
|
||||||
cp(f"{backup_folder}/ldap_config", "/etc/ldap", recursive=True)
|
rm("/etc/ldap", force=True, recursive=True)
|
||||||
cp(f"{backup_folder}/ldap_db", "/var/lib/ldap", recursive=True)
|
cp(f"{backup_folder}/ldap_config", "/etc/ldap", recursive=True)
|
||||||
cp(
|
chown("/etc/ldap/schema/", "openldap", "openldap", recursive=True)
|
||||||
f"{backup_folder}/apps_settings",
|
chown("/etc/ldap/slapd.d/", "openldap", "openldap", recursive=True)
|
||||||
"/etc/yunohost/apps",
|
rm("/var/lib/ldap", force=True, recursive=True)
|
||||||
recursive=True,
|
cp(f"{backup_folder}/ldap_db", "/var/lib/ldap", recursive=True)
|
||||||
)
|
rm("/etc/yunohost/apps", force=True, recursive=True)
|
||||||
os.system("systemctl start slapd")
|
chown("/var/lib/ldap/", "openldap", recursive=True)
|
||||||
rm(backup_folder, force=True, recursive=True)
|
cp(
|
||||||
logger.info(m18n.n("migration_ldap_rollback_success"))
|
f"{backup_folder}/apps_settings",
|
||||||
|
"/etc/yunohost/apps",
|
||||||
|
recursive=True,
|
||||||
|
)
|
||||||
|
os.system("systemctl start slapd")
|
||||||
|
rm(backup_folder, force=True, recursive=True)
|
||||||
|
logger.info(m18n.n("migration_ldap_rollback_success"))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
rm(backup_folder, force=True, recursive=True)
|
rm(backup_folder, force=True, recursive=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue