fix(cd): 兼容应用与集成测试共用的 QA 凭据文件
build / build (push) Successful in 1m32s

This commit is contained in:
姚章浩
2026-11-23 13:54:07 +08:00
parent 8faabdcf9e
commit 9cfe2114b1
3 changed files with 30 additions and 4 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
- 版本管理机使用 Python 3.11 及以上、Docker Compose、HiFox CLI 和已有 Gitea 凭据。候选执行器通过 `candidate_worker.py <仓库工作树> <访问文件>` 绑定 `127.0.0.1:38984`,仓库工作树允许读取 `origin/main`。执行器通过现有 Gitea 凭据读取作业与日志。运行账户需能以 `weknora-test` 执行只读版本检查。
- 为候选执行器单独配置 `kg-candidate` Runner。作业使用同机回环网络,通过仓库 Secrets 的 `KG_CANDIDATE_ACCESS` 访问执行器。访问文件由执行器用户持有,内容为独立 64 位十六进制随机凭据。候选作业使用的容器须无宿主 Docker socket 和生产密钥挂载。
- 业务验收使用 `~/.config/knowledge-governance/{qa.json,qa.pgpass,rds-ca.pem}`。复用 `qa_env.py` 的专用 `kg_qa_` RDS 库和角色校验。验收使用专用账号与测试数据。需要验证外部系统的用例须先准备各自的隔离资源。
- 业务验收使用 `~/.config/knowledge-governance/{qa.json,qa.pgpass,rds-ca.pem}`。复用 `qa_env.py` 的专用 `kg_qa_` RDS 库和角色校验。`qa.pgpass` 可包含同一端点的应用库和集成测试库条目,候选只读取 `qa.json` 指定的库和角色。验收使用专用账号与测试数据。需要验证外部系统的用例须先准备各自的隔离资源。
- 候选执行器采用单验收槽。新批次启动前由运维确认前一批验收结束,按上一批 `ready.json` 中的容器身份停止其 Compose 项目,归档原有配置和回执后释放槽位。保留已验收的归档及审批记录。
## 演练和当前环境
+7 -3
View File
@@ -35,10 +35,14 @@ def qa_database(path):
passfile, cert = [path.parent / name for name in ('qa.pgpass', 'rds-ca.pem')]
qa_env.private_file(passfile)
qa_env.private_file(cert)
expected = f"{db['host']}:{db['port']}:{db['database']}:{db['user']}:"
endpoint = f"{db['host']}:{db['port']}:"
expected = f"{endpoint}{db['database']}:{db['user']}:"
entries = [line for line in passfile.read_text().splitlines() if line and not line.startswith('#')]
cd.require(len(entries) == 1 and entries[0].startswith(expected), 'pgpass must authorize exactly the dedicated QA database')
password = re.sub(r'\\(.)', r'\1', entries[0][len(expected):])
qa_entry = re.compile(re.escape(endpoint) + r'kg_qa_[a-z0-9_]{1,56}:kg_qa_[a-z0-9_]{1,56}:(?:[^:\\]|\\.)+')
cd.require(all(qa_entry.fullmatch(line) for line in entries), 'pgpass must contain only exact QA entries at the configured endpoint')
matching = [line for line in entries if line.startswith(expected)]
cd.require(len(matching) == 1, 'pgpass must contain exactly one entry for the configured QA database and role')
password = re.sub(r'\\(.)', r'\1', matching[0][len(expected):])
cd.require(bool(password), 'dedicated QA database password missing')
url = (f"postgresql://{db['user']}:{quote(password, safe='')}@{db['host']}:{db['port']}/{db['database']}"
'?sslmode=verify-full&sslrootcert=/run/qa/rds-ca.pem')
+22
View File
@@ -6,6 +6,7 @@ from types import SimpleNamespace
from unittest.mock import patch
import candidate_release as candidate
import candidate_runtime as runtime
import production_cd as cd
BASE, A, B, OTHER = [c * 40 for c in 'abcd']
@@ -66,6 +67,27 @@ class CandidateReleaseTest(unittest.TestCase):
with self.assertRaisesRegex(cd.CDError, 'candidate must be on main'):
candidate.verify_source(dict(plan, base=root, sha=live), repo)
def test_candidate_selects_only_the_configured_qa_password(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
config = root / 'qa.json'
pgpass = root / 'qa.pgpass'
cert = root / 'rds-ca.pem'
for path in (config, pgpass, cert):
path.touch(mode=0o600)
config.write_text('{"host":"kg-qa-rds.test","port":15483,"database":"kg_qa_app","user":"kg_qa_app"}')
application = 'kg-qa-rds.test:15483:kg_qa_app:kg_qa_app:app\\:example'
integration = 'kg-qa-rds.test:15483:kg_qa_it:kg_qa_it:it-example'
pgpass.write_text(f'{integration}\n{application}\n')
url, ca = runtime.qa_database(config)
self.assertEqual(ca, cert)
self.assertIn('app%3Aexample@kg-qa-rds.test:15483/kg_qa_app', url)
for rows in ((integration,), (application, application), (application, '*:15483:*:*:example'),
(application, 'kg-qa-rds.test:15483:governance:governance:example')):
pgpass.write_text('\n'.join(rows))
with self.subTest(rows=rows), self.assertRaises(cd.CDError):
runtime.qa_database(config)
def test_require_all_qa_reports_and_shared_regression(self):
sources = {QA1: (self.report, self.result()), QA2: (self.report, self.result())}
with self.assertRaisesRegex(cd.CDError, 'every requirement and the release task'):