brpm_content_framework 0.2.15 → 0.2.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/config.yml +1 -1
- data/infrastructure/test_separate_process.rb +1 -1
- data/lib/brpm_script_executor.rb +52 -38
- data/tests/brpm_script_executor_spec.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTQxMzQ5YmYwOTQ2NDBiNWNkYTFlOTdlZTVjYWM1ODY0YzZlY2MxZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjlmYmI0YjI5ZjAyZGU0NzUyZGY2MjAyNWM3ZmRkOTAzMzBmZGZmZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTEzMjE0Mjk1MjdmMGU5YzlhZDU4ZWFiNTFlNDc2MDJiNDU1NTVkZTcwZDU4
|
10
|
+
MzE5YTg1NmM5NWY2NTg0Y2E4OWZjOGRkMTMxYzIwYWE3ZjUyYjMwN2ViOGYz
|
11
|
+
N2UyMzI0OGE3Nzc1NjQ4ODEwZWM3NzMwYjZlNzE5OGNkOGJkMzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDFkOWViMzY2ZWU2NzZlMGJlNmE1ODIzZWQyOTljMjA3ZGEzYjFhNjAxZmUx
|
14
|
+
ZjE2NDkxNzk1MzQxYjYxZDZlYzUyZWY4NGNkODBjODI4ZWM5MjgyNGNhNjk3
|
15
|
+
MThmMmFiMWJmNGVmM2RhZjZkMjAyMTViMTYyNGYwOWIyMDBmYzk=
|
data/config.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'brpm_script_executor'
|
3
3
|
puts `bundle show`
|
4
|
-
BrpmScriptExecutor.execute_automation_script_from_other_process('brpm_module_test', '
|
4
|
+
BrpmScriptExecutor.execute_automation_script_from_other_process('brpm_module_test', 'test_resource', '/private/tmp/brpm_content/params_000.yml', "resource_automation")
|
data/lib/brpm_script_executor.rb
CHANGED
@@ -6,14 +6,6 @@ class BrpmScriptExecutor
|
|
6
6
|
private_class_method :new
|
7
7
|
|
8
8
|
class << self
|
9
|
-
def execute_automation_script(modul, name, params)
|
10
|
-
execute_automation_script_internal(modul, name, params, "automation")
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute_resource_automation_script(modul, name, params, parent_id, offset, max_records)
|
14
|
-
execute_automation_script_internal(modul, name, params, "resource_automation", parent_id, offset, max_records)
|
15
|
-
end
|
16
|
-
|
17
9
|
def execute_automation_script_in_separate_process(modul, name, params)
|
18
10
|
execute_automation_script_in_separate_process_internal(modul, name, params, "automation")
|
19
11
|
end
|
@@ -22,33 +14,12 @@ class BrpmScriptExecutor
|
|
22
14
|
execute_automation_script_in_separate_process_internal(modul, name, params, "resource_automation", parent_id, offset, max_records)
|
23
15
|
end
|
24
16
|
|
25
|
-
def execute_automation_script_from_other_process(modul, name, params_file, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
26
|
-
raise "Params file #{params_file} doesn't exist." unless File.exists?(params_file)
|
27
|
-
|
28
|
-
puts "Loading params file #{params_file}..."
|
29
|
-
params = YAML.load_file(params_file)
|
30
|
-
|
31
|
-
puts "Loading the BRPM Content framework..."
|
32
|
-
BrpmAuto.setup(params)
|
33
|
-
BrpmAuto.log "The BRPM Content framework is loaded now. (version: #{BrpmAuto.version})"
|
34
|
-
|
35
|
-
BrpmAuto.log "Deleting params file #{params_file}..."
|
36
|
-
FileUtils.rm(params_file)
|
37
|
-
|
38
|
-
if BrpmAuto.params["SS_run_key"] and BrpmAuto.params["SS_script_support_path"]
|
39
|
-
puts "Loading the BRPM core framework's libraries..."
|
40
|
-
load File.expand_path("#{File.dirname(__FILE__)}/../infrastructure/create_output_file.rb")
|
41
|
-
end
|
42
|
-
|
43
|
-
execute_automation_script_internal(modul, name, params, automation_type, parent_id, offset, max_records)
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
17
|
def execute_automation_script_in_separate_process_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
49
18
|
BrpmAuto.setup(params)
|
50
19
|
|
51
|
-
|
20
|
+
working_path = File.expand_path(params["SS_output_dir"] || params["output_dir"] || Dir.pwd)
|
21
|
+
|
22
|
+
params_file = "#{working_path}/params_#{params["SS_run_key"] || params["run_key"] || "000"}.yml"
|
52
23
|
|
53
24
|
BrpmAuto.log "Creating params file #{params_file}..."
|
54
25
|
File.open(params_file, "w") do |file|
|
@@ -75,7 +46,6 @@ class BrpmScriptExecutor
|
|
75
46
|
raise Gem::GemNotFoundException, "Module #{modul} version #{module_version} is not installed. Expected it on path #{module_path}."
|
76
47
|
end
|
77
48
|
|
78
|
-
require_statements = ""
|
79
49
|
gemfile_path = "#{module_path}/Gemfile"
|
80
50
|
unless File.exists?(gemfile_path)
|
81
51
|
BrpmAuto.log_error("This module doesn't have a Gemfile. Expected it at #{gemfile_path}.")
|
@@ -84,21 +54,65 @@ class BrpmScriptExecutor
|
|
84
54
|
|
85
55
|
BrpmAuto.log "Using Gemfile #{gemfile_path}."
|
86
56
|
env_vars["BUNDLE_GEMFILE"] = gemfile_path
|
87
|
-
require_statements += "require 'bundler/setup'; "
|
88
57
|
|
89
58
|
BrpmAuto.log "Executing automation script '#{name}' from module '#{modul}' in a separate process..."
|
90
|
-
|
91
|
-
if
|
59
|
+
return_value = Bundler.clean_system(env_vars, RbConfig.ruby, "-e", "require 'bundler/setup'; require 'brpm_script_executor'; BrpmScriptExecutor.execute_automation_script_from_other_process(\"#{modul}\", \"#{name}\", \"#{params_file}\", \"#{automation_type}\", \"#{parent_id}\", \"#{offset}\", \"#{max_records}\")")
|
60
|
+
FileUtils.rm(params_file) if File.exists?(params_file)
|
61
|
+
if return_value.nil?
|
92
62
|
message = "The process that executed the automation script returned with 'Command execution failed'."
|
93
63
|
BrpmAuto.log_error message
|
94
64
|
raise message
|
95
|
-
elsif
|
65
|
+
elsif return_value == false
|
96
66
|
message = "The process that executed the automation script returned with non-zero exit code: #{$?.exitstatus}"
|
97
67
|
BrpmAuto.log_error message
|
98
68
|
raise message
|
99
69
|
end
|
100
70
|
|
101
|
-
|
71
|
+
if automation_type == "resource_automation"
|
72
|
+
result_file = "#{working_path}/result_#{$?.pid}.yml"
|
73
|
+
BrpmAuto.log "Returning the results from #{result_file}..."
|
74
|
+
result = YAML.load_file(result_file)
|
75
|
+
FileUtils.rm result_file
|
76
|
+
|
77
|
+
result
|
78
|
+
else
|
79
|
+
return_value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def execute_automation_script_from_other_process(modul, name, params_file, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
84
|
+
raise "Params file #{params_file} doesn't exist." unless File.exists?(params_file)
|
85
|
+
|
86
|
+
puts "Loading params file #{params_file}..."
|
87
|
+
params = YAML.load_file(params_file)
|
88
|
+
|
89
|
+
FileUtils.rm(params_file)
|
90
|
+
|
91
|
+
puts "Loading the BRPM Content framework..."
|
92
|
+
BrpmAuto.setup(params)
|
93
|
+
|
94
|
+
if BrpmAuto.params["SS_run_key"] and BrpmAuto.params["SS_script_support_path"]
|
95
|
+
puts "Loading the BRPM core framework's libraries..."
|
96
|
+
load File.expand_path("#{File.dirname(__FILE__)}/../infrastructure/create_output_file.rb")
|
97
|
+
end
|
98
|
+
|
99
|
+
result = execute_automation_script_internal(modul, name, params, automation_type, parent_id, offset, max_records)
|
100
|
+
if automation_type == "resource_automation"
|
101
|
+
result_file = "#{File.dirname(params_file)}/result_#{Process.pid}.yml"
|
102
|
+
BrpmAuto.log "Saving the results to #{result_file}..."
|
103
|
+
FileUtils.rm(result_file) if File.exists?(result_file)
|
104
|
+
File.open(result_file, "w") do |file|
|
105
|
+
file.puts(result.to_yaml)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def execute_automation_script(modul, name, params)
|
111
|
+
execute_automation_script_internal(modul, name, params, "automation")
|
112
|
+
end
|
113
|
+
|
114
|
+
def execute_resource_automation_script(modul, name, params, parent_id, offset, max_records)
|
115
|
+
execute_automation_script_internal(modul, name, params, "resource_automation", parent_id, offset, max_records)
|
102
116
|
end
|
103
117
|
|
104
118
|
def execute_automation_script_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
@@ -36,14 +36,16 @@ describe 'BRPM Script Executor' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should return false when executing an non-existing automation script in a separate process" do
|
39
|
-
|
40
|
-
|
41
|
-
expect(result).to be_falsey
|
39
|
+
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "xxx", get_default_params)}.to raise_exception
|
42
40
|
end
|
43
41
|
|
44
42
|
it "should return false when executing an erroneous automation script in a separate process" do
|
45
|
-
|
43
|
+
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby_raises_error", get_default_params)}.to raise_exception
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should execute a resource automation script in a separate process" do
|
47
|
+
result = BrpmScriptExecutor.execute_resource_automation_script_in_separate_process("brpm_module_test", "test_resource", get_default_params, nil, 0, 10)
|
46
48
|
|
47
|
-
expect(result).to
|
49
|
+
expect(result.count).to eql(3)
|
48
50
|
end
|
49
51
|
end
|