From 5ff231cea19524069d8f2853ce125fd40ad4831a Mon Sep 17 00:00:00 2001 From: root Date: Fri, 6 Feb 2026 17:21:01 +0800 Subject: [PATCH] add authd test case --- .../authd/tc_service_authd_fun001.yaml | 34 +++++++ .../authd/tc_service_authd_fun001.py | 99 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 docs/system_base/authd/tc_service_authd_fun001.yaml create mode 100644 tests/system_base/authd/tc_service_authd_fun001.py diff --git a/docs/system_base/authd/tc_service_authd_fun001.yaml b/docs/system_base/authd/tc_service_authd_fun001.yaml new file mode 100644 index 00000000..b37a52db --- /dev/null +++ b/docs/system_base/authd/tc_service_authd_fun001.yaml @@ -0,0 +1,34 @@ +作者: douzhihcong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local,authd +用例描述: 测试 authd相关功能 +修改人: douzhihcong + +前置条件: +- 系统已安装 authd、net-tools、nmap-ncat 软件包 + +测试步骤: +- 记录当前时间用于日志检查 +- 重启 auth.socket 服务并验证状态 +- 停止 auth.socket 服务并验证状态 +- 启动 auth.socket 服务并验证状态 +- 检查服务启用状态,测试 enable/disable 功能(根据当前状态执行相应操作) +- 检查指定时间后的服务日志中是否有错误信息(排除 DEBUG/INFO/WARNING 级别) +- 测试服务的 reload 功能是否适用 +- 验证 auth 服务是否在默认端口 113 上监听 +- 检查 authd 相关进程是否在运行 +- 验证 auth.socket 的配置信息 +- 检查 auth.socket 的加载状态 + +期望结果: +- 服务能够成功重启、停止和启动,状态显示正确 +- 服务的 enable/disable 功能正常工作 +- 服务日志中无错误信息(排除 DEBUG/INFO/WARNING 级别) +- reload 操作不被支持时应有相应提示 +- auth 服务在端口 113 正常监听 +- authd 进程正在运行 +- auth.socket 配置正确 +- 服务加载状态为 "loaded" diff --git a/tests/system_base/authd/tc_service_authd_fun001.py b/tests/system_base/authd/tc_service_authd_fun001.py new file mode 100644 index 00000000..544965a7 --- /dev/null +++ b/tests/system_base/authd/tc_service_authd_fun001.py @@ -0,0 +1,99 @@ +""" +@File: tc_service_authd_fun001.py +@Time: 2026/2/6 15:30:20 +@Author: douzhihcong +@Version: 1.0 +@Contact: douzhihcong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhihcong +""" +import subprocess + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_service_authd_fun001.yaml for details + + :avocado: tags=P1,noarch,local,authd + """ + PARAM_DIC = {"pkg_name": "authd net-tools nmap-ncat"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + service = 'auth.socket' + # test_execution + code, log_time = self.cmd("date '+%Y-%m-%d %T'") + # test_restart + code, result = self.cmd(f"systemctl restart {service}") + self.assertFalse(code, f"{service} restart failed") + self.cmd('sleep 5') + code, result = self.cmd(f"systemctl status {service}| grep 'Active: active'") + self.assertFalse(code, f"{service} restart failed") + code, result = self.cmd(f"systemctl stop {service}") + self.assertFalse(code, f"{service} stop failed") + self.cmd('sleep 5') + code, result = self.cmd(f"systemctl status {service}| grep 'Active: inactive'") + self.assertFalse(code, f"{service} stop failed") + code, result = self.cmd(f"systemctl start {service}") + self.assertFalse(code, f"{service} start failed") + self.cmd('sleep 5') + code, result = self.cmd(f"systemctl status {service}| grep 'Active: active'") + self.assertFalse(code, f"{service} start failed") + # test_enabled + command = f'systemctl is-enabled {service}' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + status1 = result.stdout.decode('utf-8').strip() + if status1 == "enabled": + code, symlink_file = self.cmd( + f'systemctl disable {service} 2>&1 | grep "Removed" | awk \'{{print $2}}\' | awk \'{{print substr($0,1,length($0)-1)}}\' | tr -d \'\"\'') + command = f'find {symlink_file}' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"{service} disable failed") + self.cmd(f'systemctl enable {service}') + code, result = self.cmd(f'find {symlink_file}') + self.assertFalse(code, f"{service} enable failed") + elif status1 == "disabled": + code, symlink_file = self.cmd( + f'systemctl enable "{service}" 2>&1 | grep "Created symlink" | awk \'{{print $3}}\' | tr -d \'\"\'') + code, result = self.cmd(f'find {symlink_file}') + self.assertFalse(code, f"{service} enable failed") + self.cmd(f'systemctl disable {service}') + command = f'find {symlink_file}' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"{service} disable failed") + elif status1 == "masked": + self.log.info("Unit is masked, ignoring.") + elif status1 == "static": + self.log.info( + "The unit files have no installation config,This means they are not meant to be enabled using systemctl.") + else: + self.log.info("Unit is indirect, ignoring.") + # execution + command = f' journalctl --since {log_time} -u {service} | grep -i "fail\|error" | grep -v -i "DEBUG\|INFO\|WARNING"' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"There is an error message for the log of {service}") + # test_reload + self.cmd(f'systemctl start {service}') + code, result = self.cmd(f'systemctl reload {service} 2>&1 | grep "Job type reload is not applicable"') + self.assertFalse(code, f"Job type reload is not applicable for unit {service}") + code, result = self.cmd(f'systemctl status {service} | grep "Active: active"') + self.assertFalse(code, f"{service} reload faild") + code, result = self.cmd('ss -tunlp | grep ":113"') + self.assertFalse(code, "Auth service is not listening on default port 113") + + code, result = self.cmd('pgrep -f "authd"') + self.assertFalse(code, "Auth service process is not running") + + code, result = self.cmd('systemctl show auth.socket | grep -E "Listen|Socke"') + self.assertFalse(code, "Auth socket configuration error") + + code, result = self.cmd('systemctl show auth.socket --property=LoadState | grep "loaded"') + self.assertFalse(code, "Auth socket load state error") + + def tearDown(self): + super().tearDown(self.PARAM_DIC) + -- Gitee