update testcase for testsuite uwsgi-plugin-lua

This commit is contained in:
2026-04-25 05:12:48 +08:00
parent 4e53ae20b3
commit 668d722d1d
10 changed files with 0 additions and 840 deletions

View File

@@ -1,42 +0,0 @@
{
"path": "$OET_PATH/testcases/function_test/pkg_test/uwsgi/uwsgi-plugin-lua",
"machine num": 1,
"cases": [
{
"name": "test_uwsgi-plugin-lua_function_init",
"desc": "Test initialization of uwsgi-plugin-lua"
},
{
"name": "test_uwsgi-plugin-lua_function_exec",
"desc": "Test Lua script execution"
},
{
"name": "test_uwsgi-plugin-lua_function_mem",
"desc": "Test memory management"
},
{
"name": "test_uwsgi-plugin-lua_function_err",
"desc": "Test error handling"
},
{
"name": "test_uwsgi-plugin-lua_function_install",
"desc": "Test installation of uwsgi-plugin-lua package"
},
{
"name": "test_uwsgi-plugin-lua_function_remove",
"desc": "Test removal of uwsgi-plugin-lua package"
},
{
"name": "test_uwsgi-plugin-lua_function_verify",
"desc": "Test verification of plugin installation in uWSGI"
},
{
"name": "test_uwsgi-plugin-lua_function_basic",
"desc": "Test basic uWSGI+Lua application serving"
},
{
"name": "test_uwsgi-plugin-lua_function_config",
"desc": "Test loading Lua configuration file in uWSGI"
}
]
}

View File

@@ -1,114 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2026-02-24
# @License : Mulan PSL v2
# @Desc : Test basic uWSGI+Lua application serving
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
# 判断环境是否已安装uwsgi-plugin-lua
LOG_INFO "检查uwsgi-plugin-lua是否已安装"
rpm -q uwsgi-plugin-lua &>/dev/null
if [ $? -eq 0 ]; then
LOG_INFO "uwsgi-plugin-lua已安装标记为保持安装状态"
INSTALLED_BEFORE_TEST=1
else
LOG_INFO "uwsgi-plugin-lua未安装将在测试中安装"
INSTALLED_BEFORE_TEST=0
fi
# 检查yum源中是否有uwsgi-plugin-lua软件包
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua软件包"
dnf list available uwsgi-plugin-lua &>/dev/null
if [ $? -ne 0 ]; then
LOG_ERROR "yum源中未找到uwsgi-plugin-lua软件包"
exit 255
fi
# 如果之前未安装则安装uwsgi-plugin-lua
if [ $INSTALLED_BEFORE_TEST -eq 0 ]; then
LOG_INFO "安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
fi
# 验证uwsgi是否支持lua插件
LOG_INFO "验证uwsgi是否支持lua插件"
uwsgi --plugins-list 2>/dev/null | grep -q lua
CHECK_RESULT $? 0 0 "uwsgi未找到lua插件支持"
# 创建测试用的lua应用文件
LOG_INFO "创建测试lua应用文件"
cat > /tmp/test_uwsgi_lua_app.lua << "EOF"
function hello(wsgi_env)
local headers = { ["Content-Type"] = "text/plain" }
local body = { "Hello from Lua uWSGI!\n" }
return 200, headers, body
end
EOF
CHECK_RESULT $? 0 0 "创建lua应用文件失败"
# 创建uwsgi配置文件
LOG_INFO "创建uwsgi配置文件"
cat > /tmp/test_uwsgi_lua_config.ini << EOF
[uwsgi]
http = :9090
plugin = lua
lua-load = /tmp/test_uwsgi_lua_app.lua
lua-call = hello
master = true
processes = 1
threads = 1
EOF
CHECK_RESULT $? 0 0 "创建uwsgi配置文件失败"
# 启动uwsgi服务
LOG_INFO "启动uwsgi服务"
uwsgi --ini /tmp/test_uwsgi_lua_config.ini --daemonize /tmp/uwsgi_lua_test.log
CHECK_RESULT $? 0 0 "启动uwsgi服务失败"
# 等待服务启动
sleep 2
# 测试uwsgi服务是否正常响应
LOG_INFO "测试uwsgi服务响应"
curl -s http://localhost:9090 | grep -q "Hello from Lua uWSGI!"
CHECK_RESULT $? 0 0 "uwsgi服务响应不符合预期"
# 停止uwsgi服务
LOG_INFO "停止uwsgi服务"
pkill -f "uwsgi.*test_uwsgi_lua_config.ini"
sleep 1
# 清理测试文件
LOG_INFO "清理测试文件"
rm -f /tmp/test_uwsgi_lua_app.lua /tmp/test_uwsgi_lua_config.ini /tmp/uwsgi_lua_test.log
CHECK_RESULT $? 0 0 "清理测试文件失败"
# 如果测试前未安装,则卸载软件包
if [ $INSTALLED_BEFORE_TEST -eq 0 ]; then
LOG_INFO "卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
else
LOG_INFO "保持uwsgi-plugin-lua安装状态"
fi
LOG_INFO "测试完成Test basic uWSGI+Lua application serving"
}
main "$@"

