diff --git a/docs/system_base/radvd/tc_radvd_fun001.yaml b/docs/system_base/radvd/tc_radvd_fun001.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0b41e74cdea86f61e95278296d1d3d1fa175a67d --- /dev/null +++ b/docs/system_base/radvd/tc_radvd_fun001.yaml @@ -0,0 +1,52 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local,radvd +用例描述: radvd路由器通告守护进程基本功能测试 +修改人: douzhichong + +前置条件: +- 系统已安装radvd软件包 + +测试步骤: +- 备份原始radvd配置文件 +- 获取本地UP状态网络接口的IPv4地址 +- 根据获取的IPv4地址确定对应的网络接口名称 +- 配置radvd.conf文件,添加IPv6前缀通告配置 +- 启用IPv6转发功能 +- 记录当前时间用于日志分析 +- 测试radvd服务的重启功能 +- 测试radvd服务的停止功能 +- 测试radvd服务的启动功能 +- 测试radvd服务的启用/禁用功能(根据当前状态自动适配) +- 检查radvd服务日志中是否有错误信息 +- 修改radvd服务的执行参数(添加-m选项) +- 重新加载systemd守护进程配置 +- 测试radvd服务的重新加载功能 +- 验证服务重新加载后仍保持活动状态 +- 清理测试环境,恢复原始配置 + +期望结果: +- 能够成功备份/etc/radvd.conf原始配置文件 +- 能够正确获取UP状态网络接口的IPv4地址 +- 能够根据IPv4地址确定正确的网络接口名称 +- radvd.conf配置文件能够正确生成并包含IPv6前缀配置 +- IPv6转发功能能够成功启用(/proc/sys/net/ipv6/conf/all/forwarding值为1) +- radvd服务能够成功重启并显示"Active: active"状态 +- radvd服务能够成功停止并显示"Active: inactive"状态 +- radvd服务能够成功启动并显示"Active: active"状态 +- 根据服务当前状态,能够正确执行启用或禁用操作: + - 如果服务为enabled状态,能够成功禁用并删除符号链接 + - 如果服务为disabled状态,能够成功启用并创建符号链接 + - 如果服务为masked或static状态,能够正确识别并跳过相应测试 +- radvd服务日志中无fail或error级别错误信息(DEBUG/INFO/WARNING级别除外) +- radvd服务配置能够成功修改(添加-m参数) +- systemd守护进程能够成功重新加载配置 +- radvd服务能够成功重新加载而不中断服务 +- 服务重新加载后仍保持"Active: active"状态 +- 测试完成后能够正确恢复原始配置文件 +- IPv6转发功能能够正确恢复为禁用状态(/proc/sys/net/ipv6/conf/all/forwarding值为0) +- 所有测试步骤均通过,返回码为0或符合预期 +- 测试环境能够完整清理,无残留配置影响系统 diff --git a/tests/system_base/radvd/tc_radvd_fun001.py b/tests/system_base/radvd/tc_radvd_fun001.py new file mode 100644 index 0000000000000000000000000000000000000000..1f0dcf9c1119a4b7be50e6327a8a83051beb9dc2 --- /dev/null +++ b/tests/system_base/radvd/tc_radvd_fun001.py @@ -0,0 +1,113 @@ +""" +@File: tc_radvd_fun001.py +@Time: 2025/12/15 15:30:20 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" +import subprocess + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_radvd_fun001.yaml for details + + :avocado: tags=P1,noarch,local,radvd + """ + PARAM_DIC = {"pkg_name": "radvd"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + code, ipv4 = self.cmd("ip -4 addr show | grep -A2 \"state UP\" | grep -oP 'inet \K[\d.]+'") + code, eth_name = self.cmd(f"ip a | grep {ipv4} | awk '{{print $NF}}'") + self.cmd(' cp /etc/radvd.conf /etc/radvd.bak') + command =f'''echo "interface {eth_name} +{{ + AdvSendAdvert on; + MinRtrAdvInterval 3; + MaxRtrAdvInterval 10; + prefix 2001:db8:0:f101::1/64 + {{ + AdvOnLink on; + AdvAutonomous on; + AdvRouterAddr on; + }}; + +}};" >>/etc/radvd.conf''' + self.cmd(command) + self.cmd('echo 1 >/proc/sys/net/ipv6/conf/all/forwarding') + def test(self): + service = 'radvd.service' + # 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}') + self.cmd(f"sed -i 's\ExecStart=/usr/sbin/radvd\ExecStart=/usr/sbin/radvd -m\g' /usr/lib/systemd/system/{service}") + self.cmd('systemctl daemon-reload') + code,result=self.cmd(f'systemctl reload {service}') + self.assertFalse(code, f'{service} reload failed') + code2, result = self.cmd(f'systemctl status {service} | grep "Active: active"') + self.assertFalse(code2, f'{service} reload causes the service status to change') + + + def tearDown(self): + self.cmd("sed -i 's\ExecStart=/usr/sbin/radvd -m\ExecStart=/usr/sbin/radvd\g' /usr/lib/systemd/system/radvd.service") + self.cmd('systemctl daemon-reload') + self.cmd(' systemctl reload radvd.service') + self.cmd('systemctl stop radvd.service') + self.cmd('mv -f /etc/radvd.bak /etc/radvd.conf') + self.cmd('echo 0 >/proc/sys/net/ipv6/conf/all/forwarding') + super().tearDown(self.PARAM_DIC)