From 04f2866a03941d48028c3b9a6163119cb5b1cd61 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 12 Nov 2025 17:04:29 +0800 Subject: [PATCH] add ostree test case --- docs/system_base/ostree/tc_ostree_fun001.yaml | 22 ++++++ docs/system_base/ostree/tc_ostree_fun002.yaml | 22 ++++++ docs/system_base/ostree/tc_ostree_fun003.yaml | 22 ++++++ tests/system_base/ostree/tc_ostree_fun001.py | 69 ++++++++++++++++++ tests/system_base/ostree/tc_ostree_fun002.py | 69 ++++++++++++++++++ tests/system_base/ostree/tc_ostree_fun003.py | 70 +++++++++++++++++++ 6 files changed, 274 insertions(+) create mode 100644 docs/system_base/ostree/tc_ostree_fun001.yaml create mode 100644 docs/system_base/ostree/tc_ostree_fun002.yaml create mode 100644 docs/system_base/ostree/tc_ostree_fun003.yaml create mode 100644 tests/system_base/ostree/tc_ostree_fun001.py create mode 100644 tests/system_base/ostree/tc_ostree_fun002.py create mode 100644 tests/system_base/ostree/tc_ostree_fun003.py diff --git a/docs/system_base/ostree/tc_ostree_fun001.yaml b/docs/system_base/ostree/tc_ostree_fun001.yaml new file mode 100644 index 00000000..a7109986 --- /dev/null +++ b/docs/system_base/ostree/tc_ostree_fun001.yaml @@ -0,0 +1,22 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local,ostree +用例描述: ostree-finalize-staged.service服务测试 +修改人: douzhichong + +前置条件: +系统已安装ostree + + +测试步骤: +- 检查服务状态是否为inactive +- 根据服务启用状态测试enable/disable功能 +- 检查服务日志是否有错误信息 + +期望结果: +- 服务状态显示正确 +- enable/disable功能正常 +- 日志无错误信息 diff --git a/docs/system_base/ostree/tc_ostree_fun002.yaml b/docs/system_base/ostree/tc_ostree_fun002.yaml new file mode 100644 index 00000000..884eeb12 --- /dev/null +++ b/docs/system_base/ostree/tc_ostree_fun002.yaml @@ -0,0 +1,22 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local,ostree +用例描述: ostree-prepare-root.service服务测试 +修改人: douzhichong + +前置条件: +系统已安装ostree + + +测试步骤: +- 检查服务状态是否为inactive +- 根据服务启用状态测试enable/disable功能 +- 检查服务日志是否有错误信息 + +期望结果: +- 服务状态显示正确 +- enable/disable功能正常 +- 日志无错误信息 diff --git a/docs/system_base/ostree/tc_ostree_fun003.yaml b/docs/system_base/ostree/tc_ostree_fun003.yaml new file mode 100644 index 00000000..c14d4c60 --- /dev/null +++ b/docs/system_base/ostree/tc_ostree_fun003.yaml @@ -0,0 +1,22 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local,ostree +用例描述: ostree-remount.service服务测试 +修改人: douzhichong + +前置条件: +系统已安装ostree + + +测试步骤: +- 检查服务状态是否为inactive +- 根据服务启用状态测试enable/disable功能 +- 检查服务日志是否有错误信息 + +期望结果: +- 服务状态显示正确 +- enable/disable功能正常 +- 日志无错误信息 diff --git a/tests/system_base/ostree/tc_ostree_fun001.py b/tests/system_base/ostree/tc_ostree_fun001.py new file mode 100644 index 00000000..1aa9d744 --- /dev/null +++ b/tests/system_base/ostree/tc_ostree_fun001.py @@ -0,0 +1,69 @@ +""" +@File: tc_ostree_fun001.py +@Time: 2025/11/12 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_ostree_fun001.yaml for details + + :avocado: tags=P1,noarch,local,ostree + """ + PARAM_DIC = {"pkg_name": "ostree"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + + service = 'ostree-finalize-staged.service' + status = 'inactive (dead)' + code, log_time = self.cmd("date '+%Y-%m-%d %T'") + command = f'systemctl status {service} | grep "Active" | grep -v "{status}"' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"There is an error for the status of {service}") + # 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}") + + def tearDown(self): + super().tearDown(self.PARAM_DIC) diff --git a/tests/system_base/ostree/tc_ostree_fun002.py b/tests/system_base/ostree/tc_ostree_fun002.py new file mode 100644 index 00000000..096a59f2 --- /dev/null +++ b/tests/system_base/ostree/tc_ostree_fun002.py @@ -0,0 +1,69 @@ +""" +@File: tc_ostree_fun002.py +@Time: 2025/11/12 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_ostree_fun002.yaml for details + + :avocado: tags=P1,noarch,local,ostree + """ + PARAM_DIC = {"pkg_name": "ostree"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + + service = 'ostree-prepare-root.service' + status = 'inactive (dead)' + code, log_time = self.cmd("date '+%Y-%m-%d %T'") + command = f'systemctl status {service} | grep "Active" | grep -v "{status}"' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"There is an error for the status of {service}") + # 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}") + + def tearDown(self): + super().tearDown(self.PARAM_DIC) diff --git a/tests/system_base/ostree/tc_ostree_fun003.py b/tests/system_base/ostree/tc_ostree_fun003.py new file mode 100644 index 00000000..9bb41e06 --- /dev/null +++ b/tests/system_base/ostree/tc_ostree_fun003.py @@ -0,0 +1,70 @@ +""" +@File: tc_ostree_fun003.py +@Time: 2025/11/12 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_ostree_fun003.yaml for details + + :avocado: tags=P1,noarch,local,ostree + """ + PARAM_DIC = {"pkg_name": "ostree"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + + service = 'ostree-remount.service' + status = 'inactive (dead)' + code, log_time = self.cmd("date '+%Y-%m-%d %T'") + command = f'systemctl status {service} | grep "Active" | grep -v "{status}"' + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertTrue(result.returncode, f"There is an error for the status of {service}") + # 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}") + + def tearDown(self): + super().tearDown(self.PARAM_DIC) + -- Gitee