lib/itamae-mitsurin/mitsurin/serverspec_task.rb in itamae-mitsurin-0.30 vs lib/itamae-mitsurin/mitsurin/serverspec_task.rb in itamae-mitsurin-0.31
- old
+ new
@@ -14,11 +14,11 @@
file_name = File.basename(node_file, '.json')
begin
node_attr = JSON.parse(File.read(node_file), symbolize_names: true)
rescue JSON::ParserError => e
puts e.class.to_s + ", " + e.backtrace[0].to_s
- puts "nodefile error, nodefile:#{node_file}, reason:#{e.message}"
+ puts "Node error, nodefile:#{node_file}, reason:#{e.message}"
end
node_short = node_attr[:environments][:hostname].split(".")[0]
all << node_short
desc "Serverspec to all nodes"
@@ -35,11 +35,11 @@
TaskBase.get_node_recipes(node_file).each do |recipe|
recipes << recipe
end
rescue Exception => e
puts e.class.to_s + ", " + e.backtrace[0].to_s
- puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
+ puts "Node or role error, nodefile:#{node_file} reason:#{e.message}"
exit 1
else
recipes << {'_base' => 'default'}
recipes.flatten!
end
@@ -63,12 +63,16 @@
specs = "bundle exec rspec"
# recipe load to_spec
spec_pattern = []
recipes.each do |spec_h|
- spec_pattern <<
- " #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/#{spec_h["#{spec_h.keys.join}"]}_spec.rb").join("\s")}"
+ target_spec = "site-cookbooks/**/#{spec_h.keys.join}/spec/#{spec_h["#{spec_h.keys.join}"]}_spec.rb"
+ unless File.exists?("#{Dir.glob(target_spec).join}")
+ ex_recipe = spec_h.to_s.gsub('=>', '::').gsub('"', '')
+ raise "Spec load error, nodefile:#{node_file}, reason:Not exist the spec #{ex_recipe}"
+ end
+ spec_pattern << " #{Dir.glob(target_spec).join("\s")}"
end
spec_pattern.sort_by! {|item| File.dirname(item)}
specs << spec_pattern.join
run_list_noti = []
@@ -77,9 +81,10 @@
run_list_noti << c_spec.split("/")[2] + "::#{c_spec.split("/")[4].split(".")[0].split("_spec")[0]}"
else
run_list_noti << c_spec.split("/")[2]
end
}
+
puts TaskBase.hl.color(%!Run Serverspec to \"#{node_name}\"!, :red)
puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
st = system specs
exit 1 unless st
end