Reuse the installer worker group when creating its service user
This commit is contained in:
1 parent
10e8a9d90d
commit
469c1817ff
2 files changed
+49
-3
No files matched your search
@@ -148,10 +148,12 @@ def identity(name, home="/nonexistent"):
|
|||||||
try:
|
try:
|
||||||
account = pwd.getpwnam(name)
|
account = pwd.getpwnam(name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
private_group = group(name)
|
||||||
run(
|
run(
|
||||||
"useradd",
|
"useradd",
|
||||||
"--system",
|
"--system",
|
||||||
"--user-group",
|
"--gid",
|
||||||
|
str(private_group.gr_gid),
|
||||||
"--no-create-home",
|
"--no-create-home",
|
||||||
"--home-dir",
|
"--home-dir",
|
||||||
home,
|
home,
|
||||||
@@ -184,8 +186,9 @@ def install_unit(unit):
|
|||||||
|
|
||||||
|
|
||||||
def install_worker(group_name, user, socket_unit, worker_unit):
|
def install_worker(group_name, user, socket_unit, worker_unit):
|
||||||
group(group_name)
|
|
||||||
identity(user)
|
identity(user)
|
||||||
|
if group_name != user:
|
||||||
|
group(group_name)
|
||||||
for unit in (
|
for unit in (
|
||||||
f"{socket_unit}.socket",
|
f"{socket_unit}.socket",
|
||||||
f"{socket_unit}@.service",
|
f"{socket_unit}@.service",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from deploy.panel_installer.config import (
|
|||||||
read_password,
|
read_password,
|
||||||
read_plan,
|
read_plan,
|
||||||
)
|
)
|
||||||
from deploy.panel_installer.engine import Installer
|
from deploy.panel_installer.engine import Installer, install_worker
|
||||||
from deploy.panel_installer.web import Wizard, WizardHandler, form_plan
|
from deploy.panel_installer.web import Wizard, WizardHandler, form_plan
|
||||||
|
|
||||||
PROXY = {
|
PROXY = {
|
||||||
@@ -27,6 +27,49 @@ ADMIN = {"username": "operator", "email": "ops@example.net"}
|
|||||||
|
|
||||||
|
|
||||||
class InstallerParametersTests(unittest.TestCase):
|
class InstallerParametersTests(unittest.TestCase):
|
||||||
|
def test_worker_can_join_its_existing_private_group(self):
|
||||||
|
name = "coulobre-operator"
|
||||||
|
service = f"{name}-worker.service"
|
||||||
|
account = SimpleNamespace(
|
||||||
|
pw_gid=983,
|
||||||
|
pw_uid=984,
|
||||||
|
pw_dir="/nonexistent",
|
||||||
|
pw_shell="/usr/sbin/nologin",
|
||||||
|
)
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"deploy.panel_installer.engine.pwd.getpwnam",
|
||||||
|
side_effect=[KeyError, account],
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"deploy.panel_installer.engine.grp.getgrnam",
|
||||||
|
return_value=SimpleNamespace(gr_gid=983),
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"deploy.panel_installer.engine.os.getgrouplist",
|
||||||
|
return_value=[983],
|
||||||
|
),
|
||||||
|
patch("deploy.panel_installer.engine.run") as run,
|
||||||
|
patch("deploy.panel_installer.engine.install_unit"),
|
||||||
|
):
|
||||||
|
self.assertEqual(
|
||||||
|
install_worker(name, name, f"{name}-apply", service),
|
||||||
|
service,
|
||||||
|
)
|
||||||
|
run.assert_called_once_with(
|
||||||
|
"useradd",
|
||||||
|
"--system",
|
||||||
|
"--gid",
|
||||||
|
"983",
|
||||||
|
"--no-create-home",
|
||||||
|
"--home-dir",
|
||||||
|
"/nonexistent",
|
||||||
|
"--shell",
|
||||||
|
"/usr/sbin/nologin",
|
||||||
|
name,
|
||||||
|
label=f"Create service user {name}",
|
||||||
|
)
|
||||||
|
|
||||||
def test_default_health_targets_follow_locally_installed_roles(self):
|
def test_default_health_targets_follow_locally_installed_roles(self):
|
||||||
cases = (
|
cases = (
|
||||||
({}, None, []),
|
({}, None, []),
|
||||||
|
|||||||
Reference in new issue
Block a user