brpm_content_framework 0.2.16 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/config.yml +1 -1
- data/lib/brpm_script_executor.rb +19 -20
- data/lib/module_installer.rb +8 -7
- data/tests/brpm_script_executor_spec.rb +25 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjViNDgwZmYyZjFiYWMxYmRhYzhlNWI4YjYyMzNiZDAxMTBmYjViZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjU2YWVlNWVmZDJlZjk0ZDFjNWFlMTZmMDNmYjExNDE3YTJiMDdlZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTY4NzNlOWQxNzFhOGYyNmY0M2E0OGE2NmE4MmExYWVhZGM3MjlmMjg4NTQz
|
10
|
+
NWI5ZDJlMDUwNDlmOWQ2NzBlYWE1ODFhYTZhYjFkZWU4NGJiMDdmNjliNjMx
|
11
|
+
Njc2NWZkZWZkNWRlYjk1YjMwZjEyMzdjNDZmODU2NzBiNDNiMzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzE1MTU5YmFlNmI5NTVkNTQwMjM5MTEwZWY4MjM4OTBkMjc3MjMxODYwN2Zh
|
14
|
+
ZGYwZWEwNTE4NGE4Mzg2M2JjMDAzYTJiM2Q3MjBjN2NiODczMmFiNDAyODQ5
|
15
|
+
Y2E5YTkzMGY2OGE1ZDAzNzI3YjJkNDZkNWI0MGU3MTRkYzdmYzE=
|
data/config.yml
CHANGED
data/lib/brpm_script_executor.rb
CHANGED
@@ -17,15 +17,6 @@ class BrpmScriptExecutor
|
|
17
17
|
def execute_automation_script_in_separate_process_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
18
18
|
BrpmAuto.setup(params)
|
19
19
|
|
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"
|
23
|
-
|
24
|
-
BrpmAuto.log "Creating params file #{params_file}..."
|
25
|
-
File.open(params_file, "w") do |file|
|
26
|
-
file.puts(params.to_yaml)
|
27
|
-
end
|
28
|
-
|
29
20
|
env_vars = {}
|
30
21
|
env_vars["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
|
31
22
|
|
@@ -47,16 +38,25 @@ class BrpmScriptExecutor
|
|
47
38
|
end
|
48
39
|
|
49
40
|
gemfile_path = "#{module_path}/Gemfile"
|
50
|
-
|
51
|
-
BrpmAuto.
|
52
|
-
|
41
|
+
if File.exists?(gemfile_path)
|
42
|
+
BrpmAuto.log "Using Gemfile #{gemfile_path}."
|
43
|
+
env_vars["BUNDLE_GEMFILE"] = gemfile_path
|
44
|
+
require_bundler = "require 'bundler/setup';"
|
45
|
+
else
|
46
|
+
BrpmAuto.log("This module doesn't have a Gemfile.")
|
47
|
+
require_bundler = ""
|
53
48
|
end
|
54
49
|
|
55
|
-
|
56
|
-
|
50
|
+
working_path = File.expand_path(params["SS_output_dir"] || params["output_dir"] || Dir.pwd)
|
51
|
+
params_file = "#{working_path}/params_#{params["SS_run_key"] || params["run_key"] || "000"}.yml"
|
52
|
+
|
53
|
+
BrpmAuto.log "Temporarily storing the params to #{params_file}..."
|
54
|
+
File.open(params_file, "w") do |file|
|
55
|
+
file.puts(params.to_yaml)
|
56
|
+
end
|
57
57
|
|
58
58
|
BrpmAuto.log "Executing automation script '#{name}' from module '#{modul}' in a separate process..."
|
59
|
-
return_value = Bundler.clean_system(env_vars, RbConfig.ruby, "-e", "require '
|
59
|
+
return_value = Bundler.clean_system(env_vars, RbConfig.ruby, "-e", "#{require_bundler}require 'brpm_script_executor'; BrpmScriptExecutor.execute_automation_script_from_other_process(\"#{modul}\", \"#{name}\", \"#{params_file}\", \"#{automation_type}\", \"#{parent_id}\", \"#{offset}\", \"#{max_records}\")")
|
60
60
|
FileUtils.rm(params_file) if File.exists?(params_file)
|
61
61
|
if return_value.nil?
|
62
62
|
message = "The process that executed the automation script returned with 'Command execution failed'."
|
@@ -70,7 +70,7 @@ class BrpmScriptExecutor
|
|
70
70
|
|
71
71
|
if automation_type == "resource_automation"
|
72
72
|
result_file = "#{working_path}/result_#{$?.pid}.yml"
|
73
|
-
BrpmAuto.log "
|
73
|
+
BrpmAuto.log "Loading the result from #{result_file} and cleaning it up..."
|
74
74
|
result = YAML.load_file(result_file)
|
75
75
|
FileUtils.rm result_file
|
76
76
|
|
@@ -83,12 +83,11 @@ class BrpmScriptExecutor
|
|
83
83
|
def execute_automation_script_from_other_process(modul, name, params_file, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
84
84
|
raise "Params file #{params_file} doesn't exist." unless File.exists?(params_file)
|
85
85
|
|
86
|
-
puts "Loading params
|
86
|
+
puts "Loading the params from #{params_file} and cleaning it up..."
|
87
87
|
params = YAML.load_file(params_file)
|
88
|
-
|
89
88
|
FileUtils.rm(params_file)
|
90
89
|
|
91
|
-
puts "
|
90
|
+
puts "Setting up the BRPM Content framework..."
|
92
91
|
BrpmAuto.setup(params)
|
93
92
|
|
94
93
|
if BrpmAuto.params["SS_run_key"] and BrpmAuto.params["SS_script_support_path"]
|
@@ -99,7 +98,7 @@ class BrpmScriptExecutor
|
|
99
98
|
result = execute_automation_script_internal(modul, name, params, automation_type, parent_id, offset, max_records)
|
100
99
|
if automation_type == "resource_automation"
|
101
100
|
result_file = "#{File.dirname(params_file)}/result_#{Process.pid}.yml"
|
102
|
-
BrpmAuto.log "
|
101
|
+
BrpmAuto.log "Temporarily storing the result to #{result_file}..."
|
103
102
|
FileUtils.rm(result_file) if File.exists?(result_file)
|
104
103
|
File.open(result_file, "w") do |file|
|
105
104
|
file.puts(result.to_yaml)
|
data/lib/module_installer.rb
CHANGED
@@ -152,14 +152,14 @@ class ModuleInstaller
|
|
152
152
|
def install_bundle(spec)
|
153
153
|
gemfile_path = File.join(spec.gem_dir, "Gemfile")
|
154
154
|
|
155
|
-
|
156
|
-
|
155
|
+
if File.exists?(gemfile_path)
|
156
|
+
command = "cd #{spec.gem_dir}; bundle install"
|
157
|
+
BrpmAuto.log "Found a Gemfile so executing command '#{command}'..."
|
158
|
+
result = BrpmAuto.execute_shell(command)
|
159
|
+
else
|
160
|
+
BrpmAuto.log "This module doesn't have a Gemfile."
|
157
161
|
end
|
158
162
|
|
159
|
-
command = "cd #{spec.gem_dir}; bundle install"
|
160
|
-
BrpmAuto.log "Found a Gemfile so executing command '#{command}'..."
|
161
|
-
result = BrpmAuto.execute_shell(command)
|
162
|
-
|
163
163
|
BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
|
164
164
|
unless result["status"] == 0
|
165
165
|
raise result["stderr"]
|
@@ -532,12 +532,12 @@ params["direct_execute"] = "true"
|
|
532
532
|
params["framework_version"] = nil if params["framework_version"].empty?
|
533
533
|
params["module_version"] = nil if params["module_version"].empty?
|
534
534
|
|
535
|
-
require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content_framework-\#{params["framework_version"] || "latest"}/lib/brpm_script_executor.rb"
|
536
535
|
EOR
|
537
536
|
|
538
537
|
if automation_type == "Automation"
|
539
538
|
|
540
539
|
template += <<EOR
|
540
|
+
require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content_framework-\#{params["framework_version"] || "latest"}/lib/brpm_script_executor.rb"
|
541
541
|
|
542
542
|
BrpmScriptExecutor.execute_automation_script_in_separate_process("#{module_name}", "#{auto_script_name}", params)
|
543
543
|
EOR
|
@@ -545,6 +545,7 @@ EOR
|
|
545
545
|
elsif automation_type == "ResourceAutomation"
|
546
546
|
|
547
547
|
template += <<EOR
|
548
|
+
load "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content_framework-\#{params["framework_version"] || "latest"}/lib/brpm_script_executor.rb"
|
548
549
|
|
549
550
|
def execute(script_params, parent_id, offset, max_records)
|
550
551
|
BrpmScriptExecutor.execute_resource_automation_script_in_separate_process("#{module_name}", "#{auto_script_name}", script_params, parent_id, offset, max_records)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "spec_helper"
|
2
|
+
require "fileutils"
|
2
3
|
|
3
4
|
describe 'BRPM Script Executor' do
|
4
5
|
before(:all) do
|
@@ -8,10 +9,12 @@ describe 'BRPM Script Executor' do
|
|
8
9
|
require_relative "../lib/brpm_auto"
|
9
10
|
BrpmAuto.setup(get_default_params)
|
10
11
|
|
11
|
-
|
12
|
+
@module_name = "brpm_module_test"
|
13
|
+
# We are running inside bundler and the brpm_module_test is not specified in it so don't use the Gem methods
|
14
|
+
test_gems = Dir.glob("#{ENV["BRPM_HOME"]}/modules/gems/#{@module_name}*")
|
12
15
|
|
13
16
|
if test_gems.empty?
|
14
|
-
# watch out we are running inside bundler, known for messing up the gem configs
|
17
|
+
# watch out we are running inside bundler, known for messing up the gem configs, so explicitly set the GEM_HOME env var
|
15
18
|
ENV["GEM_HOME"] = "#{ENV["BRPM_HOME"]}/modules"
|
16
19
|
Gem.paths = ENV
|
17
20
|
|
@@ -20,31 +23,45 @@ describe 'BRPM Script Executor' do
|
|
20
23
|
# result = Bundler.clean_system("export GEM_HOME=#{ENV["GEM_HOME"]} && cd .. && rake install")
|
21
24
|
# raise "rake install failed" unless result
|
22
25
|
|
23
|
-
BrpmAuto.log "Installing
|
26
|
+
BrpmAuto.log "Installing #{@module_name}..."
|
24
27
|
specs = Gem.install("brpm_module_test")
|
25
|
-
spec = specs.find { |spec| spec.name ==
|
28
|
+
spec = specs.find { |spec| spec.name == @module_name}
|
26
29
|
BrpmAuto.log "Bundle install..."
|
27
30
|
result = Bundler.clean_system("export GEM_HOME=#{ENV["GEM_HOME"]} && export BUNDLE_GEMFILE=#{spec.gem_dir}/Gemfile && bundle install")
|
28
31
|
raise "bundle install failed" unless result
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
# Note: the following tests will run the automation scripts in a separate process and will therefore use an already installed brpm_content_framework module,
|
36
|
+
# either the version from their Gemfile/Gemfile.lock or the latest, but not the one from source code
|
37
|
+
it "should execute an automation script in a separate process inside a bundler context" do
|
33
38
|
result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby", get_default_params)
|
34
39
|
|
35
40
|
expect(result).to be_truthy
|
36
41
|
end
|
37
42
|
|
43
|
+
it "should execute an automation script in a separate process outside a bundler context" do
|
44
|
+
module_version = BrpmScriptExecutor.get_latest_installed_version(@module_name)
|
45
|
+
module_gem_path = BrpmScriptExecutor.get_module_gem_path(@module_name, module_version)
|
46
|
+
gemfile_path = "#{module_gem_path}/Gemfile"
|
47
|
+
|
48
|
+
FileUtils.move(gemfile_path, "#{gemfile_path}_tmp")
|
49
|
+
result = BrpmScriptExecutor.execute_automation_script_in_separate_process(@module_name, "test_ruby", get_default_params)
|
50
|
+
FileUtils.move("#{gemfile_path}_tmp", gemfile_path)
|
51
|
+
|
52
|
+
expect(result).to be_truthy
|
53
|
+
end
|
54
|
+
|
38
55
|
it "should return false when executing an non-existing automation script in a separate process" do
|
39
|
-
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process(
|
56
|
+
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process(@module_name, "xxx", get_default_params)}.to raise_exception
|
40
57
|
end
|
41
58
|
|
42
59
|
it "should return false when executing an erroneous automation script in a separate process" do
|
43
|
-
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process(
|
60
|
+
expect{BrpmScriptExecutor.execute_automation_script_in_separate_process(@module_name, "test_ruby_raises_error", get_default_params)}.to raise_exception
|
44
61
|
end
|
45
62
|
|
46
63
|
it "should execute a resource automation script in a separate process" do
|
47
|
-
result = BrpmScriptExecutor.execute_resource_automation_script_in_separate_process(
|
64
|
+
result = BrpmScriptExecutor.execute_resource_automation_script_in_separate_process(@module_name, "test_resource", get_default_params, nil, 0, 10)
|
48
65
|
|
49
66
|
expect(result.count).to eql(3)
|
50
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brpm_content_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niek Bartholomeus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|