Я тестирую рецепт, который создает несколько файлов с owner "dev"
, и получаю это исключение:
Chef::Exceptions::UserIDNotFound
--------------------------------
cannot determine user id for 'dev', does the user exist on this system?
сейчас, в другом рецепте я устанавливаю файл deb, который создает этого пользователя. Есть ли способ издеваться над ним во время теста?
Обновление - Обмен фрагмент кода:
это часть моего рецепта my_cookbook::configure.rb
, что я тестирование с ChefSpe c:
# Code that iterates cluster members with some logic querying Chef Server (until it finds all of them)
....
#define my_service so we can notify it config is changed
#note that i do that to make the tests happy as this service is being installed in another recipe by a .deb file
service "my_service" do
action :nothing
end
template "#{node[:my_service][:config_file]}" do
source "my_service.conf.erb"
owner "dev" # <-- this throws an exception during chefspec test run
group "dev"
mode "0644"
notifies :restart, 'service[my_service]', :delayed
variables(
{
:node_id => node_id,
:cluster_members => cluster_nodes,
}
)
end
и тест:
def get_cluster_members_stubs
[stub_node("my_service_node1.us.example.com",
platform: 'ubuntu',
version: '14.04',
ohai: {
hostname: 'my_service_node1',
ipaddress: '1.2.3.4'
}),
stub_node("my_service_node2.us.example.com",
platform: 'ubuntu',
version: '14.04',
ohai: {
hostname: 'my_service_node2',
ipaddress: '1.2.3.5'
}),
stub_node("my_service_node3.us.example.com",
platform: 'ubuntu',
version: '14.04',
ohai: {
hostname: 'my_service_node3',
ipaddress: '1.2.3.6'
})]
end
describe 'cluster member nodes lookup - wait until all join' do
my_node = {
service: 'my_service',
node: '1',
dc: 'us',
}
before(:context) do
cluster_members_stubs = get_cluster_members_stubs
@chef_run = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '14.04') do |node, server|
node.automatic[:common] = my_node
# This is the current server data (first ha)
server.create_node(cluster_members_stubs[0])
# This is the second ha server data
server.create_node(cluster_members_stubs[1])
end
Thread.new {
@chef_run.converge(described_recipe) do
@chef_run.resource_collection.insert(
Chef::Resource::Service.new('my_service', @chef_run.run_context))
end
}
timeout = 15 # should be enough for converging...
started = Time.now
until (@chef_run.node[:my_service] != nil &&
@chef_run.node[:my_service][:cluster_members] != nil &&
@chef_run.node[:my_service][:cluster_members].length === 2) ||
Time.now - started > timeout
puts "[#{Time.now - started}] waiting for converge...#{@chef_run.node[:my_service]}"
sleep 1
end
puts "[#{Time.now - started}] Converged!...#{@chef_run.node[:my_service][:cluster_members]}"
end
it 'should find the first 2 registered nodes' do
expect(@chef_run.node[:my_service][:cluster_members].to_a).to match_array(['1.2.3.4', '1.2.3.5'])
end
context 'add 20003 in 3 seconds' do
before(:context) do
cluster_members_stubs = get_cluster_members_stubs
sleep 3
@chef_run.create_node(cluster_members_stubs[2])
timeout = 20 # should be enough for converging...
started = Time.now
until (@chef_run.node[:my_service] != nil &&
@chef_run.node[:my_service][:cluster_members] != nil &&
@chef_run.node[:my_service][:cluster_members].length === 3) ||
Time.now - started > timeout
puts "[#{Time.now - started}] waiting for recipe to find our new member...#{@chef_run.node[:my_service]}"
sleep 1
end
puts "[#{Time.now - started}] Found!...#{@chef_run.node[:my_service][:cluster_members]}"
end
it 'should find it once added' do
expect(@chef_run.node[:my_service][:cluster_members].to_a).to match_array(['1.2.3.4', '1.2.3.5', '1.2.3.6'])
end
end
end
При запуске Chef spe c для этого кода (с помощью chef exec rspec spec/configure_spec.rb -f d
) тест проходит успешно но я получаю это исключение:
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
should add all members to my_service.conf as ha.initial_hosts list
cluster member nodes lookup - wait until all join
[4.4e-05] waiting for converge...
[1.003424] waiting for converge...
[2.003765] waiting for converge...
[3.014148] waiting for converge...
[4.027826] waiting for converge...
[5.034108] waiting for converge...
[6.035726] waiting for converge...
[7.039808] waiting for converge...
[8.04352] waiting for converge...
[9.045821] waiting for converge...
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
[10.046889] Converged!...#<Set: {"1.2.3.4", "1.2.3.5"}>
should find the first 2 registered nodes
add 20003 in 3 seconds
[5.4e-05] waiting for recipe to find our new member...
================================================================================
Error executing action `create` on resource 'template[/etc/my_service/my_service.conf]'
================================================================================
Chef::Exceptions::UserIDNotFound
--------------------------------
cannot determine user id for 'dev', does the user exist on this system?
Resource Declaration:
---------------------
# In /var/folders/21/x4vz7kyd19z30q2f_jvn_g3c0000gn/T/chefspec20200202-59873-1g2naeefile_cache_path/cookbooks/my_service/recipes/configure.rb
85: template "#{node[:my_service][:config_file]}" do
86: source "my_service.conf.erb"
87: owner "dev"
88: group "dev"
89: mode "0644"
90: notifies :restart, 'service[my_service]', :delayed
91: variables(
92: {
94: :node_id => node_id,
95: :cluster_members => cluster_nodes,
...
99: }
100: )
102: end
Compiled Resource:
------------------
# Declared in /var/folders/21/x4vz7kyd19z30q2f_jvn_g3c0000gn/T/chefspec20200202-59873-1g2naeefile_cache_path/cookbooks/my_service/recipes/configure.rb:85:in `from_file'
template("/etc/my_service/my_service.conf") do
action [:create]
default_guard_interpreter :default
source "my_service.conf.erb"
declared_type :template
cookbook_name "my_service"
recipe_name "configure"
owner "dev"
group "dev"
mode "0644"
variables {:node_id=>"node1", :cluster_members=>"1.2.3.4,1.2.3.5,1.2.3.6"}
path "/etc/my_service/my_service.conf"
verifications []
end
System Info:
------------
chef_version=15.4.45
platform=ubuntu
platform_version=14.04
ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
program_name=/opt/chefdk/embedded/bin/rspec
executable=/Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb
#<Thread:0x00007fbb70636d88@/Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:138 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
26: from /Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:139:in `block (4 levels) in <top (required)>'
25: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/server_runner.rb:35:in `converge'
24: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/solo_runner.rb:122:in `converge'
23: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `converge'
22: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `catch'
21: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:704:in `block in converge'
20: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:130:in `converge'
19: from /opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `execute_each_resource'
18: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:94:in `execute_each_resource'
17: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
16: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
15: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:86:in `step'
14: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:115:in `call_iterator_block'
13: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:96:in `block in execute_each_resource'
12: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:132:in `block in converge'
11: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `run_all_actions'
10: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `each'
9: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `block in run_all_actions'
8: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:74:in `run_action'
7: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/extensions/chef/resource.rb:42:in `run_action'
6: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource.rb:585:in `run_action'
5: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:175:in `run_action'
4: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:197:in `process_resource_requirements'
3: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `run'
2: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `each'
1: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:238:in `run': cannot determine user id for 'my_service', does the user exist on this system? (Chef::Exceptions::UserIDNotFound)
26: from /Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:139:in `block (4 levels) in <top (required)>'
25: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/server_runner.rb:35:in `converge'
24: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/solo_runner.rb:122:in `converge'
23: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `converge'
22: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `catch'
21: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:704:in `block in converge'
20: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:130:in `converge'
19: from /opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `execute_each_resource'
18: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:94:in `execute_each_resource'
17: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
16: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
15: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:86:in `step'
14: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:115:in `call_iterator_block'
13: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:96:in `block in execute_each_resource'
12: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:132:in `block in converge'
11: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `run_all_actions'
10: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `each'
9: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `block in run_all_actions'
8: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:74:in `run_action'
7: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/extensions/chef/resource.rb:42:in `run_action'
6: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource.rb:585:in `run_action'
5: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:175:in `run_action'
4: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:197:in `process_resource_requirements'
3: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `run'
2: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `each'
1: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:238:in `run': template[/etc/my_service/my_service.conf] (my_service::configure line 85) had an error: Chef::Exceptions::UserIDNotFound: cannot determine user id for 'my_service', does the user exist on this system? (Chef::Exceptions::UserIDNotFound)
[1.004191] Found!...#<Set: {"1.2.3.4", "1.2.3.5", "1.2.3.6"}>
should find it once added