“找不到菜谱apache_wrapper”;在apache_wrapper食谱中运行Chefspec时 [英] "Cookbook apache_wrapper not found" when running chefspec in apache_wrapper cookbook

查看:82
本文介绍了“找不到菜谱apache_wrapper”;在apache_wrapper食谱中运行Chefspec时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是厨师规范的新手,并尝试找出如何在我的食谱中使用单元测试。
我已经安装了chefdk(在不同的ubuntu实例上的v2和v3)和刀规格插件。
创建 apache_wrapper食谱后,我更改了下一个文件:

I'm new in chef spec and try to figure out how to use unit testing in my cookbooks. I have installed chefdk(v2 and v3 on different ubuntu instances) and knife spec plugin. After "apache_wrapper" cookbook creation I have changed next files:

spec / spec_helper.rb

spec/spec_helper.rb

require 'chefspec'
require 'chefspec/berkshelf'

RSpec.configure do |config|
config.log_level = :debug
  config.platform = 'ubuntu'
  config.version = '12.04'
end

spec / recipes / default_spec.rb

spec/recipes/default_spec.rb

require_relative '../spec_helper'

describe 'apache_wrapper::default' do
  subject { ChefSpec::Runner.new.converge(described_recipe) }

  it 'includes community cookbook apache2' do
    expect(subject).to include_recipe('apache2')
  end

  it 'creates a template with attributes' do
    expect(subject).to create_template('/var/www/html/index.html').with(
      user:   'root',
      group:  'root',
      backup: true,
    )

    expect(subject).to_not create_template('/var/www/html/index.html').with(
      user:   'bacon',
      group:  'fat',
      backup: true,
    )
  end
end

在我的食谱默认值中。eb:

in my recipe default.eb:

include_recipe 'apache2'

template "/var/www/html/index.html" do
  source "index.html.erb"
  mode 00644
end

但是当我调用rspec时,我得到了下一个:

But when I invoke rspec I got next:

$ pwd
/tmp/apache_wrapper
$ rspec
...
Failures:

  1) apache_wrapper::default includes community cookbook apache2
     Failure/Error: subject { ChefSpec::Runner.new.converge(described_recipe) }
     Chef::Exceptions::CookbookNotFound:
       Cookbook apache_wrapper not found. If you're loading apache_wrapper from another cookbook, make sure you configure the dependency in your metadata
     # ./spec/recipes/default_spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./spec/recipes/default_spec.rb:27:in `block (2 levels) in <top (required)>'

  2) apache_wrapper::default creates a template with attributes
     Failure/Error: subject { ChefSpec::Runner.new.converge(described_recipe) }
     Chef::Exceptions::CookbookNotFound:
       Cookbook apache_wrapper not found. If you're loading apache_wrapper from another cookbook, make sure you configure the dependency in your metadata
     # ./spec/recipes/default_spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./spec/recipes/default_spec.rb:31:in `block (2 levels) in <top (required)>'

Finished in 0.32355 seconds (files took 2.39 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/recipes/default_spec.rb:26 # apache_wrapper::default includes community cookbook apache2
rspec ./spec/recipes/default_spec.rb:30 # apache_wrapper::default creates a template with attributes

然后在Cookbook文件夹中出现Berksfile.lock。
有人可以告诉我我在做什么错吗?

And in cookbook folder Berksfile.lock appeared. Can anybody told me what Im doing wrong?

UPD:

Berksfile:

Berksfile:

source "https://supermarket.getchef.com"
cookbook 'apache2', '= 1.9.6'

Berksfile.lock

Berksfile.lock

DEPENDENCIES
  apache2 (= 1.9.6)

GRAPH
  apache2 (1.9.6)
    iptables (>= 0.0.0)
    logrotate (>= 0.0.0)
    pacman (>= 0.0.0)
  iptables (0.14.0)
  logrotate (1.7.0)
  pacman (1.1.1)

UPD2:

cat ../apache_wrapper/metadata.rb | grep -E 'dep|nam'
name             'apache_wrapper'
depends 'apache2'

UPD3:

我也尝试使用下一个

let (:chef_run) { ChefSpec::ServerRunner.new.converge 'apache_wrapper::default' } 

并现在收到

Missing Cookbooks:
------------------
No such cookbook: apache_wrapper

Expanded Run List:
------------------
* apache_wrapper::default

F

Failures:

  1) apache_wrapper::default includes community cookbook apache2
     Failure/Error: let (:chef_run) { ChefSpec::ServerRunner.new.converge 'apache_wrapper::default' }
     Net::HTTPServerException:
       412 "Precondition Failed "
     # ./spec/default_spec.rb:23:in `block (2 levels) in <top (required)>'
     # ./spec/default_spec.rb:26:in `block (2 levels) in <top (required)>

我不明白,我做错了什么,今天我开始新的实例,在那儿安装ruby2.1以及chefspec等其他所有宝石。现在使用rake运行测试,但仍然出现相同的错误

I don't understand, what Im doing wrong, today I've started new instans, install there ruby2.1 and all gems like chefspec and others. And now use rake to run tests, but still getting same error

解决方案:
只需在菜谱Berksfile中添加元数据

SOLUTION: Just add "metadata" to cookbooks Berksfile

推荐答案

您必须在菜谱中指定 apache2作为依赖项 metadata.rb

You must specify "apache2" as dependency in your cookbooks metadata.rb :

name             'COOKBOOK NAME'
maintainer       'YOUR NAME'
maintainer_email 'YOUR_EMAIL'
...

version          '0.0.1'

depends          'apache2'

之后,您可以在食谱中加入 apache2中的食谱。

After that you can include recipes from "apache2" in your cookbook.

更新:

此外,您还需要指定 apache_wrapper食谱的位置,请检查Chefspec的配置选项了解更多信息

Also you need to specify where your "apache_wrapper" cookbook is located, please check chefspec's configuration options for more info

更新2

添加元数据到Berksfile中,Berkshelf将在其中添加您的本地食谱到本地食谱列表。

Add metadata to your Berksfile, with that in place Berkshelf will add your local cookbook to List of local cookbooks.

从berkshelf.com:

From berkshelf.com:


metadata关键字就像在Bundler的Gemfile中说出gemspec。它说:在我的Berksfile的相同相对路径中有一个metadata.rb文件。这样一来,您就可以解析当前正在使用的Cookbook的依赖项,就像解析当前正在使用Bundler的Gem的依赖项一样。

The metadata keyword is like saying gemspec in Bundler’s Gemfile. It says, "There is a metadata.rb file within the same relative path of my Berksfile". This allows you to resolve a Cookbook’s dependencies that you are currently working on just like you would resolve the dependencies of a Gem that you are currently working on with Bundler.

这篇关于“找不到菜谱apache_wrapper”;在apache_wrapper食谱中运行Chefspec时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