除了_default之外,对于chef_environment的嘲讽会让404分开
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了除了_default之外,对于chef_environment的嘲讽会让404分开相关的知识,希望对你有一定的参考价值。
我试图模仿chef_environment,如果我尝试模拟_default厨师环境,我已经成功了。但是一旦我用不同的环境变量编写上下文块,我就会收到404错误
我有stg和_default厨师环境。但我没有使用_default环境,所以它的default_attributes列表和其他东西都是空的。那么_default工作的原因是什么,而所有其他环境都给出了错误?
下面是我的user_rspec.rb文件: -
require 'ChefSpec'
require 'spec_helper'
describe 'base::users' do
let(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'amazon', version: '2017.09') do |node|
env = Chef::Environment.new
env.name environment # using a variable here so we can change it in other contexts
allow(node).to receive(:chef_environment).and_return(env.name)
allow(Chef::Environment).to receive(:load).and_return(env)
end.converge(described_recipe)
end
context 'When all attributes are default, on an amazon 2017.09 with _default end' do
let(:environment) { '_default' }
it 'converges successfully' do
expect{ chef_run }.to_not raise_error
end
it "create devops group" do
expect(chef_run).to create_users_manage('devops').with(group_id: 3000)
end
it "assign sudo permission to devops-trainee on _default env" do
expect(chef_run).to create_sudo('devops-trainee')
end
end
context 'When all attributes are default, on an amazon 2017.09 with stg env' do
let(:environment) { 'stg' }
it "don't assign sudo permission to devops-trainee on stg env" do
expect(chef_run).not_to create_sudo('devops-trainee')
end
end
end
产量
base::users
When all attributes are default, on an amazon 2017.09 with _default end
converges successfully
create devops group
assign sudo permission to devops-trainee on _default env
When all attributes are default, on an amazon 2017.09 with stg env
don't assign sudo permission to devops-trainee on stg env (FAILED - 1)
Failures:
1) base::users When all attributes are default, on an amazon 2017.09 with stg env don't assign sudo permission to devops-trainee on stg env
Failure/Error:
ChefSpec::ServerRunner.new(platform: 'amazon', version: '2017.09') do |node|
env = Chef::Environment.new
env.name environment # using a variable here so we can change it in other contexts
allow(node).to receive(:chef_environment).and_return(env.name)
allow(Chef::Environment).to receive(:load).and_return(env)
end.converge(described_recipe)
Net::HTTPServerException:
404 "Not Found "
# ./cookbooks/base/spec/unit/recipes/users_spec.rb:16:in `block (2 levels) in <top (required)>'
# ./cookbooks/base/spec/unit/recipes/users_spec.rb:40:in `block (3 levels) in <top (required)>'
Finished in 18.34 seconds (files took 1.36 seconds to load)
4 examples, 1 failure
Failed examples:
rspec ./cookbooks/base/spec/unit/recipes/users_spec.rb:39 # base::users When all attributes are default, on an amazon 2017.09 with stg env don't assign sudo permission to devops-trainee on stg env
ChefSpec Coverage report generated...
Total Resources: 5
Touched Resources: 1
Touch Coverage: 20.0%
答案
好吧,我在上面的例子中发现了问题。
我使用ChefSpec :: ServerRunner而不是SoloRunner,上面的东西只适用于solo runner。
对于ServerRunner,您必须执行以下操作。
let(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'amazon', version: '2017.09') do |node, server|
server.create_environment(environment)
node.chef_environment = environment
end.converge(described_recipe)
end
以上是关于除了_default之外,对于chef_environment的嘲讽会让404分开的主要内容,如果未能解决你的问题,请参考以下文章
除了win32_product之外,是否有更快的方法来查找已安装软件的产品编号
python [Python中的虚拟守护进程]一个虚拟守护进程,除了睡眠之外什么都不做,对于测试systemd和其他服务管理器非常有用#python #daemon