itamae-mitsurin 0.50 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/itamae-mitsurin/cli.rb +0 -2
- data/lib/itamae-mitsurin/logger.rb +74 -20
- data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
- data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
- data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
- data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
- data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
- data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
- data/lib/itamae-mitsurin/node.rb +0 -1
- data/lib/itamae-mitsurin/notification.rb +0 -1
- data/lib/itamae-mitsurin/recipe.rb +2 -5
- data/lib/itamae-mitsurin/resource.rb +1 -1
- data/lib/itamae-mitsurin/resource/base.rb +0 -12
- data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
- data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
- data/lib/itamae-mitsurin/runner.rb +4 -5
- data/lib/itamae-mitsurin/version.txt +1 -1
- metadata +6 -221
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
- data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
- data/test/test_itamae-mitsurin.rb +0 -18
- data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
- data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
- data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
- data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
- data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -33
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
- data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
- data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
- data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
- data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
- data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
- data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
- data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
- data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
- data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
- data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
- data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
- data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
- data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
- data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
- data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
- data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
- data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
- data/test/test_itamae-mitsurin/test_backend.rb +0 -297
- data/test/test_itamae-mitsurin/test_cli.rb +0 -88
- data/test/test_itamae-mitsurin/test_definition.rb +0 -40
- data/test/test_itamae-mitsurin/test_ext.rb +0 -1
- data/test/test_itamae-mitsurin/test_handler.rb +0 -21
- data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
- data/test/test_itamae-mitsurin/test_logger.rb +0 -124
- data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
- data/test/test_itamae-mitsurin/test_node.rb +0 -74
- data/test/test_itamae-mitsurin/test_notification.rb +0 -46
- data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
- data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
- data/test/test_itamae-mitsurin/test_resource.rb +0 -73
- data/test/test_itamae-mitsurin/test_runner.rb +0 -124
- data/test/test_itamae-mitsurin/test_version.rb +0 -3
- data/test/test_itamae-mitsurin/version.txt +0 -1
- data/test_project/.rspec +0 -2
- data/test_project/Gemfile +0 -4
- data/test_project/Rakefile +0 -3
- data/test_project/environments/.keep +0 -0
- data/test_project/keys/.keep +0 -0
- data/test_project/nodes/.keep +0 -0
- data/test_project/nodes/test.json +0 -9
- data/test_project/roles/.keep +0 -0
- data/test_project/roles/test.json +0 -14
- data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
- data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +0 -8
- data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
- data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/recipes/default.rb +0 -2
- data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
- data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
- data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
- data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
- data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +0 -1
- data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
- data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +0 -7
- data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/recipes/default.rb +0 -5
- data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
- data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
- data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +0 -6
- data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
- data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +0 -10
- data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +0 -20
- data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
- data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
- data/test_project/spec/spec_helper.rb +0 -33
- data/test_project/tmp-nodes/.keep +0 -0
- data/test_project/tmp-nodes/test.json +0 -12
@@ -1,106 +1,81 @@
|
|
1
|
-
require 'itamae-mitsurin/mitsurin/
|
2
|
-
include Rake::DSL if defined? Rake::DSL
|
1
|
+
require 'itamae-mitsurin/mitsurin/base_task'
|
3
2
|
|
4
|
-
module
|
3
|
+
module ItamaeMitsurin
|
5
4
|
module Mitsurin
|
6
|
-
class ServerspecTask
|
5
|
+
class ServerspecTask < BaseTask
|
6
|
+
LoadSpecError = Class.new(StandardError)
|
7
7
|
|
8
|
-
|
8
|
+
def list_recipe_filepath(run_list)
|
9
|
+
recipes = []
|
10
|
+
run_list.each do |recipe|
|
11
|
+
target_list = Dir.glob("site-cookbooks/**/#{recipe.keys.join}/spec/#{recipe.values.join}_spec.rb")
|
12
|
+
|
13
|
+
raise LoadSpecError, "#{recipe.to_a.join('::')} cookbook or spec does not exist." if target_list.empty?
|
14
|
+
|
15
|
+
target_list.each do |target|
|
16
|
+
recipes << " #{target}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
recipes
|
21
|
+
end
|
22
|
+
|
23
|
+
ItamaeMitsurin.logger.formatter.colored = true
|
24
|
+
task = ServerspecTask.new
|
9
25
|
|
10
26
|
namespace :spec do
|
11
27
|
all = []
|
12
|
-
Dir.glob("tmp-nodes/**/*.json").each do |node_file|
|
13
28
|
|
14
|
-
|
29
|
+
Dir.glob('nodes/**/*.json').each do |node_file|
|
15
30
|
begin
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
31
|
+
node_name = File.basename(node_file, '.json')
|
32
|
+
node = task.load_node_attributes(node_file)
|
33
|
+
node_short = node[:environments][:hostname].split('.')[0]
|
34
|
+
rescue => e
|
35
|
+
ItamaeMitsurin.logger.error e.inspect
|
36
|
+
ItamaeMitsurin.logger.info "From node file: #{node_file}"
|
37
|
+
exit 2
|
20
38
|
end
|
21
39
|
|
22
|
-
node_short = node_attr[:environments][:hostname].split(".")[0]
|
23
40
|
all << node_short
|
24
|
-
desc
|
25
|
-
task
|
26
|
-
|
27
|
-
desc "Spec to #{file_name}"
|
28
|
-
task node_attr[:environments][:hostname].split(".")[0] do
|
41
|
+
desc 'Serverspec to all nodes'
|
42
|
+
task 'all' => all
|
29
43
|
|
44
|
+
desc "Serverspec to #{node_name}"
|
45
|
+
task node_short do
|
30
46
|
begin
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
TaskBase.get_node_recipes(node_file).each do |recipe|
|
36
|
-
recipes << recipe
|
37
|
-
end
|
38
|
-
rescue Exception => e
|
39
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
40
|
-
puts "Node or role error, nodefile:#{node_file} reason:#{e.message}"
|
41
|
-
exit 1
|
42
|
-
else
|
43
|
-
recipes << {'_base' => 'default'}
|
44
|
-
recipes.flatten!
|
45
|
-
end
|
46
|
-
|
47
|
-
node_name = node_attr[:environments][:hostname]
|
48
|
-
ssh_user = node_attr[:environments][:ssh_user]
|
49
|
-
ssh_password = node_attr[:environments][:ssh_password]
|
50
|
-
sudo_password = node_attr[:environments][:sudo_password]
|
51
|
-
ssh_port = node_attr[:environments][:ssh_port]
|
52
|
-
ssh_key = node_attr[:environments][:ssh_key]
|
47
|
+
run_list = task.load_run_list(node_file)
|
48
|
+
environments = task.load_environments(node)
|
49
|
+
recipe_attributes_list = task.load_recipe_attributes(run_list)
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
ENV['SUDO_PASSWORD'] = sudo_password
|
59
|
-
ENV['SSH_KEY'] = "keys/#{ssh_key}"
|
60
|
-
ENV['SSH_PORT'] = ssh_port
|
61
|
-
ENV['SSH_USER'] = ssh_user
|
51
|
+
merged_recipe = task.merge_attributes(recipe_attributes_list)
|
52
|
+
merged_environments = task.merge_attributes(merged_recipe, environments)
|
53
|
+
attributes = task.merge_attributes(merged_environments, node)
|
54
|
+
task.create_tmp_nodes(node_name, attributes)
|
62
55
|
|
63
|
-
|
56
|
+
command = task.create_spec_command(node_name, attributes)
|
57
|
+
command_recipe = task.list_recipe_filepath(run_list)
|
58
|
+
command_recipe.sort_by! {|item| File.dirname(item) }
|
59
|
+
command << command_recipe.join
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
raise "Spec load error, nodefile: #{node_file}, reason: Does not exist " +
|
71
|
-
recipe_h.keys.join + '::' + recipe_h.values.join
|
72
|
-
end
|
73
|
-
Dir.glob(target_recipe).join("\s").split.each do |target|
|
74
|
-
unless File.exists?(target)
|
75
|
-
ex_recipe = recipe_h.to_s.gsub('=>', '::').gsub('"', '')
|
76
|
-
raise "Spec load error, nodefile: #{node_file}, reason: Does not exist #{ex_recipe}"
|
61
|
+
task.runner_display(attributes[:run_list], run_list, command)
|
62
|
+
st = system command
|
63
|
+
if st
|
64
|
+
ItamaeMitsurin.logger.color(:green) do
|
65
|
+
ItamaeMitsurin.logger.info 'serverspec_task is completed.'
|
77
66
|
end
|
78
|
-
command_recipe << " #{target}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
command_recipe.sort_by! {|item| File.dirname(item)}
|
83
|
-
command << command_recipe.join
|
84
|
-
|
85
|
-
puts TaskBase.hl.color(%!Run Serverspec to "#{bname}"!, :red)
|
86
|
-
run_list_noti = []
|
87
|
-
command_recipe.each { |c_recipe|
|
88
|
-
unless c_recipe.split('/')[4].split('.')[0] == 'default_spec'
|
89
|
-
subspec = c_recipe.split('/')[4].split('.')[0].split('_')[0..-2].join('_')
|
90
|
-
run_list_noti << c_recipe.split('/')[2] + "::#{subspec}"
|
91
67
|
else
|
92
|
-
|
68
|
+
ItamaeMitsurin.logger.error 'serverspec_task is failed.'
|
69
|
+
exit 1
|
93
70
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
exit 1 unless st
|
71
|
+
rescue => e
|
72
|
+
ItamaeMitsurin.logger.error e.inspect
|
73
|
+
ItamaeMitsurin.logger.info "From node file: #{node_file}"
|
74
|
+
exit 2
|
75
|
+
end
|
100
76
|
end
|
101
77
|
end
|
102
78
|
end
|
103
|
-
|
104
79
|
end
|
105
80
|
end
|
106
81
|
end
|
@@ -1,171 +1,108 @@
|
|
1
|
-
require 'itamae-mitsurin/mitsurin/
|
2
|
-
include Rake::DSL if defined? Rake::DSL
|
1
|
+
require 'itamae-mitsurin/mitsurin/base_task'
|
3
2
|
|
4
3
|
module ItamaeMitsurin
|
5
4
|
module Mitsurin
|
6
|
-
class ServerspecWithTargetTask
|
5
|
+
class ServerspecWithTargetTask < BaseTask
|
6
|
+
ChangeTargetError = Class.new(StandardError)
|
7
|
+
LoadSpecError = Class.new(StandardError)
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
puts TaskBase.hl.color "Changed target mode '#{ARGV[1]}'", :green
|
19
|
-
else
|
20
|
-
raise "Change mode error '#{ARGV[1]}' is not exists"
|
9
|
+
def list_recipe_filepath(run_list)
|
10
|
+
recipes = []
|
11
|
+
run_list.each do |recipe|
|
12
|
+
target_list = Dir.glob("site-cookbooks/**/#{recipe.keys.join}/spec/#{recipe.values.join}_spec.rb")
|
13
|
+
|
14
|
+
raise LoadSpecError, "#{recipe.to_a.join('::')} cookbook or spec does not exist." if target_list.empty?
|
15
|
+
|
16
|
+
target_list.each do |target|
|
17
|
+
recipes << " #{target}"
|
21
18
|
end
|
22
19
|
end
|
23
|
-
ret = JSON.parse(File.read("Project.json"))
|
24
|
-
target = ret["project"] << '/**'
|
25
20
|
|
26
|
-
|
27
|
-
|
21
|
+
recipes
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
rescue JSON::ParserError => e
|
32
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
33
|
-
puts "Node error, nodefile:#{node_file}, reason:#{e.message}"
|
34
|
-
end
|
24
|
+
ItamaeMitsurin.logger.formatter.colored = true
|
25
|
+
task = ServerspecWithTargetTask.new
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
desc "Serverspec to all nodes"
|
39
|
-
task :all => all
|
27
|
+
namespace :spec do
|
28
|
+
all = []
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
begin
|
44
|
-
recipes = []
|
45
|
-
TaskBase.get_roles(node_file).each do |role|
|
46
|
-
recipes << TaskBase.get_recipes(role)
|
47
|
-
end
|
48
|
-
TaskBase.get_node_recipes(node_file).each do |recipe|
|
49
|
-
recipes << recipe
|
50
|
-
end
|
51
|
-
rescue Exception => e
|
52
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
53
|
-
puts "Node or role error, nodefile:#{node_file}, reason:#{e.message}"
|
54
|
-
else
|
55
|
-
recipes.flatten!
|
56
|
-
end
|
30
|
+
begin
|
31
|
+
project = { project: ARGV[1] }
|
57
32
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
raise "No environments set error" if env_set.nil?
|
62
|
-
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
63
|
-
rescue Exception => e
|
64
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
65
|
-
puts "Node or environment error, nodefile:#{node_file}, reason:#{e.message}"
|
33
|
+
if (ARGV[0] == '-T' || ARGV[0] == '--tasks') && !project[:project].nil?
|
34
|
+
unless Dir.exist?("nodes/#{project[:project]}")
|
35
|
+
raise ChangeTargetError, "'#{project[:project]}' project is not exist."
|
66
36
|
end
|
67
37
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
recipe_attr_file.insert 0,
|
73
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
74
|
-
else
|
75
|
-
recipe_attr_file <<
|
76
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
77
|
-
end
|
38
|
+
File.open 'Project.json', 'w' do |f|
|
39
|
+
f.flock File::LOCK_EX
|
40
|
+
f.puts project.to_json
|
41
|
+
f.flock File::LOCK_UN
|
78
42
|
end
|
79
43
|
|
80
|
-
|
44
|
+
resp = JSON.parse(File.read('Project.json'))
|
45
|
+
target = resp['project'] << '/**'
|
81
46
|
|
82
|
-
|
83
|
-
|
84
|
-
recipe_attr_file.each do |file|
|
85
|
-
recipe_h = JSON.parse(File.read(file), symbolize_names: true)
|
86
|
-
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
87
|
-
end
|
88
|
-
|
89
|
-
# recipe attr other=recipes_env
|
90
|
-
moto = recipe_env_h_a[0]
|
91
|
-
recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
|
92
|
-
recipe_env_h = moto
|
93
|
-
|
94
|
-
if recipe_env_h.nil?
|
95
|
-
# env attr other=node
|
96
|
-
node_env_h = env_h.deep_merge(node_h)
|
97
|
-
node_env_j = TaskBase.jq node_env_h
|
98
|
-
TaskBase.write_json(bname) {|file| file.puts node_env_j}
|
99
|
-
else
|
100
|
-
# recipe_env attr other=node
|
101
|
-
recipe_env_node_h = recipe_env_h.deep_merge(node_h)
|
102
|
-
recipe_env_node_j = TaskBase.jq recipe_env_node_h
|
103
|
-
TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
|
47
|
+
ItamaeMitsurin.logger.color(:green) do
|
48
|
+
ItamaeMitsurin.logger.info "Changed target mode '#{project[:project]}'"
|
104
49
|
end
|
50
|
+
end
|
51
|
+
rescue => e
|
52
|
+
ItamaeMitsurin.logger.error e.inspect
|
53
|
+
exit 2
|
54
|
+
end
|
105
55
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
if local_ipv4.nil?
|
117
|
-
ENV['TARGET_HOST'] = node
|
118
|
-
else
|
119
|
-
ENV['TARGET_HOST'] = local_ipv4
|
120
|
-
end
|
121
|
-
ENV['NODE_FILE'] = "tmp-nodes/#{File.basename(node_file)}"
|
122
|
-
ENV['SSH_PASSWORD'] = ssh_password
|
123
|
-
ENV['SUDO_PASSWORD'] = sudo_password
|
124
|
-
ENV['SSH_KEY'] = "keys/#{ssh_key}"
|
125
|
-
ENV['SSH_PORT'] = ssh_port
|
126
|
-
ENV['SSH_USER'] = ssh_user
|
127
|
-
|
128
|
-
command = "bundle exec rspec"
|
129
|
-
|
130
|
-
# Pass to read the spec command
|
131
|
-
command_recipe = []
|
132
|
-
recipes.each do |recipe_h|
|
133
|
-
target_recipe = "site-cookbooks/**/#{recipe_h.keys.join}/spec/#{recipe_h[recipe_h.keys.join]}_spec.rb"
|
134
|
-
if Dir.glob(target_recipe).empty?
|
135
|
-
raise "Spec load error, nodefile: #{node_file}, reason: Does not exist " +
|
136
|
-
recipe_h.keys.join + '::' + recipe_h.values.join
|
137
|
-
end
|
138
|
-
Dir.glob(target_recipe).join("\s").split.each do |target|
|
139
|
-
unless File.exists?(target)
|
140
|
-
ex_recipe = recipe_h.to_s.gsub('=>', '::').gsub('"', '')
|
141
|
-
raise "Spec load error, nodefile: #{node_file}, reason: Does not exist #{ex_recipe}"
|
142
|
-
end
|
143
|
-
command_recipe << " #{target}"
|
144
|
-
end
|
145
|
-
end
|
56
|
+
Dir.glob("nodes/#{target}/*.json").each do |node_file|
|
57
|
+
begin
|
58
|
+
node_name = File.basename(node_file, '.json')
|
59
|
+
node = task.load_node_attributes(node_file)
|
60
|
+
node_short = node[:environments][:hostname].split('.')[0]
|
61
|
+
rescue => e
|
62
|
+
ItamaeMitsurin.logger.error e.inspect
|
63
|
+
ItamaeMitsurin.logger.info "From node file: #{node_file}"
|
64
|
+
exit 2
|
65
|
+
end
|
146
66
|
|
147
|
-
|
148
|
-
|
67
|
+
all << node_short
|
68
|
+
desc 'Serverspec to all nodes'
|
69
|
+
task 'all' => all
|
149
70
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
71
|
+
desc "Serverspec to #{node_name}"
|
72
|
+
task node_short do
|
73
|
+
begin
|
74
|
+
run_list = task.load_run_list(node_file)
|
75
|
+
environments = task.load_environments(node)
|
76
|
+
recipe_attributes_list = task.load_recipe_attributes(run_list)
|
77
|
+
|
78
|
+
merged_recipe = task.merge_attributes(recipe_attributes_list)
|
79
|
+
merged_environments = task.merge_attributes(merged_recipe, environments)
|
80
|
+
attributes = task.merge_attributes(merged_environments, node)
|
81
|
+
task.create_tmp_nodes(node_name, attributes)
|
82
|
+
|
83
|
+
command = task.create_spec_command(node_name, attributes)
|
84
|
+
command_recipe = task.list_recipe_filepath(run_list)
|
85
|
+
command_recipe.sort_by! {|item| File.dirname(item) }
|
86
|
+
command << command_recipe.join
|
87
|
+
|
88
|
+
task.runner_display(attributes[:run_list], run_list, command)
|
89
|
+
st = system command
|
90
|
+
if st
|
91
|
+
ItamaeMitsurin.logger.color(:green) do
|
92
|
+
ItamaeMitsurin.logger.info 'serverspec_with_target_task is completed.'
|
93
|
+
end
|
156
94
|
else
|
157
|
-
|
95
|
+
ItamaeMitsurin.logger.error 'serverspec_with_target_task is failed.'
|
96
|
+
exit 1
|
158
97
|
end
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
exit 1 unless st
|
98
|
+
rescue => e
|
99
|
+
ItamaeMitsurin.logger.error e.inspect
|
100
|
+
ItamaeMitsurin.logger.info "From node file: #{node_file}"
|
101
|
+
exit 2
|
102
|
+
end
|
165
103
|
end
|
166
104
|
end
|
167
105
|
end
|
168
|
-
|
169
106
|
end
|
170
107
|
end
|
171
108
|
end
|
data/lib/itamae-mitsurin/node.rb
CHANGED
@@ -35,7 +35,6 @@ module ItamaeMitsurin
|
|
35
35
|
unless errors.empty?
|
36
36
|
errors.each do |error|
|
37
37
|
ItamaeMitsurin.logger.error "'#{error.position.join('->')}' #{error.message}"
|
38
|
-
ItamaeMitsurin.file_logger.error "'#{error.position.join('->')}' #{error.message}"
|
39
38
|
end
|
40
39
|
raise ValidationError
|
41
40
|
end
|
@@ -33,7 +33,6 @@ module ItamaeMitsurin
|
|
33
33
|
def validate!
|
34
34
|
unless [:delay, :delayed, :immediately].include?(timing)
|
35
35
|
ItamaeMitsurin.logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
|
36
|
-
ItamaeMitsurin.file_logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
|
37
36
|
abort
|
38
37
|
end
|
39
38
|
end
|
@@ -63,10 +63,8 @@ module ItamaeMitsurin
|
|
63
63
|
|
64
64
|
@runner.handler.event(:recipe, path: @path) do
|
65
65
|
ItamaeMitsurin.logger.with_indent do
|
66
|
-
|
67
|
-
|
68
|
-
run_delayed_notifications
|
69
|
-
end
|
66
|
+
@children.run
|
67
|
+
run_delayed_notifications
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -85,7 +83,6 @@ module ItamaeMitsurin
|
|
85
83
|
|
86
84
|
def show_banner
|
87
85
|
ItamaeMitsurin.logger.info "Recipe: #{@path}"
|
88
|
-
ItamaeMitsurin.file_logger.info "Recipe: #{@path}"
|
89
86
|
end
|
90
87
|
|
91
88
|
class EvalContext
|