View File

@@ -1,97 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2026-02-24
# @License : Mulan PSL v2
# @Desc : Test loading Lua configuration file in uWSGI
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
LOG_INFO "开始测试Test loading Lua configuration file in uWSGI"
# 定义软件包名称
PACKAGE_NAME="uwsgi-plugin-lua"
# 检查软件包是否已在yum源中
LOG_INFO "检查yum源中是否存在软件包$PACKAGE_NAME"
if ! dnf list available "$PACKAGE_NAME" &>/dev/null; then
LOG_ERROR "yum源中未找到软件包$PACKAGE_NAME"
exit 255
fi
# 检查当前环境是否已安装软件包
LOG_INFO "检查当前环境是否已安装软件包:$PACKAGE_NAME"
if rpm -q "$PACKAGE_NAME" &>/dev/null; then
LOG_INFO "软件包 $PACKAGE_NAME 已安装,将保持安装状态"
INSTALLED_BEFORE=true
else
LOG_INFO "软件包 $PACKAGE_NAME 未安装,将在测试过程中安装"
INSTALLED_BEFORE=false
fi
# 如果未安装,则安装软件包
if [ "$INSTALLED_BEFORE" = false ]; then
LOG_INFO "安装软件包:$PACKAGE_NAME"
dnf install -y "$PACKAGE_NAME"
CHECK_RESULT $? 0 0 "安装软件包 $PACKAGE_NAME 失败"
fi
# 测试加载Lua配置文件
LOG_INFO "测试加载Lua配置文件"
uwsgi --plugin lua --lua-config test_config.lua --help &>/dev/null
CHECK_RESULT $? 0 0 "加载Lua配置文件失败"
# 检查uWSGI是否支持Lua插件
LOG_INFO "检查uWSGI是否支持Lua插件"
if ! uwsgi --plugins-list 2>/dev/null | grep -q lua; then
LOG_ERROR "uWSGI不支持Lua插件"
exit 255
fi
# 创建测试Lua配置文件
LOG_INFO "创建测试Lua配置文件"
cat > test_config.lua << "EOF"
config = {
workers = 2,
master = true,
socket = ":9090",
module = "wsgi:app"
}
for key, value in pairs(config) do
print(key .. " = " .. tostring(value))
end
EOF
# 使用uWSGI加载Lua配置文件
LOG_INFO "使用uWSGI加载Lua配置文件"
uwsgi --plugin lua --lua-config test_config.lua --dry-run 2>&1 | grep -q "workers = 2"
CHECK_RESULT $? 0 0 "uWSGI加载Lua配置文件未按预期工作"
# 清理测试文件
LOG_INFO "清理测试文件"
rm -f test_config.lua
# 如果测试前未安装软件包,则在测试结束后卸载
if [ "$INSTALLED_BEFORE" = false ]; then
LOG_INFO "卸载软件包:$PACKAGE_NAME"
dnf remove -y "$PACKAGE_NAME"
CHECK_RESULT $? 0 0 "卸载软件包 $PACKAGE_NAME 失败"
fi
LOG_INFO "测试完成Test loading Lua configuration file in uWSGI"
}
main "$@"

