Chef infra 为什么Chefspec找不到我的资源?
我有一个规范配方,其中包括测试两个命令中的一个是否运行。如果安装了第一个命令,将运行该命令。如果没有,则应运行第二个 然而,由于某种原因,该规范配方没有看到第一个执行资源,尽管它将确切命名的资源列为其他执行资源。但它确实看到并传递了第二个命令 RSpec输出如下所示:Chef infra 为什么Chefspec找不到我的资源?,chef-infra,devops,chefspec,Chef Infra,Devops,Chefspec,我有一个规范配方,其中包括测试两个命令中的一个是否运行。如果安装了第一个命令,将运行该命令。如果没有,则应运行第二个 然而,由于某种原因,该规范配方没有看到第一个执行资源,尽管它将确切命名的资源列为其他执行资源。但它确实看到并传递了第二个命令 RSpec输出如下所示: gets admin key using getkey (FAILED - 1) gets admin key using keyremoteclient [passed] it 'gets admin key using yk
gets admin key using getkey (FAILED - 1)
gets admin key using keyremoteclient [passed]
it 'gets admin key using ykeykeygetkey' do
expect(chef_run).to run_execute('use getkey')
end
it 'gets admin key using ykeykeyremoteclient' do
expect(chef_run).to run_execute('keyremoteclient')
end
错误消息:
Failures:
1) cookbook-forwarders::install_forwarder_package gets admin key using getkey
Failure/Error: expect(chef_run).to run_execute('use getkey')
expected "execute[use getkey]" with action :run to be in Chef run.
Other execute resources:
execute[use getkey]
错误的这一部分毫无意义,因为存在确切的资源
-->execute[use getkey]<--
我已经在规范配方开头的“only_if”保护中删除了命令:
before do
# stub command to get admin password using getkey
stub_command('getkey(the_key_name)').and_return('xyz')
# stub command to get admin password using keyremoteclient
stub_command('keyremoteclient(the_kgp, the_key_name)').and_return('xyz')
# stub check if getkey is installed
stub_command('/usr/local/bin/inst ls getkey -noname -noversion').and_return(true)
# stub check for already installed getkey package to use keyremoteclient
stub_command('/usr/local/bin/inst ls getkey -noname -noversion').and_return(false)
end
Spec recipe部分如下所示:
gets admin key using getkey (FAILED - 1)
gets admin key using keyremoteclient [passed]
it 'gets admin key using ykeykeygetkey' do
expect(chef_run).to run_execute('use getkey')
end
it 'gets admin key using ykeykeyremoteclient' do
expect(chef_run).to run_execute('keyremoteclient')
end
所以有几个问题,;第一,不能使用stub_命令来存根Ruby代码,比如getkey。其次,您对两个防护使用相同的命令,因此存根可能相互冲突。我建议您重构代码,使其仅使用单个命令执行。您可能不需要为此编写单元测试,只需编写集成测试即可。谢谢,我怀疑情况就是这样。