brpm_content_framework 0.2.1 → 0.2.3
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/infrastructure/test_separate_process.rb +3 -0
- data/lib/brpm_auto.rb +14 -1
- data/lib/brpm_script_executor.rb +44 -41
- data/tests/brpm_script_executor_spec.rb +36 -5
- data/tests/spec_helper.rb +2 -17
- data/tests_no_bundler/spec_helper.rb +28 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTliYTJlZTEwMWZjYjZhZWUxYTk0NmQ3MDMzODY5ZmMxODdiNjY4Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzdjYTA4ZWYxZWUyODQ1N2FjYzNiZDVjZjkxNDZlNWJiYjgyNWNjMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzhmNGUxYzI0OGZiNGNmMTEzMjdjNjZhYWQwZWY0YjE2YmFjM2NmOTI4Y2Fl
|
10
|
+
ZTUwMTczMGU3MGMzMjQ3ZThiODBiNzdiMjQ3NjNjYzFlMTU0Y2RjNzc2MDE5
|
11
|
+
ZjI2OGY5ZTYxZDUzZmQyNWM3MDQwOTljMjM0OWU2NjlhYmU0ZGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDY1MWQwYTRkZDBmNGU0NTUzYTQyNGNlNjExMjg5YjY0NzA2MzZkYWMzNmMw
|
14
|
+
MzJlNzMzNWIwNDVjODdlNTE0NmUxMmE3Y2RmMzA3ZGJlMTcxMjdkZmRhNzcx
|
15
|
+
NjdjNjkwNzQ2ZGNhYTMxNGEyMmJlZTYzZjk5NjU5YTRjYTY2NzY=
|
data/config.yml
CHANGED
data/lib/brpm_auto.rb
CHANGED
@@ -31,6 +31,7 @@ class BrpmAuto
|
|
31
31
|
@version = @config["version"]
|
32
32
|
|
33
33
|
@brpm_version = get_brpm_version if self.brpm_installed?
|
34
|
+
@gems_root_path = get_gems_root_path
|
34
35
|
end
|
35
36
|
|
36
37
|
def setup(params = {})
|
@@ -173,7 +174,7 @@ class BrpmAuto
|
|
173
174
|
end
|
174
175
|
|
175
176
|
def get_module_gem_path(module_name, module_version)
|
176
|
-
"#{
|
177
|
+
"#{@gems_root_path}/gems/#{module_name}-#{module_version}"
|
177
178
|
end
|
178
179
|
|
179
180
|
def get_latest_installed_version(module_name)
|
@@ -228,6 +229,18 @@ class BrpmAuto
|
|
228
229
|
end
|
229
230
|
end
|
230
231
|
|
232
|
+
def get_gems_root_path
|
233
|
+
if ENV["BRPM_CONTENT_HOME"]
|
234
|
+
ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
|
235
|
+
elsif ENV["BRPM_HOME"]
|
236
|
+
"#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed
|
237
|
+
elsif ENV["GEM_HOME"]
|
238
|
+
ENV["GEM_HOME"] # default gemset location when BRPM is not installed
|
239
|
+
else
|
240
|
+
raise "Unable to find out the gems root path."
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
231
244
|
def get_config
|
232
245
|
YAML.load_file("#{@framework_root_path}/config.yml")
|
233
246
|
end
|
data/lib/brpm_script_executor.rb
CHANGED
@@ -16,11 +16,45 @@ class BrpmScriptExecutor
|
|
16
16
|
file.puts(params.to_yaml)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
env_vars = {}
|
20
|
+
env_vars["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
|
21
|
+
|
22
|
+
BrpmAuto.log "Finding the module path..."
|
23
|
+
module_version = params["module_version"] || BrpmAuto.get_latest_installed_version(modul)
|
24
|
+
module_path = BrpmAuto.get_module_gem_path(modul, module_version)
|
25
|
+
|
26
|
+
if File.exists?(module_path)
|
27
|
+
BrpmAuto.log "Found module #{modul} #{module_version || ""} in path #{module_path}."
|
28
|
+
else
|
29
|
+
raise Gem::GemNotFoundException, "Module #{modul} version #{module_version} is not installed. Expected it on path #{module_path}."
|
30
|
+
end
|
31
|
+
|
32
|
+
require_statements = ""
|
33
|
+
gemfile_path = "#{module_path}/Gemfile"
|
34
|
+
unless File.exists?(gemfile_path)
|
35
|
+
BrpmAuto.log_error("This module doesn't have a Gemfile. Expected it at #{gemfile_path}.")
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
BrpmAuto.log "Found a Gemfile (#{gemfile_path}) so the automation script will have to run inside bundler."
|
40
|
+
env_vars["BUNDLE_GEMFILE"] = gemfile_path
|
41
|
+
require_statements += "require 'bundler/setup'; "
|
42
|
+
# TODO Bundler.require
|
43
|
+
|
44
|
+
BrpmAuto.log "Executing automation script '#{name}' from module '#{modul}' in a separate process..."
|
45
|
+
result = Bundler.clean_system(env_vars, RbConfig.ruby, "-e", "#{require_statements}; require 'brpm_script_executor'; BrpmScriptExecutor.execute_automation_script_from_other_process(\"#{modul}\", \"#{name}\", \"#{params_file}\")")
|
46
|
+
if result.nil?
|
47
|
+
BrpmAuto.log_error("The process that executed the automation script returned with 'Command execution failed'.")
|
48
|
+
elsif result == false
|
49
|
+
BrpmAuto.log_error("The process that executed the automation script returned with non-zero exit code: #{$?.exitstatus}")
|
50
|
+
end
|
51
|
+
|
52
|
+
result
|
21
53
|
end
|
22
54
|
|
23
55
|
def execute_automation_script_from_other_process(modul, name, params_file)
|
56
|
+
raise "Params file #{params_file} doesn't exist." unless File.exists?(params_file)
|
57
|
+
|
24
58
|
puts "Loading params file #{params_file}..."
|
25
59
|
params = YAML.load_file(params_file)
|
26
60
|
|
@@ -49,20 +83,20 @@ class BrpmScriptExecutor
|
|
49
83
|
BrpmAuto.log ">>>>>>>>>>>>>> START automation #{name}"
|
50
84
|
start_time = Time.now
|
51
85
|
|
52
|
-
original_brpm_version = BrpmAuto.version
|
53
|
-
|
54
|
-
BrpmAuto.log "Initializing module #{modul}#{params["module_version"] ? " #{params["module_version"]}" : ""} and its dependencies..."
|
55
86
|
module_version = params["module_version"] || BrpmAuto.get_latest_installed_version(modul)
|
56
|
-
module_path =
|
57
|
-
BrpmAuto.log "Finished loading the module."
|
87
|
+
module_path = BrpmAuto.get_module_gem_path(modul, module_version)
|
58
88
|
|
59
|
-
|
89
|
+
if File.exists?(module_path)
|
90
|
+
BrpmAuto.log "Found module #{modul} #{module_version || ""} in gem path #{module_path}."
|
91
|
+
else
|
92
|
+
raise Gem::GemNotFoundException, "Module #{modul} version #{module_version} is not installed. Expected it on path #{module_path}."
|
93
|
+
end
|
60
94
|
|
61
95
|
BrpmAuto.require_module(modul, module_version)
|
62
96
|
|
63
97
|
automation_script_path = "#{module_path}/automations/#{name}.rb"
|
64
98
|
|
65
|
-
BrpmAuto.log "
|
99
|
+
BrpmAuto.log "Executing the automation script #{automation_script_path}..."
|
66
100
|
load automation_script_path
|
67
101
|
|
68
102
|
rescue Exception => e
|
@@ -98,7 +132,7 @@ class BrpmScriptExecutor
|
|
98
132
|
|
99
133
|
automation_script_path = "#{module_path}/resource_automations/#{name}.rb"
|
100
134
|
|
101
|
-
BrpmAuto.log "
|
135
|
+
BrpmAuto.log "Executing the resource automation script #{automation_script_path}..."
|
102
136
|
load automation_script_path
|
103
137
|
|
104
138
|
BrpmAuto.log "Calling execute_resource_automation_script(params, parent_id, offset, max_records)..."
|
@@ -121,37 +155,6 @@ class BrpmScriptExecutor
|
|
121
155
|
end
|
122
156
|
|
123
157
|
alias_method :execute_resource_automation_script_from_gem, :execute_resource_automation_script
|
124
|
-
|
125
|
-
def get_ruby_cmd
|
126
|
-
@ruby ||= File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
127
|
-
end
|
128
|
-
|
129
|
-
# this method is used BEFORE BrpmAuto is activated so make sure not to use any logic from BrpmAuto in here
|
130
|
-
def initialize_module(module_name, module_version)
|
131
|
-
module_gem_path = BrpmAuto.get_module_gem_path(module_name, module_version)
|
132
|
-
|
133
|
-
if File.exists?(module_gem_path)
|
134
|
-
BrpmAuto.log "Found module #{module_name} #{module_version || ""} in gem path #{module_gem_path}."
|
135
|
-
else
|
136
|
-
raise Gem::GemNotFoundException, "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}."
|
137
|
-
end
|
138
|
-
|
139
|
-
gemfile_path = "#{module_gem_path}/Gemfile"
|
140
|
-
if File.exists?(gemfile_path)
|
141
|
-
BrpmAuto.log "Found a Gemfile (#{gemfile_path}) so activating bundler..."
|
142
|
-
ENV["BUNDLE_GEMFILE"] = gemfile_path
|
143
|
-
require "bundler/setup"
|
144
|
-
# TODO Bundler.require
|
145
|
-
|
146
|
-
params = BrpmAuto.params
|
147
|
-
|
148
|
-
BrpmAuto.log "Reloading brpm_auto to make sure the version that was specified by the Gemfile/Gemfile.lock of the module is active from now on..."
|
149
|
-
require "brpm_auto"
|
150
|
-
BrpmAuto.setup(params)
|
151
|
-
end
|
152
|
-
|
153
|
-
module_gem_path
|
154
|
-
end
|
155
158
|
end
|
156
159
|
end
|
157
160
|
|
@@ -8,19 +8,50 @@ describe 'BRPM Script Executor' do
|
|
8
8
|
require_relative "../lib/brpm_auto"
|
9
9
|
BrpmAuto.setup(get_default_params)
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
test_gems = Dir.glob("#{ENV["BRPM_HOME"]}/modules/gems/brpm_module_test*")
|
12
|
+
|
13
|
+
if test_gems.empty?
|
14
|
+
# watch out we are running inside bundler, known for messing up the gem configs
|
15
|
+
ENV["GEM_HOME"] = "#{ENV["BRPM_HOME"]}/modules"
|
16
|
+
Gem.paths = ENV
|
13
17
|
|
14
|
-
gem_installed = `gem list -i brpm_module_test`.chomp
|
15
|
-
if gem_installed != "true" # we are running inside bundler here so simplest to install the gem using a separate process
|
16
18
|
BrpmAuto.log "Installing brpm_module_test..."
|
17
|
-
|
19
|
+
specs = Gem.install("brpm_module_test")
|
20
|
+
spec = specs.find { |spec| spec.name == "brpm_module_test"}
|
21
|
+
BrpmAuto.log "Bundle install..."
|
22
|
+
`export GEM_HOME=#{ENV["GEM_HOME"]}; export BUNDLE_GEMFILE=#{spec.gem_dir}/Gemfile; bundle install`
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
26
|
+
it "should execute an automation script in-process" do
|
27
|
+
result = BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby", get_default_params)
|
28
|
+
|
29
|
+
expect(result).to be_truthy
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return false when executing an non-existing automation script in-process" do
|
33
|
+
expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "xxx", get_default_params)}.to raise_exception
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return false when executing an erroneous automation script in-process" do
|
37
|
+
expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby_raises_error", get_default_params)}.to raise_exception
|
38
|
+
end
|
39
|
+
|
21
40
|
it "should execute an automation script in a separate process" do
|
22
41
|
result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby", get_default_params)
|
23
42
|
|
24
43
|
expect(result).to be_truthy
|
25
44
|
end
|
45
|
+
|
46
|
+
it "should return false when executing an non-existing automation script in a separate process" do
|
47
|
+
result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "xxx", get_default_params)
|
48
|
+
|
49
|
+
expect(result).to be_falsey
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return false when executing an erroneous automation script in a separate process" do
|
53
|
+
result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby_raises_error", get_default_params)
|
54
|
+
|
55
|
+
expect(result).to be_falsey
|
56
|
+
end
|
26
57
|
end
|
data/tests/spec_helper.rb
CHANGED
@@ -3,10 +3,10 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
FileUtils.mkdir_p "/tmp/brpm_content"
|
6
|
+
raise "$BRPM_STUB_HOME is not set" unless ENV["BRPM_STUB_HOME"]
|
7
|
+
ENV["BRPM_HOME"] = ENV["BRPM_STUB_HOME"]
|
6
8
|
|
7
9
|
def setup_brpm_env
|
8
|
-
raise "$BRPM_STUB_HOME is not set" unless ENV["BRPM_STUB_HOME"]
|
9
|
-
ENV["BRPM_HOME"] = ENV["BRPM_STUB_HOME"]
|
10
10
|
end
|
11
11
|
|
12
12
|
def setup_brpm_auto
|
@@ -53,18 +53,3 @@ def decrypt_string_with_prefix(input) # mocked method
|
|
53
53
|
|
54
54
|
input.gsub("_encrypted", "")
|
55
55
|
end
|
56
|
-
|
57
|
-
def create_brpm_file
|
58
|
-
if File.exists?("~/.brpm")
|
59
|
-
FileUtils.rm("~/.brpm")
|
60
|
-
end
|
61
|
-
|
62
|
-
params = get_default_params
|
63
|
-
brpm_params = {}
|
64
|
-
brpm_params["brpm_url"] = params["brpm_url"]
|
65
|
-
brpm_params["brpm_api_token"] = params["brpm_api_token"]
|
66
|
-
|
67
|
-
File.open(File.expand_path("~/.brpm"), "w") do |file|
|
68
|
-
file.puts(brpm_params.to_yaml)
|
69
|
-
end
|
70
|
-
end
|
@@ -36,8 +36,36 @@ EOR
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def get_default_params
|
40
|
+
params = {}
|
41
|
+
params['unit_test'] = 'true'
|
42
|
+
params['also_log_to_console'] = 'true'
|
43
|
+
|
44
|
+
params['brpm_url'] = 'http://brpm-content.pulsar-it.be:8088/brpm'
|
45
|
+
params['brpm_api_token'] = ENV["BRPM_API_TOKEN"]
|
46
|
+
|
47
|
+
params['output_dir'] = "/tmp/brpm_content"
|
48
|
+
|
49
|
+
params
|
50
|
+
end
|
51
|
+
|
39
52
|
def setup_brpm_auto
|
40
53
|
require_relative "../lib/brpm_auto" #require_relative because we can't run inside bundler, we can't run inside bundler because we need the brpm_module_test which is not included in the brpm_content_framework Gemfile
|
41
54
|
BrpmAuto.setup(get_default_params)
|
42
55
|
end
|
43
56
|
|
57
|
+
def create_brpm_file
|
58
|
+
if File.exists?("~/.brpm")
|
59
|
+
FileUtils.rm("~/.brpm")
|
60
|
+
end
|
61
|
+
|
62
|
+
params = get_default_params
|
63
|
+
brpm_params = {}
|
64
|
+
brpm_params["brpm_url"] = params["brpm_url"]
|
65
|
+
brpm_params["brpm_api_token"] = params["brpm_api_token"]
|
66
|
+
|
67
|
+
File.open(File.expand_path("~/.brpm"), "w") do |file|
|
68
|
+
file.puts(brpm_params.to_yaml)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
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.3
|
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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- infrastructure/silent_install_options_4.6.txt
|
153
153
|
- infrastructure/silent_install_options_upgrade_4.6.txt
|
154
154
|
- infrastructure/smtp_settings.rb
|
155
|
+
- infrastructure/test_separate_process.rb
|
155
156
|
- lib/brpm_auto.rb
|
156
157
|
- lib/brpm_script_executor.rb
|
157
158
|
- lib/logging/brpm_logger.rb
|