View File

@@ -1,71 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2025-12-10
# @License : Mulan PSL v2
# @Desc : Test error handling
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
# 检查uwsgi-plugin-lua是否已安装
LOG_INFO "检查uwsgi-plugin-lua是否已安装"
rpm -q uwsgi-plugin-lua > /dev/null 2>&1
if [ $? -eq 0 ]; then
LOG_INFO "uwsgi-plugin-lua已安装脚本结束后将保持安装状态"
INSTALLED=1
else
LOG_INFO "uwsgi-plugin-lua未安装将在测试结束后卸载"
INSTALLED=0
fi
# 检查yum源中是否存在uwsgi-plugin-lua软件包
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua软件包"
dnf list available uwsgi-plugin-lua > /dev/null 2>&1
if [ $? -ne 0 ]; then
LOG_ERROR "yum源中不存在uwsgi-plugin-lua软件包"
exit 255
fi
# 安装uwsgi-plugin-lua软件包
LOG_INFO "安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
# 测试错误处理功能
LOG_INFO "测试错误处理功能"
uwsgi --plugin lua --lua-error-test > /dev/null 2>&1
if [ $? -eq 255 ]; then
LOG_INFO "错误处理功能测试通过"
else
LOG_ERROR "错误处理功能测试失败"
exit 255
fi
# 清理环境
if [ $INSTALLED -eq 0 ]; then
LOG_INFO "卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua > /dev/null 2>&1
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
else
LOG_INFO "保持uwsgi-plugin-lua安装状态"
fi
LOG_INFO "测试脚本执行完毕"
exit 0
}
main "$@"

View File

@@ -1,69 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2025-12-10
# @License : Mulan PSL v2
# @Desc : Test Lua script execution
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
# 检查yum源中是否存在uwsgi-plugin-lua软件包
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua软件包"
dnf list available uwsgi-plugin-lua &> /dev/null
if [ $? -ne 0 ]; then
LOG_ERROR "yum源中不存在uwsgi-plugin-lua软件包"
exit 255
fi
# 检查是否已安装uwsgi-plugin-lua
LOG_INFO "检查是否已安装uwsgi-plugin-lua"
rpm -q uwsgi-plugin-lua &> /dev/null
installed=$?
# 如果未安装,则安装软件包
if [ $installed -ne 0 ]; then
LOG_INFO "安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
fi
# 测试Lua脚本执行功能
LOG_INFO "测试Lua脚本执行功能"
cat << EOF > test.lua
function hello()
return "Hello, Lua!"
end
EOF
uwsgi --plugin lua --lua test.lua --lua-call hello &> /dev/null
CHECK_RESULT $? 0 0 "Lua脚本执行失败"
# 清理测试文件
rm -f test.lua
# 如果之前未安装,则卸载软件包
if [ $installed -ne 0 ]; then
LOG_INFO "卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
fi
LOG_INFO "测试完成,环境已恢复"
}
main "$@"

View File

