我正在为我正在研究的一些新的厨师食谱编写InSpec测试.我想利用cookbook使用的data_bags迭代数据包项.我无法弄清楚如何在我的InSpec测试中访问它们!配方使用search,data_bag和data_bag_item方法.但是这些方法似乎在我的InSpec测试中不可用.我怀疑这些是Chef DSL特有的方法吗?data_bags的源代码在源代码控制之下,因此我可以在本地文件系统上访问它们的json.
如何使用InSpec语法在Chef_zero中访问这些data_bags?
我在网上找了几个例子,但是我没看到chef_zero实际上是如何加载data_bag的,所以它们可以在测试中使用,例如https://github.com/charlesjohnson/fundamentals-with-tests/blob/master /chef-repo/cookbooks/users/test/integration/default/serverspec/default_spec.rb 和 https://github.com/chef/chef/blob/master/kitchen-tests/test/integration/webapp/default_spec.rb
我在Vagrant测试厨房使用Windows服务器2012R2盒子.这是来自其中一个数据包的数据包项目的示例:
{
  "User": "mcummins",
  "FullName": "Martin Cummins",
  "id": "mcummins"
}
此特定数据包列出了添加到管理员组的Windows Active Directory用户.
我已经在我的.kitchen.yml中设置了data_bag_path(我在套件和配置器中设置了它)但是我没有达到可以看出哪一个是正确的点:
---
driver:
  name: vagrant
  customize:
   natdnshostresolver1: "on"
provisioner:
  name: chef_zero
  data_bags_path: ../../../data_bags
#  client_rb:
#    audit_mode: :audit_only
verifier:
  name: inspec
platforms:
   - name: mwrock/Windows2012R2
     transport:
      name: winrm
suites:
  - name: default
    data_bags_path: ../../../data_bags
    run_list:
      - recipe[SPMWindowsBuilder::default]
    verifier:
      inspec_tests:
        - test/integration
    attributes:
我已将厨师文件从我的厨师服务器复制到本地客户端节点,在 下~/.chef,我拥有~/.chef/environments、 例如development.rb、production.rb等下的所有环境。
当我chef-client -z -E development -r 'recipe[cookbook_foo::recipe_bar]'从下面运行时~/.chef/,我收到此错误:
================================================================================
Error expanding the run_list:
================================================================================
Unexpected API Request Failure:
-------------------------------
Object not found: http://localhost:8889/environments/development
如果我在没有运行命令的情况下-E development一切正常。但是,我需要传递环境名称,因为#{node.chef_environment}该厨师食谱中使用了变量。谷歌没有向我提供有关此问题的答案:/
我使用的是厨师客户端 11.16.4
有任何想法吗?