From 26e3b118001a1c6d42c0aa14df92e6811b776e26 Mon Sep 17 00:00:00 2001 From: sdu-xinglindu <1783674677@qq.com> Date: Sun, 28 May 2023 14:09:18 +0800 Subject: [PATCH] dhcp --- dhcp/testcase/dhcp.sh | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 dhcp/testcase/dhcp.sh diff --git a/dhcp/testcase/dhcp.sh b/dhcp/testcase/dhcp.sh new file mode 100755 index 0000000..b90170e --- /dev/null +++ b/dhcp/testcase/dhcp.sh @@ -0,0 +1,70 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20230528-140306-254085788 +# @用例名称: dhcp +# @用例级别: 3 +# @用例标签: +# @用例类型: 功能 +############################################################################### +[ -z "$TST_TS_TOPDIR" ] && { + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + export TST_TS_TOPDIR +} +source "${TST_TS_TOPDIR}/tst_common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 系统正常运行,且已安装 `dhcp` 包 + assert_true yum install -y dhcp + + return 0 +} + + +do_test() { + msg "this is do_test" + + # @测试步骤:1 创建 DHCP 配置文件 + # @预期结果:1 确保成功创建 DHCP 配置文件 + assert_true echo "subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.10 192.168.0.20; }" > /etc/dhcp/dhcpd.conf + + # @测试步骤:2 启动 DHCP 服务 + # @预期结果:2 确保 DHCP 服务能够成功启动 + assert_true systemctl start dhcpd + + # @测试步骤:3 检查 DHCP 服务状态 + # @预期结果:3 确保 DHCP 服务处于运行状态 + assert_true systemctl is-active dhcpd + + # @测试步骤:4 分配 IP 地址 + # @预期结果:4 确保成功为客户端分配 IP 地址 + assert_true dhclient -v + + # @测试步骤:5 验证网络连接 + # @预期结果:5 确保客户端能够通过 DHCP 获得有效的 IP 地址,并与网络正常通信 + assert_true ping -c 3 192.168.0.1 + + return 0 +} + + + +tc_teardown() { + msg "this is tc_teardown" + + # @清理操作: 停止 DHCP 服务 + assert_true systemctl stop dhcpd + # @删除创建配置文件 + rm /etc/dhcp/dhcpd.conf + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### -- Gitee