@@ -1,62 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2025-12-10
# @License : Mulan PSL v2
# @Desc : Test initialization of uwsgi-plugin-lua
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
# 检查环境是否已安装uwsgi-plugin-lua
LOG_INFO "检查环境是否已安装uwsgi-plugin-lua"
if dnf list installed uwsgi-plugin-lua &>/dev/null; then
LOG_INFO "uwsgi-plugin-lua已安装脚本结束时将保持安装状态"
INSTALLED=true
else
LOG_INFO "uwsgi-plugin-lua未安装将在测试结束后卸载"
INSTALLED=false
fi
# 检查yum源中是否存在uwsgi-plugin-lua
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua"
if ! dnf list available uwsgi-plugin-lua &>/dev/null; then
LOG_ERROR "yum源中未找到uwsgi-plugin-lua软件包"
exit 255
fi
# 安装uwsgi-plugin-lua如果未安装
if [ "$INSTALLED" = false ]; then
LOG_INFO "正在安装uwsgi-plugin-lua"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
fi
# 测试初始化功能
LOG_INFO "测试uwsgi-plugin-lua的初始化功能"
uwsgi --plugin lua --lua-init test_init.lua
CHECK_RESULT $? 0 0 "uwsgi-plugin-lua初始化失败"
# 清理环境(如果最初未安装)
if [ "$INSTALLED" = false ]; then
LOG_INFO "正在卸载uwsgi-plugin-lua"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
fi
LOG_INFO "测试完成,环境已恢复"
}
main "$@"

View File

@@ -1,76 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2026-02-24
# @License : Mulan PSL v2
# @Desc : Test installation of uwsgi-plugin-lua package
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
LOG_INFO "开始测试安装uwsgi-plugin-lua软件包"
LOG_INFO "步骤1检查yum源中是否存在uwsgi-plugin-lua软件包"
dnf list available uwsgi-plugin-lua > /dev/null 2>&1
if [ $? -ne 0 ]; then
LOG_ERROR "yum源中不存在uwsgi-plugin-lua软件包"
exit 255
fi
LOG_INFO "步骤2检查系统是否已安装uwsgi-plugin-lua软件包"
rpm -q uwsgi-plugin-lua > /dev/null 2>&1
if [ $? -eq 0 ]; then
LOG_INFO "系统已安装uwsgi-plugin-lua软件包测试完成后将保持安装状态"
INSTALLED=true
else
LOG_INFO "系统未安装uwsgi-plugin-lua软件包将进行安装测试"
INSTALLED=false
fi
if [ "$INSTALLED" = false ]; then
LOG_INFO "步骤3安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua软件包失败"
fi
LOG_INFO "步骤4验证uwsgi-plugin-lua插件功能"
uwsgi --help | grep -q lua
CHECK_RESULT $? 0 0 "uwsgi不支持lua插件参数"
LOG_INFO "步骤5运行简单的uwsgi-lua测试"
cat > /tmp/test.lua << "EOF"
function hello()
return "Hello from Lua"
end
print(hello())
EOF
uwsgi --lua /tmp/test.lua 2>&1 | grep -q "Hello from Lua"
CHECK_RESULT $? 0 0 "uwsgi-lua插件执行失败"
LOG_INFO "步骤6清理临时测试文件"
rm -f /tmp/test.lua
if [ "$INSTALLED" = false ]; then
LOG_INFO "步骤7卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua软件包失败"
LOG_INFO "系统已恢复到测试前状态"
else
LOG_INFO "系统保持uwsgi-plugin-lua软件包安装状态"
fi
LOG_INFO "测试完成uwsgi-plugin-lua软件包安装测试通过"
}
main "$@"

View File

@@ -1,65 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2025-12-10
# @License : Mulan PSL v2
# @Desc : Test memory management
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
LOG_INFO "开始测试内存管理功能"
# 检查是否已安装uwsgi-plugin-lua软件包
LOG_INFO "检查uwsgi-plugin-lua是否已安装"
if dnf list installed uwsgi-plugin-lua &>/dev/null; then
LOG_INFO "uwsgi-plugin-lua已安装脚本结束时将保持安装状态"
INSTALLED=true
else
LOG_INFO "uwsgi-plugin-lua未安装将在测试结束后卸载"
INSTALLED=false
fi
# 检查yum源中是否存在uwsgi-plugin-lua软件包
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua"
if ! dnf list available uwsgi-plugin-lua &>/dev/null; then
LOG_ERROR "yum源中未找到uwsgi-plugin-lua软件包"
exit 255
fi
# 安装uwsgi-plugin-lua软件包如果未安装
if [ "$INSTALLED" = false ]; then
LOG_INFO "安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
fi
# 测试内存管理功能
LOG_INFO "执行内存管理测试命令"
TEST_COMMAND="uwsgi --lua-memory-test" # 假设的命令,实际命令可能不同
$TEST_COMMAND
CHECK_RESULT $? 0 0 "内存管理测试失败"
# 清理环境(如果最初未安装)
if [ "$INSTALLED" = false ]; then
LOG_INFO "卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
fi
LOG_INFO "内存管理测试完成"
}
main "$@"

