Skip to content

Commit

Permalink
DAOS-16072 test: support systemctl --user for daos_agent
Browse files Browse the repository at this point in the history
Skip-test: true
Skip-build: true

Required-githooks: true

Signed-off-by: Dalton Bohning <dalton.bohning@intel.com>
  • Loading branch information
daltonbohning committed Jul 23, 2024
1 parent 1d415df commit 9561077
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 133 deletions.
5 changes: 4 additions & 1 deletion src/tests/ftest/network/cart_self_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
"""
import os

from apricot import TestWithServers
from command_utils import ExecutableCommand
from command_utils_base import EnvironmentVariables, FormattedParameter
Expand Down Expand Up @@ -70,7 +72,8 @@ def setUp(self):
self.server_managers[0].get_config_value("provider")
self.cart_env["D_INTERFACE"] = \
self.server_managers[0].get_config_value("fabric_iface")
self.cart_env["DAOS_AGENT_DRPC_DIR"] = "/var/run/daos_agent/"
self.cart_env["DAOS_AGENT_DRPC_DIR"] = os.environ.get(
"DAOS_AGENT_DRPC_DIR", "/var/run/daos_agent/")

self.server_managers[0].manager.assign_environment(self.cart_env, True)
self.server_managers[0].detect_start_via_dmg = True
Expand Down
25 changes: 11 additions & 14 deletions src/tests/ftest/util/agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import re
import socket
from getpass import getuser

from agent_utils_params import DaosAgentTransportCredentials, DaosAgentYamlParameters
from ClusterShell.NodeSet import NodeSet
Expand Down Expand Up @@ -193,11 +192,11 @@ def support_collect_log(self, **kwargs):
self.set_command(("support", "collect-log"), **kwargs)
return self._get_json_result()

def get_user_file(self):
"""Get the file defined in the yaml file that must be owned by the user.
def get_socket_dir(self):
"""Get the socket directory.
Returns:
str: file defined in the yaml file that must be owned by the user
str: the socket directory
"""
return self.get_config_value("runtime_dir")
Expand All @@ -207,7 +206,7 @@ class DaosAgentManager(SubprocessManager):
"""Manages the daos_agent execution on one or more hosts."""

def __init__(self, group, bin_dir, cert_dir, config_file, run_user, config_temp=None,
manager="Orterun", outputdir=None):
manager="Systemctl", outputdir=None):
"""Initialize a DaosAgentManager object.
Args:
Expand All @@ -221,9 +220,8 @@ def __init__(self, group, bin_dir, cert_dir, config_file, run_user, config_temp=
the hosts using the config_file specification. Defaults to None.
manager (str, optional): the name of the JobManager class used to
manage the YamlCommand defined through the "job" attribute.
Defaults to "Orterun".
outputdir (str, optional): path to avocado test outputdir. Defaults
to None.
Defaults to "Systemctl".
outputdir (str, optional): path to avocado test outputdir. Defaults to None.
"""
agent_command = get_agent_command(
group, cert_dir, bin_dir, config_file, run_user, config_temp)
Expand Down Expand Up @@ -272,11 +270,10 @@ def start(self):
self._hosts, self.manager.command)

# Copy certificates
self.manager.job.copy_certificates(
get_log_file("daosCA/certs"), self._hosts)
self.manager.job.copy_certificates(get_log_file("daosCA/certs"), self._hosts)

# Verify the socket directory exists when using a non-systemctl manager
self.verify_socket_directory(getuser())
self.verify_socket_directory(self.manager.job.certificate_owner)

super().start()

Expand Down Expand Up @@ -368,11 +365,11 @@ def stop(self):
raise CommandFailure(
"Failed to stop agents:\n {}".format("\n ".join(messages)))

def get_user_file(self):
"""Get the file defined in the yaml file that must be owned by the user.
def get_socket_dir(self):
"""Get the socket directory.
Returns:
str: file defined in the yaml file that must be owned by the user
str: the socket directory
"""
return self.get_config_value("runtime_dir")
63 changes: 35 additions & 28 deletions src/tests/ftest/util/apricot/apricot/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import sys
from ast import literal_eval
from getpass import getuser
from time import time

from agent_utils import DaosAgentManager, include_local_host
Expand Down Expand Up @@ -70,8 +71,6 @@ def __init__(self, *args, **kwargs):
# Define a test unique temporary directory
self.test_env = TestEnvironment()
self.test_dir = os.path.join(self.test_env.log_dir, self.test_id)

# Create a test unique temporary directory on this host
os.makedirs(self.test_dir, exist_ok=True)

# Support unique test case timeout values. These test case specific
Expand Down Expand Up @@ -521,13 +520,7 @@ def setUp(self):
super().setUp()
self.bin = os.path.join(self.prefix, 'bin')
self.daos_test = os.path.join(self.prefix, 'bin', 'daos_test')

# set default shared dir for daos tests in case DAOS_TEST_SHARED_DIR
# is not set, for RPM env and non-RPM env.
if os.path.normpath(self.prefix) != os.path.join(os.sep, 'usr'):
self.tmp = os.path.join(self.prefix, 'tmp')
else:
self.tmp = os.getenv('DAOS_TEST_SHARED_DIR', os.path.expanduser('~/daos_test'))
self.tmp = self.test_env.shared_dir
os.makedirs(self.tmp, exist_ok=True)
self.log.debug("Shared test directory: %s", self.tmp)
self.log.debug("Common test directory: %s", self.test_dir)
Expand Down Expand Up @@ -741,7 +734,7 @@ def setUp(self):

# Toggle whether to dump server ULT stacks on failure
self.__dump_engine_ult_on_failure = self.params.get(
"dump_engine_ult_on_failure", "/run/setup/*", True)
"dump_engine_ult_on_failure", "/run/setup/*", self.__dump_engine_ult_on_failure)

# # Find a configuration that meets the test requirements
# self.config = Configuration(
Expand Down Expand Up @@ -1064,12 +1057,16 @@ def add_agent_manager(self, group=None, config_file=None, config_temp=None):
"""
if group is None:
group = self.server_group
if config_file is None and self.agent_manager_class == "Systemctl":
config_file = get_default_config_file("agent")
config_temp = self.get_config_file(group, "agent", self.test_dir)
elif config_file is None:
config_file = self.get_config_file(group, "agent")
config_temp = None

