如何在Puppet Litmus中模拟Puppet文件共享路径?
解决Litmus测试中模拟Puppet文件共享的方法
方法1:在临时Puppet服务器上配置文件共享目录
Litmus会部署临时Puppet服务器用于测试,你可以在该服务器上创建puppet:///common对应的文件目录并上传测试文件:
- 在验收测试代码(如
spec/acceptance/your_class_spec.rb)中添加前置操作:before(:suite) do # 定位Litmus部署的Puppet服务器节点 puppet_server = find_one('role=puppet_server') # 创建fileserver对应的common目录 run_command('mkdir -p /etc/puppetlabs/code/files/common', target: puppet_server) # 上传测试用的data.txt到该目录 create_remote_file(puppet_server, '/etc/puppetlabs/code/files/common/data.txt', '测试文件内容') end - 测试节点的Puppet agent运行时,就能从临时服务器的
common共享中拉取文件,避免失败。
方法2:单节点测试时本地模拟文件源
如果测试在单节点(agent与server同节点)运行,可通过自定义fileserver配置实现:
- 创建临时fileserver配置文件
/tmp/fileserver.conf:[common] path /tmp/puppet_files/common allow * - 在测试代码中完成目录创建、文件上传,并指定配置运行Puppet:
before(:all) do target_node = find_one('role=agent') # 创建本地文件目录 run_command('mkdir -p /tmp/puppet_files/common', target: target_node) # 上传测试文件 create_remote_file(target_node, '/tmp/puppet_files/common/data.txt', '测试文件内容') # 指定自定义fileserver配置运行manifest apply_manifest(your_class_manifest, { '--fileserverconfig' => '/tmp/fileserver.conf' }, target: target_node) end
方法3:临时覆盖file资源的source参数
若只需验证类的其他逻辑,可跳过文件服务器模拟,直接覆盖source:
# 先加载你的目标类 include your_class # 重新定义file资源,用本地文件替代puppet://源 file { '/opt/common/data.txt': ensure => file, source => 'file:///tmp/test_data.txt', }
测试前用create_remote_file上传/tmp/test_data.txt即可。
内容的提问来源于stack exchange,提问作者Tamerz
相关产品推荐
相关产品推荐

