测试厨师角色和环境 [英] Testing Chef roles and environments
问题描述
我是Chef的新手,并且一直使用测试厨房来测试我的菜谱的有效性,效果很好。现在,我要确保在最初运行Chef之前,特定于环境的属性在生产节点上是正确的。这些将在角色中定义。
I'm new to Chef and have been using Test Kitchen to test the validity of my cookbooks, which works great. Now I'm trying to ensure that environment-specific attributes are correct on production nodes prior to running Chef initially. These would be defined in a role.
例如,我有一些食谱可以使用带有开发人员设置的Vagrant框来收敛,从而验证食谱。我希望能够测试生产节点的角色。我想我希望这些测试成为描述我的环境的真实来源。看看Test Kitchen的文档,这似乎超出了范围。
For example, I may have recipes that converge using a Vagrant box with dev settings, which validates the cookbook. I want to be able to test that a production node's role. I think I want these tests as the source of truth describing my environment. Looking at Test Kitchen's documentation, this seems beyond its scope.
我的假设正确吗?在第一次在生产节点上运行Chef之前,是否有更好的方法来测试菜谱以确保它具有正确的设置?
Is my assumption correct? Is there a better approach to test a cookbook before the first time Chef is run on a production node to ensure it has the correct settings?
推荐答案
我很高兴地发现Chef_zero在其厨师存储库中使用了 test / integration目录。
I pleasantly discovered that chef_zero uses the "test/integration" directory as it's chef repository.
只需在
- 测试/集成/角色
标准厨师食谱布局。
├── attributes
│ └── default.rb
├── Berksfile
├── Berksfile.lock
├── chefignore
├── .kitchen.yml
├── metadata.rb
├── README.md
├── recipes
│ └── default.rb
└── test
└── integration
├── default
│ └── serverspec
│ ├── default_spec.rb
│ └── spec_helper.rb
└── roles
└── demo.json
.kitchen.yml
.kitchen.yml
---
driver:
name: vagrant
provisioner:
name: chef_zero
platforms:
- name: ubuntu-14.04
suites:
- name: default
run_list:
- role[demo]
attributes:
注意:
- 供应商是Chef_zero
- 运行列表配置为使用角色
file "/opt/helloworld.txt" do
content "#{node['demo']['greeting']}"
end
属性/默认值。 rb
attributes/default.rb
default['demo']['greeting'] = "hello world"
注意:
- 没有默认值
require 'spec_helper'
describe file('/opt/helloworld.txt') do
it { should be_file }
its(:content) { should match /this came from my role/ }
end
注意:
- 集成测试正在寻找由角色设置的内容属性
{
"name": "demo",
"default_attributes": {
"demo": {
"greeting": "this came from my role"
}
},
"run_list": [
"recipe[demo]"
]
}
这篇关于测试厨师角色和环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!