if config_file is None:
if self.agent_manager_class == "Systemctl" and self.test_env.agent_user != getuser():
# Default directory requiring privileged access
config_file = get_default_config_file("agent")
config_temp = self.get_config_file(group, "agent", self.test_dir)
else:
# Test-specific directory not requiring privileged access
config_file = os.path.join(self.test_dir, "daos_agent.yml")
config_temp = self.get_config_file(group, "agent", self.test_dir)

# Verify the correct configuration files have been provided
if self.agent_manager_class == "Systemctl" and config_temp is None:
Expand All @@ -1078,10 +1075,12 @@ def add_agent_manager(self, group=None, config_file=None, config_temp=None):
"file provided for the Systemctl manager class!")

# Define the location of the certificates
if self.agent_manager_class == "Systemctl":
if self.agent_manager_class == "Systemctl" and self.test_env.agent_user != getuser():
# Default directory requiring privileged access
cert_dir = os.path.join(os.sep, "etc", "daos", "certs")
else:
cert_dir = self.workdir
# Test-specific directory not requiring privileged access
cert_dir = os.path.join(self.test_dir, "certs")

self.agent_managers.append(
DaosAgentManager(
Expand Down Expand Up @@ -1114,33 +1113,41 @@ def add_server_manager(self, group=None, svr_config_file=None,
"""
if group is None:
group = self.server_group

# Set default server config files
if svr_config_file is None and self.server_manager_class == "Systemctl":
svr_config_file = get_default_config_file("server")
svr_config_temp = self.get_config_file(
group, "server", self.test_dir)
elif svr_config_file is None:
svr_config_file = self.get_config_file(group, "server")
svr_config_temp = None
if dmg_config_file is None and self.server_manager_class == "Systemctl":
dmg_config_file = get_default_config_file("control")
dmg_config_temp = self.get_config_file(group, "dmg", self.test_dir)
elif dmg_config_file is None:
dmg_config_file = self.get_config_file(group, "dmg")
dmg_config_temp = None

# Verify the correct configuration files have been provided
if self.server_manager_class == "Systemctl" and svr_config_temp is None:
self.fail(
"Error adding a DaosServerManager: no temporary configuration "
"file provided for the Systemctl manager class!")

# Define the location of the certificates
# Set default dmg config files
if dmg_config_file is None:
if self.server_manager_class == "Systemctl" and self.test_env.agent_user != getuser():
dmg_config_file = get_default_config_file("control")
dmg_config_temp = self.get_config_file(group, "dmg", self.test_dir)
else:
dmg_config_file = os.path.join(self.test_dir, "daos_control.yml")

# Define server certificate directory
if self.server_manager_class == "Systemctl":
svr_cert_dir = os.path.join(os.sep, "etc", "daos", "certs")
dmg_cert_dir = os.path.join(os.sep, "etc", "daos", "certs")
else:
svr_cert_dir = self.workdir
dmg_cert_dir = self.workdir

# Define dmg certificate directory
if self.server_manager_class == "Systemctl" and self.test_env.agent_user != getuser():
dmg_cert_dir = os.path.join(os.sep, "etc", "daos", "certs")
else:
dmg_cert_dir = os.path.join(self.test_dir, "certs")

self.server_managers.append(
DaosServerManager(
Expand Down Expand Up @@ -1681,7 +1688,7 @@ def get_dmg_command(self, index=0):

dmg_cmd = get_dmg_command(
self.server_group, dmg_cert_dir, self.bin, dmg_config_file,
dmg_config_temp, self.access_points_suffix)
dmg_config_temp, self.access_points_suffix, getuser())
dmg_cmd.hostlist = self.access_points
return dmg_cmd

Expand Down
Loading

0 comments on commit 9561077

Please sign in to comment.