feat(chv-guest): 阶段 1 数据盘独立持久(客内挂载)
- 新增 chv-guest/chv-data-mount.sh:按 LABEL=CHVDATA 找盘 (不依赖 /dev/vd? 固定名;seed ISO 与根盘排除),无 fs 即 mkfs.ext4 -L CHVDATA,挂到 /home/chv/workspace,幂等; 无数据盘即静默退出 0(copy 模式旧 VM 不报错)。 - build.sh:缺脚本即失败(与 chv-sync.sh 同款门);拷入 镜像 /usr/local/bin/chv-data-mount;99-chv-sync.cfg runcmd 在 chv-sync boot 之前调它(工作区先挂好再 clone)。 - buildinfo.py BASE_CONTENTS 与两 lockfile DECLARED_SOURCES 登记 chv-data-mount(repo_commit,随 P2 三脚本先例)。 - tests:test_chv_opt_stage1.DataMountScriptTest(脚本内容、 构建接线、lockfile 登记);P2 干跑夹具补新文件。 回归:discover test_chv_*.py 与 test_cloud_hypervisor.py 全过。 不推、不合、不部署;只本地分支。
This commit is contained in:
1 parent
7a6fae7993
commit
a5f836e9fd
7 files changed
+118
-2
No files matched your search
@@ -568,7 +568,8 @@ class BuildDryRunTest(unittest.TestCase):
|
||||
os.makedirs(os.path.join(bindir, "codex-resources"))
|
||||
for name in ("build.sh", "buildinfo.py", "check_lockfile.py",
|
||||
"generate_lockfile.py", "chv-sync.sh",
|
||||
"chv-cell.py", "chv-broker.py", "chv-browser.py"):
|
||||
"chv-cell.py", "chv-broker.py", "chv-browser.py",
|
||||
"chv-data-mount.sh"):
|
||||
shutil.copy2(ROOT / "chv-guest" / name,
|
||||
os.path.join(guest, name))
|
||||
shutil.copy2(ROOT / "host.py", os.path.join(repo, "host.py"))
|
||||
|
||||
@@ -653,5 +653,55 @@ class PersistentPoolTest(ChvOpt1Case):
|
||||
self.assertEqual(len(self.launches), 1)
|
||||
|
||||
|
||||
# -- 数据盘挂载脚本与构建接线 ----------------------------------------------
|
||||
class DataMountScriptTest(unittest.TestCase):
|
||||
def _repo(self, *parts):
|
||||
return os.path.join(
|
||||
Path(__file__).resolve().parents[2], *parts)
|
||||
|
||||
def test_mount_script_present_and_safe(self):
|
||||
path = self._repo("chv-guest", "chv-data-mount.sh")
|
||||
with open(path) as fh:
|
||||
text = fh.read()
|
||||
self.assertIn("LABEL=CHVDATA", text)
|
||||
self.assertIn("/home/chv/workspace", text)
|
||||
self.assertIn("mkfs.ext4", text)
|
||||
# 无数据盘即静默退出 0,不挡启动;绝不含任何秘密值。
|
||||
self.assertIn("no data disk found, skip", text)
|
||||
for secret in ("GITEA_TOKEN", "sk-", "password"):
|
||||
self.assertNotIn(secret, text)
|
||||
|
||||
def test_build_sh_wires_mount_script(self):
|
||||
with open(self._repo("chv-guest", "build.sh")) as fh:
|
||||
text = fh.read()
|
||||
self.assertIn("chv-data-mount.sh:/usr/local/bin/", text)
|
||||
self.assertIn("chv-data-mount >>/var/log/chv-data-mount.log",
|
||||
text)
|
||||
# 挂载在 chv-sync boot 之前(工作区须先挂好再 clone):
|
||||
# 以 99-chv-sync.cfg 那一行为准(文件头注释里也出现
|
||||
# chv-sync boot 字样,不能全文 index 比对)。
|
||||
cfg_line = next(
|
||||
line for line in text.splitlines()
|
||||
if "99-chv-sync.cfg" in line and "runcmd" in line)
|
||||
self.assertLess(cfg_line.index("chv-data-mount >>"),
|
||||
cfg_line.index("chv-sync boot"))
|
||||
|
||||
def test_lockfile_declares_mount_script(self):
|
||||
import importlib.util
|
||||
guest = self._repo("chv-guest")
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"stage1_buildinfo", os.path.join(guest, "buildinfo.py"))
|
||||
buildinfo = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(buildinfo)
|
||||
self.assertIn("chv-data-mount", buildinfo.BASE_CONTENTS)
|
||||
for name in ("check_lockfile.py", "generate_lockfile.py"):
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"stage1_" + name[:-3], os.path.join(guest, name))
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
self.assertEqual(mod.DECLARED_SOURCES["chv-data-mount"],
|
||||
"repo_commit")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user