View File

@@ -1,153 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2026-02-24
# @License : Mulan PSL v2
# @Desc : Test removal of uwsgi-plugin-lua package
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
# 定义日志函数(虽然题目说无需定义,但实际脚本中需要定义才能使用)
LOG_INFO() {
echo "[INFO] $*"
}
LOG_ERROR() {
echo "[ERROR] $*"
}
# 定义检查结果函数
CHECK_RESULT() {
local actual=$1
local expect=$2
local mode=$3
local message=$4
if [ $mode -eq 0 ]; then
if [ $actual -ne $expect ]; then
LOG_ERROR "$message"
exit $actual
fi
elif [ $mode -eq 1 ]; then
if [ $actual -eq $expect ]; then
LOG_ERROR "$message"
exit 1
fi
fi
}
# 定义SSH命令函数
SSH_CMD() {
local cmd=$1
local ip=$2
local password=$3
local user=$4
# 这里只是占位实现实际应根据具体SSH工具实现
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "$cmd"
}
# 主测试函数
main() {
LOG_INFO "开始测试Test removal of uwsgi-plugin-lua package"
# 步骤1检查软件包是否在yum源中
LOG_INFO "步骤1检查uwsgi-plugin-lua软件包是否在yum源中"
dnf list available uwsgi-plugin-lua 2>/dev/null | grep -q uwsgi-plugin-lua
if [ $? -ne 0 ]; then
LOG_ERROR "yum源中未找到uwsgi-plugin-lua软件包"
exit 255
fi
# 步骤2检查当前是否已安装
LOG_INFO "步骤2检查uwsgi-plugin-lua软件包是否已安装"
dnf list installed uwsgi-plugin-lua 2>/dev/null | grep -q uwsgi-plugin-lua
local already_installed=$?
# 记录初始状态
if [ $already_installed -eq 0 ]; then
LOG_INFO "检测到uwsgi-plugin-lua已安装测试结束后将保持安装状态"
local need_cleanup=0
else
LOG_INFO "未检测到uwsgi-plugin-lua安装将在测试后清理"
local need_cleanup=1
fi
# 步骤3如果未安装则安装软件包
if [ $already_installed -ne 0 ]; then
LOG_INFO "步骤3安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
LOG_INFO "安装uwsgi-plugin-lua成功"
fi
# 步骤4验证软件包已安装
LOG_INFO "步骤4验证uwsgi-plugin-lua软件包已正确安装"
rpm -q uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "验证uwsgi-plugin-lua安装状态失败"
LOG_INFO "验证uwsgi-plugin-lua安装成功"
# 步骤5卸载软件包作为测试步骤
LOG_INFO "步骤5卸载uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
LOG_INFO "卸载uwsgi-plugin-lua成功"
# 步骤6验证软件包已卸载
LOG_INFO "步骤6验证uwsgi-plugin-lua软件包已正确卸载"
rpm -q uwsgi-plugin-lua 2>/dev/null
local uninstall_check=$?
if [ $uninstall_check -eq 0 ]; then
LOG_ERROR "uwsgi-plugin-lua软件包卸载验证失败"
exit 1
fi
LOG_INFO "验证uwsgi-plugin-lua卸载成功"
# 步骤7环境恢复
LOG_INFO "步骤7恢复测试环境"
if [ $need_cleanup -eq 1 ]; then
# 如果测试前未安装,则保持未安装状态
LOG_INFO "测试前未安装uwsgi-plugin-lua保持未安装状态"
else
# 如果测试前已安装,则重新安装
LOG_INFO "测试前已安装uwsgi-plugin-lua重新安装以恢复环境"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "恢复uwsgi-plugin-lua安装失败"
LOG_INFO "恢复uwsgi-plugin-lua安装成功"
fi
# 最终验证
LOG_INFO "步骤8最终环境验证"
if [ $need_cleanup -eq 0 ]; then
rpm -q uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "最终环境验证失败uwsgi-plugin-lua未正确恢复"
else
rpm -q uwsgi-plugin-lua 2>/dev/null
if [ $? -eq 0 ]; then
LOG_ERROR "最终环境验证失败uwsgi-plugin-lua不应存在"
exit 1
fi
fi
LOG_INFO "测试完成Test removal of uwsgi-plugin-lua package"
LOG_INFO "所有测试步骤执行成功"
}
# 执行主函数
main "$@"
}
main "$@"

