提交 issue 时如何提供最小可复现的 SLS 与版本信息?

解读

面试官想知道你是否具备“让社区一眼就能定位 Bug”的素养。国内很多工程师直接把整个业务仓库打包上传,或只贴一段报错栈,结果维护者因环境差异无法复现,issue 被直接标记为 “incomplete” 甚至 “invalid”。正确做法是:

  1. 给出 最小、独立、可运行 的 SLS 片段;
  2. 提供 精确、可验证 的版本与运行环境;
  3. 用 国内可访问 的文本方式一次性贴出,避免外部链接失效。

知识点

  1. 最小可复现 SLS 三要素

    • 单文件:只保留触发 Bug 的 state,其余依赖全部剔除。
    • 无业务数据:用 placeholder 或 test.sls 代替敏感变量。
    • 自包含:把 pillar、grains、文件模板全部内联,确保别人 salt-call --local state.apply 即可复现。
  2. 版本信息四件套

    • Salt Version:salt --versions-report 完整输出,包含 Python、Tornado、Jinja2 等依赖。
    • OS/Arch:cat /etc/os-release + uname -a,国内常见如 CentOS 7.9.2009 x86_64。
    • 安装方式:salt-minion 来自 阿里云镜像、官方 repo 还是 pip,不同源补丁级别不同。
    • Master/Minion 同异:明确是否同一台机器,或跨云 VPC,网络延迟也可能触发 race condition。
  3. 国内特色细节

    • 镜像源:如果用了 清华 TUNA 或 中科大源,需注明,防止国外维护者拉不到相同包。
    • 中文路径:Windows Minion 若路径含中文,需额外给出 chcp 65001 前后对比。
    • 合规脱敏:用 example.com 代替真实域名,用 xxxxx 代替 AK/SK,避免违反公司合规。

答案

步骤如下,可直接作为 issue 模板粘贴:

  1. 创建最小目录结构
/tmp/salt-issue/
├── repro.sls
├── pillar.sls
└── minion
  1. 文件内容示例
    repro.sls
{% set user = pillar.get('user', 'test') %}
create_user:
  user.present:
    - name: {{ user }}
    - home: /home/{{ user }}

pillar.sls

user: repro

minion

file_client: local
pillar_roots:
  base:
    - /tmp/salt-issue
  1. 复现命令
cd /tmp/salt-issue
salt-call --local --config-dir=. --pillar-root=. state.apply repro
  1. 版本信息
# salt --versions-report
Salt Version:
           Salt: 3006.4
Python Version:
           Python: 3.9.16 (main, May 29 2023, 15:17:16)
Dependency Versions:
           Jinja2: 3.1.2
           Tornado: 4.5.3
…
  1. 报错输出
[ERROR   ] User 'repro' already exists, but the home directory /home/repro does not
  1. 补充说明
  • OS:CentOS Linux release 7.9.2009 (Core)
  • 安装源:阿里云镜像 baseurl=https://mirrors.aliyun.com/saltstack/py3/redhat/7/x86_64/3006/
  • 是否 SELinux:Enforcing
  • 是否容器:否,物理机

把以上 1-6 项一次性贴入 GitHub Issue 或 Gitee Issue,不打外部补丁、不引用私有仓库,维护者可在 5 分钟内复现并定位。

拓展思考

  1. 如果 Bug 只在 Salt-SSH 出现,需额外给出 roster 文件与 -l debug 日志,并说明 目标机 SSH 版本(国内很多主机仍用 OpenSSH_7.4,会导致 async 失败)。
  2. 对于 Windows Minion,需附加 systeminfo|findstr /B /C:"OS Name" 与 PowerShell 版本;中文系统还需给出 win32_locale 输出,防止编码 Bug。
  3. 若涉及 云厂商 API(如阿里云 ECS),可录制 dry-run 输出:salt-cloud -p aliyun-centos7 test-node -l debug >cloud.log 2>&1,并替换 AK/SK 为 xxx。
  4. 养成 git bisect 习惯:在 Salt 官方仓库里快速定位引入 Bug 的 commit,再提交 git bisect log,社区会直接 assign 给对应作者,极大提升修复速度。