Chef - 测试传递给启动服务时使用的配方的变量

时间:2017-07-03 14:16:37

标签: rspec chef chef-recipe

我有一个小配方,负责停止和启动服务。

该配方由机器执行块中的另一个调用,该块将服务器上的节点设置为特定端口,然后用于直接定位该服务。

我正在尝试单独测试它,因此粉丝无法模拟节点或设置该变量。

任何有关如何实现的帮助都会很棒,谢谢。

port = node['restart-port'] #this will change to 'current port' or something

solrCore = "solr_#{port}"
# solrCore = "solr_8987"

service solrCore do
  service_name solrCore
  supports :status => true, :stop => true, :start => true
  action :nothing
end

ruby_block "stop the service" do
  block do
    Chef::Log.info('triggers restart')
    notifies :stop, run_context.resource_collection.find(:service => solrCore), :immediately
    sleep 30
    notifies :run, run_context.resource_collection.find(:ruby_block => 'start the service')
  end
end

ruby_block "start the service" do
  block do
    Chef::Log.info('triggers start')
    action :nothing
    notifies :start, run_context.resource_collection.find(:service => solrCore), :immediately
  end
end

我可怜的测试课程:

    let(:chef_run) do
  runner = ChefSpec::ServerRunner.new
  runner.converge(described_recipe)
end

it 'converges successfully' do
  expect { chef_run }.to_not raise_error
end

it 'has create and defined the solr service' do
  expect(chef_run).to_not enable_service('solr_port but how, node is transient')
end

0 个答案:

没有答案