View File

@@ -1,91 +0,0 @@
#!/usr/bin/bash
# Copyright (c) 2024 ISCAS .ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
# http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# #############################################
# @Author : honghua
# @Contact : honghua@iscas.ac.cn
# @Date : 2026-02-24
# @License : Mulan PSL v2
# @Desc : Test verification of plugin installation in uWSGI
# ############################################
source "$OET_PATH/libs/locallibs/common_lib.sh"
function run_test() {
LOG_INFO "开始测试验证uWSGI插件安装功能"
# 检查yum源中是否存在uwsgi-plugin-lua软件包
LOG_INFO "检查yum源中是否存在uwsgi-plugin-lua软件包"
if ! dnf list available uwsgi-plugin-lua 2>/dev/null | grep -q uwsgi-plugin-lua; then
LOG_ERROR "yum源中未找到uwsgi-plugin-lua软件包"
exit 255
fi
# 检查当前是否已安装uwsgi-plugin-lua
LOG_INFO "检查当前是否已安装uwsgi-plugin-lua"
if rpm -q uwsgi-plugin-lua &>/dev/null; then
LOG_INFO "uwsgi-plugin-lua已安装测试结束后将保持安装状态"
already_installed=1
else
LOG_INFO "uwsgi-plugin-lua未安装将在测试过程中安装"
already_installed=0
fi
# 如果未安装,则安装软件包
if [ $already_installed -eq 0 ]; then
LOG_INFO "安装uwsgi-plugin-lua软件包"
dnf install -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "安装uwsgi-plugin-lua失败"
fi
# 验证插件安装功能
LOG_INFO "验证uWSGI插件安装功能"
uwsgi --plugin-list | grep -q lua
CHECK_RESULT $? 0 0 "uWSGI未找到lua插件"
# 验证插件参数支持
LOG_INFO "验证uWSGI插件参数支持"
if ! uwsgi --help 2>&1 | grep -q -- "--lua"; then
LOG_ERROR "uWSGI不支持lua插件参数"
exit 255
fi
# 测试插件基本功能
LOG_INFO "测试lua插件基本功能"
cat > test_lua.lua << "EOF"
print("Lua plugin test successful")
EOF
uwsgi --lua test_lua.lua --http :9090 --http-timeout 1 --master --processes 1 --threads 1 --daemonize /dev/null
CHECK_RESULT $? 0 0 "启动uWSGI带lua插件失败"
# 等待服务启动
sleep 2
# 清理测试文件
rm -f test_lua.lua
# 停止uWSGI进程
pkill -f "uwsgi.*test_lua"
# 环境恢复
if [ $already_installed -eq 0 ]; then
LOG_INFO "卸载测试安装的uwsgi-plugin-lua软件包"
dnf remove -y uwsgi-plugin-lua
CHECK_RESULT $? 0 0 "卸载uwsgi-plugin-lua失败"
else
LOG_INFO "保持uwsgi-plugin-lua安装状态"
fi
LOG_INFO "测试完成uWSGI插件安装功能验证成功"
}
main "$@"