brpm_content_framework 0.1.61 → 0.2.1
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/.travis.yml +2 -1
- data/config.yml +1 -1
- data/infrastructure/module_template/Rakefile +0 -1
- data/lib/brpm_auto.rb +63 -193
- data/lib/brpm_script_executor.rb +81 -3
- data/lib/module_installer.rb +17 -42
- data/lib/write_to.rb +1 -1
- data/tests/all_params_spec.rb +1 -0
- data/tests/brpm_auto_spec.rb +1 -0
- data/tests/brpm_script_executor_spec.rb +26 -0
- data/tests/customer_include_spec.rb +1 -0
- data/tests/params_spec.rb +1 -0
- data/tests/request_params_spec.rb +1 -0
- data/tests/server_yaml_spec.rb +1 -0
- data/tests/spec_helper.rb +8 -1
- data/{tests → tests_no_bundler}/module_installer_spec.rb +4 -33
- data/tests_no_bundler/spec_helper.rb +43 -0
- data/to_be_migrated/brpm_framework.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTNmZjEwZDA2ZDQzMGNiNTVhMzU3YjI1NDNkYjAxMDkwNTM0YjliOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzEyZWQ0YzBlMjA0MDlkMzE3NjI0MDE5NjJiNWQ4YzRmYmQ0NDJiMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmIwZTI4NjFkYjJhYjc3N2FmZjBjY2E3NzVhYjQ4ZDY1ZjZmYjg4YjM2MzUz
|
10
|
+
MGFmM2MxMGVkODg3NTYxNTkwNzcyNzA3NTUxMjc1Yzc1MWZkY2Q5NWM4NThj
|
11
|
+
YzA1OWE1OGRhODIyMmFiMDRiMzIzMTZjMDBkNWQ3ZDE2YWQ3Y2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDY1MmQxZDE3MzQzNmQ0ZDI4NmVmYzhiYjllZWJhMGUyYjQ0M2RkOTJjMGI2
|
14
|
+
NzI0YjEzZTIwODY1MjYwZjg5NzIwYjg3YWFlYzA2MzhlOTJhNmUzMjMyOTRh
|
15
|
+
N2FkZWFiODM3ZDAxODQzYjI5MzBiZjYwOWRkNTNiYTU0NDAwMTE=
|
data/.travis.yml
CHANGED
data/config.yml
CHANGED
data/lib/brpm_auto.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "bundler"
|
2
1
|
require "yaml"
|
3
2
|
|
4
3
|
class BrpmAuto
|
@@ -31,9 +30,7 @@ class BrpmAuto
|
|
31
30
|
@config = get_config
|
32
31
|
@version = @config["version"]
|
33
32
|
|
34
|
-
@brpm_version = get_brpm_version if self.brpm_installed
|
35
|
-
|
36
|
-
@gems_root_path = get_gems_root_path
|
33
|
+
@brpm_version = get_brpm_version if self.brpm_installed?
|
37
34
|
end
|
38
35
|
|
39
36
|
def setup(params = {})
|
@@ -73,62 +70,6 @@ class BrpmAuto
|
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
|
-
def require_module(module_name, module_version = nil)
|
77
|
-
module_version ||= get_latest_installed_version(module_name)
|
78
|
-
module_gem_path = get_module_gem_path(module_name, module_version)
|
79
|
-
|
80
|
-
if File.exists?(module_gem_path)
|
81
|
-
BrpmAuto.log "Found module #{module_name} #{module_version || ""} in gem path #{module_gem_path}."
|
82
|
-
else
|
83
|
-
raise Gem::GemNotFoundException, "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}."
|
84
|
-
end
|
85
|
-
|
86
|
-
gemfile_lock_path = "#{module_gem_path}/Gemfile.lock"
|
87
|
-
if File.exists?(gemfile_lock_path) # TODO: decide how to react when multiple gems are 'required', each with a gemfile.lock
|
88
|
-
BrpmAuto.log "Found a Gemfile.lock: #{gemfile_lock_path} so parsing the specified version numbers for later usage..."
|
89
|
-
Dir.chdir(File.dirname(gemfile_lock_path)) do
|
90
|
-
@gemfile_lock = Bundler::LockfileParser.new(Bundler.read_file(gemfile_lock_path))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
require_module_internal(module_name, module_version)
|
95
|
-
end
|
96
|
-
|
97
|
-
def require_libs_no_file_logging(module_path)
|
98
|
-
require_libs(module_path, false)
|
99
|
-
end
|
100
|
-
|
101
|
-
def require_libs(module_path, log = true)
|
102
|
-
lib_path = "#{module_path}/lib/**/*.rb"
|
103
|
-
|
104
|
-
log_message = "Loading all files from #{lib_path}..."
|
105
|
-
log ? (BrpmAuto.log log_message) : (print "#{log_message}\n")
|
106
|
-
|
107
|
-
require_files(Dir[lib_path], log)
|
108
|
-
end
|
109
|
-
|
110
|
-
def require_files(files, log = true)
|
111
|
-
failed_files = []
|
112
|
-
error_messages = []
|
113
|
-
files.each do |file|
|
114
|
-
if File.file?(file)
|
115
|
-
begin
|
116
|
-
require file
|
117
|
-
rescue NameError => ne # when we require a set of files with inter-dependencies, the order is important, therefore we will retry the failed files later
|
118
|
-
failed_files << file
|
119
|
-
error_messages << ne
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
if failed_files.count > 0
|
124
|
-
if failed_files.count == files.count
|
125
|
-
raise NameError, "Following files failed loading: #{failed_files.join(", ")}\nError messages: #{error_messages.join(", ")}"
|
126
|
-
else
|
127
|
-
require_files(failed_files, log)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
73
|
def load_server_params
|
133
74
|
server_config_file_path = "#{self.params.config_dir}/server.yml"
|
134
75
|
if File.exists?(server_config_file_path)
|
@@ -184,110 +125,12 @@ class BrpmAuto
|
|
184
125
|
@integration_settings = IntegrationSettings.new(dns, username, password, details)
|
185
126
|
end
|
186
127
|
|
187
|
-
def brpm_installed
|
188
|
-
ENV["BRPM_HOME"]
|
189
|
-
end
|
190
|
-
|
191
|
-
def get_gems_root_path
|
192
|
-
if ENV["BRPM_CONTENT_HOME"]
|
193
|
-
ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
|
194
|
-
elsif ENV["BRPM_HOME"]
|
195
|
-
"#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed
|
196
|
-
elsif ENV["GEM_HOME"]
|
197
|
-
ENV["GEM_HOME"] # default gemset location when BRPM is not installed
|
198
|
-
else
|
199
|
-
raise "Unable to find out the gems root path."
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
###############################################################################################################################
|
204
|
-
# Assure backward compatibility with the ssh_script_header methods when running the automation scripts in a separate process
|
205
|
-
def set_property_flag(prop, value = nil)
|
206
|
-
acceptable_fields = ["name", "value", "environment", "component", "global", "private"]
|
207
|
-
flag = "#------ Block to Set Property ---------------#\n"
|
208
|
-
if value.nil?
|
209
|
-
flag += set_build_flag_data("properties", prop, acceptable_fields)
|
210
|
-
else
|
211
|
-
flag += "$$SS_Set_property{#{prop}=>#{value}}$$"
|
212
|
-
end
|
213
|
-
flag += "\n#------- End Set Property ---------------#\n"
|
214
|
-
BrpmAuto.log flag
|
215
|
-
flag
|
216
|
-
end
|
217
|
-
|
218
|
-
def set_server_flag(servers)
|
219
|
-
# servers = "server_name, env\ncserver2_name, env2"
|
220
|
-
acceptable_fields = ["name", "environment", "group"]
|
221
|
-
flag = "#------ Block to Set Servers ---------------#\n"
|
222
|
-
flag += set_build_flag_data("servers", servers, acceptable_fields)
|
223
|
-
flag += "\n#------ End Set Servers ---------------#\n"
|
224
|
-
BrpmAuto.log flag
|
225
|
-
flag
|
226
|
-
end
|
227
|
-
|
228
|
-
def set_component_flag(components)
|
229
|
-
# comps = "comp_name, version\ncomp2_name, version2"
|
230
|
-
flag = "#------ Block to Set Components ---------------#\n"
|
231
|
-
acceptable_fields = ["name", "version", "environment", "application"]
|
232
|
-
flag += set_build_flag_data("components", components, acceptable_fields)
|
233
|
-
flag += "\n#------ End Set Components ---------------#\n"
|
234
|
-
BrpmAuto.log flag
|
235
|
-
flag
|
236
|
-
end
|
237
|
-
|
238
|
-
def set_titles_acceptable?(cur_titles, acceptable_titles)
|
239
|
-
cur_titles.each.reject{ |cur| acceptable_titles.include?(cur)}.count == 0
|
240
|
-
end
|
241
|
-
|
242
|
-
def set_build_flag_data(set_item, set_data, acceptable_titles)
|
243
|
-
flag = ""; msg = ""
|
244
|
-
lines = set_data.split("\n")
|
245
|
-
titles = lines[0].split(",").map{ |it| it.strip }
|
246
|
-
if set_titles_acceptable?(titles, acceptable_titles)
|
247
|
-
flag += "$$SS_Set_#{set_item}{\n"
|
248
|
-
flag += "#{titles.join(", ")}\n"
|
249
|
-
lines[1..-1].each do |line|
|
250
|
-
if line.split(",").count == titles.count
|
251
|
-
flag += "#{line}\n"
|
252
|
-
else
|
253
|
-
msg += "Skipped: #{line}"
|
254
|
-
end
|
255
|
-
end
|
256
|
-
flag += "}$$\n"
|
257
|
-
else
|
258
|
-
flag += "ERROR - Unable to set #{set_item} - improper format\n"
|
259
|
-
end
|
260
|
-
flag += msg
|
128
|
+
def brpm_installed?
|
129
|
+
ENV["BRPM_HOME"] and !ENV["BRPM_HOME"].empty?
|
261
130
|
end
|
262
131
|
|
263
|
-
def
|
264
|
-
|
265
|
-
flag = "#------ Block to Set Application Version ---------------#\n"
|
266
|
-
flag += "$$SS_Set_application{#{prop}=>#{value}}$$"
|
267
|
-
flag += "\n#------ End Set Application ---------------#\n"
|
268
|
-
BrpmAuto.log(flag)
|
269
|
-
flag
|
270
|
-
end
|
271
|
-
|
272
|
-
def pack_response(argument_name, response)
|
273
|
-
flag = "#------ Block to Set Pack Response ---------------#\n"
|
274
|
-
unless argument_name.nil?
|
275
|
-
if response.is_a?(Hash)
|
276
|
-
# Used for out-table output parameter
|
277
|
-
flag += "$$SS_Pack_Response{#{argument_name}@@#{response.to_json}}$$"
|
278
|
-
else
|
279
|
-
flag += "$$SS_Pack_Response{#{argument_name}=>#{response}}$$"
|
280
|
-
end
|
281
|
-
end
|
282
|
-
flag += "\n#------- End Set Pack Response Block ---------------#\n"
|
283
|
-
BrpmAuto.log flag
|
284
|
-
flag
|
285
|
-
end
|
286
|
-
###############################################################################################################################
|
287
|
-
|
288
|
-
private
|
289
|
-
|
290
|
-
def require_module_internal(module_name, module_version)
|
132
|
+
def require_module(module_name, module_version = nil)
|
133
|
+
module_version ||= get_latest_installed_version(module_name)
|
291
134
|
module_path = get_module_gem_path(module_name, module_version)
|
292
135
|
|
293
136
|
module_config_file_path = "#{module_path}/config.yml"
|
@@ -316,7 +159,7 @@ class BrpmAuto
|
|
316
159
|
end
|
317
160
|
|
318
161
|
BrpmAuto.log "Loading module #{dep_module_name} version #{dep_module_version}..."
|
319
|
-
|
162
|
+
require_module(dep_module_name, dep_module_version)
|
320
163
|
end
|
321
164
|
end
|
322
165
|
else
|
@@ -329,54 +172,81 @@ class BrpmAuto
|
|
329
172
|
module_path
|
330
173
|
end
|
331
174
|
|
332
|
-
def get_config
|
333
|
-
YAML.load_file("#{@framework_root_path}/config.yml")
|
334
|
-
end
|
335
|
-
|
336
|
-
def get_brpm_version
|
337
|
-
unless self.params.brpm_installed
|
338
|
-
raise "BRPM is not installed."
|
339
|
-
end
|
340
|
-
|
341
|
-
knob_file = "#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml"
|
342
|
-
unless File.exists?(knob_file)
|
343
|
-
raise "Could not find the knob file at the expected location (#{knob_file})"
|
344
|
-
end
|
345
|
-
|
346
|
-
knob = YAML.load_file(knob_file)
|
347
|
-
version_content = File.read("#{knob["application"]["root"]}/VERSION")
|
348
|
-
version_content.scan(/VERSION=([0-9\.]*)/)[0][0]
|
349
|
-
end
|
350
|
-
|
351
175
|
def get_module_gem_path(module_name, module_version)
|
352
|
-
"#{
|
176
|
+
"#{ENV["GEM_HOME"]}/gems/#{module_name}-#{module_version}"
|
353
177
|
end
|
354
178
|
|
355
179
|
def get_latest_installed_version(module_name)
|
356
180
|
latest_version_path = get_module_gem_path(module_name, "latest")
|
357
181
|
return "latest" if File.exists?(latest_version_path)
|
358
182
|
|
183
|
+
# TODO: use Gem::Specification.find_by_name(@module_name, Gem::Requirement.create(Gem::Version.new(@module_version)))
|
359
184
|
all_version_search = get_module_gem_path(module_name, "*")
|
360
185
|
version_paths = Dir.glob(all_version_search)
|
361
186
|
|
362
|
-
raise
|
187
|
+
raise Gem::GemNotFoundException, "Could not find any installed version of module #{module_name}. Expected them in #{get_module_gem_path(module_name, "*")}" if version_paths.empty?
|
363
188
|
|
364
189
|
versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }
|
365
190
|
|
366
191
|
versions.sort{ |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
|
367
192
|
end
|
368
193
|
|
369
|
-
|
370
|
-
|
371
|
-
|
194
|
+
private
|
195
|
+
|
196
|
+
def require_libs_no_file_logging(module_path)
|
197
|
+
require_libs(module_path, false)
|
372
198
|
end
|
373
|
-
end
|
374
199
|
|
375
|
-
|
376
|
-
|
200
|
+
def require_libs(module_path, log = true)
|
201
|
+
lib_path = "#{module_path}/lib/**/*.rb"
|
377
202
|
|
378
|
-
|
379
|
-
|
203
|
+
log_message = "Loading all files from #{lib_path}..."
|
204
|
+
log ? (BrpmAuto.log log_message) : (print "#{log_message}\n")
|
205
|
+
|
206
|
+
require_files(Dir[lib_path], log)
|
207
|
+
end
|
208
|
+
|
209
|
+
def require_files(files, log = true)
|
210
|
+
failed_files = []
|
211
|
+
error_messages = []
|
212
|
+
files.each do |file|
|
213
|
+
if File.file?(file)
|
214
|
+
begin
|
215
|
+
require file
|
216
|
+
rescue NameError => ne # when we require a set of files with inter-dependencies, the order is important, therefore we will retry the failed files later
|
217
|
+
failed_files << file
|
218
|
+
error_messages << ne
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
if failed_files.count > 0
|
223
|
+
if failed_files.count == files.count
|
224
|
+
raise NameError, "Following files failed loading: #{failed_files.join(", ")}\nError messages: #{error_messages.join(", ")}"
|
225
|
+
else
|
226
|
+
require_files(failed_files, log)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def get_config
|
232
|
+
YAML.load_file("#{@framework_root_path}/config.yml")
|
233
|
+
end
|
234
|
+
|
235
|
+
def get_brpm_version
|
236
|
+
unless self.brpm_installed?
|
237
|
+
raise "BRPM is not installed."
|
238
|
+
end
|
380
239
|
|
381
|
-
|
240
|
+
knob_file = "#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml"
|
241
|
+
unless File.exists?(knob_file)
|
242
|
+
raise "Could not find the knob file at the expected location (#{knob_file})"
|
243
|
+
end
|
244
|
+
|
245
|
+
knob = YAML.load_file(knob_file)
|
246
|
+
version_content = File.read("#{knob["application"]["root"]}/VERSION")
|
247
|
+
version_content.scan(/VERSION=([0-9\.]*)/)[0][0]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
self.init
|
382
252
|
end
|
data/lib/brpm_script_executor.rb
CHANGED
@@ -1,7 +1,46 @@
|
|
1
1
|
require_relative "brpm_auto"
|
2
|
+
require 'fileutils'
|
3
|
+
require "yaml"
|
2
4
|
|
3
5
|
class BrpmScriptExecutor
|
6
|
+
private_class_method :new
|
7
|
+
|
4
8
|
class << self
|
9
|
+
def execute_automation_script_in_separate_process(modul, name, params)
|
10
|
+
BrpmAuto.setup(params)
|
11
|
+
|
12
|
+
params_file = "#{File.expand_path(params["SS_output_dir"] || params["output_dir"] || Dir.pwd)}/params_#{params["SS_run_key"] || params["run_key"] || "000"}.yml"
|
13
|
+
|
14
|
+
BrpmAuto.log "Creating params file #{params_file}..."
|
15
|
+
File.open(params_file, "w") do |file|
|
16
|
+
file.puts(params.to_yaml)
|
17
|
+
end
|
18
|
+
|
19
|
+
BrpmAuto.log "Executing '#{modul}' '#{name}' in a separate process..."
|
20
|
+
Bundler.clean_system({"GEM_HOME" => ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}, get_ruby_cmd, "-r", __FILE__, "-e", "BrpmScriptExecutor.execute_automation_script_from_other_process(\"#{modul}\", \"#{name}\", \"#{params_file}\")")
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_automation_script_from_other_process(modul, name, params_file)
|
24
|
+
puts "Loading params file #{params_file}..."
|
25
|
+
params = YAML.load_file(params_file)
|
26
|
+
|
27
|
+
puts "Loading the BRPM Content framework..."
|
28
|
+
BrpmAuto.setup(params)
|
29
|
+
BrpmAuto.log "The BRPM Content framework is loaded now. (version: #{BrpmAuto.version})"
|
30
|
+
|
31
|
+
BrpmAuto.log "Deleting params file #{params_file}..."
|
32
|
+
FileUtils.rm(params_file)
|
33
|
+
|
34
|
+
if params["SS_run_key"] and params["SS_script_support_path"]
|
35
|
+
BrpmAuto.log "Loading script_support libraries..."
|
36
|
+
require "#{params["SS_script_support_path"]}/ssh_script_header.rb"
|
37
|
+
require "#{params["SS_script_support_path"]}/script_helper.rb"
|
38
|
+
require "#{params["SS_script_support_path"]}/file_in_utf.rb"
|
39
|
+
end
|
40
|
+
|
41
|
+
execute_automation_script(modul, name, params)
|
42
|
+
end
|
43
|
+
|
5
44
|
def execute_automation_script(modul, name, params)
|
6
45
|
begin
|
7
46
|
BrpmAuto.setup(params)
|
@@ -10,10 +49,17 @@ class BrpmScriptExecutor
|
|
10
49
|
BrpmAuto.log ">>>>>>>>>>>>>> START automation #{name}"
|
11
50
|
start_time = Time.now
|
12
51
|
|
13
|
-
BrpmAuto.
|
14
|
-
|
52
|
+
original_brpm_version = BrpmAuto.version
|
53
|
+
|
54
|
+
BrpmAuto.log "Initializing module #{modul}#{params["module_version"] ? " #{params["module_version"]}" : ""} and its dependencies..."
|
55
|
+
module_version = params["module_version"] || BrpmAuto.get_latest_installed_version(modul)
|
56
|
+
module_path = initialize_module(modul, module_version)
|
15
57
|
BrpmAuto.log "Finished loading the module."
|
16
58
|
|
59
|
+
BrpmAuto.log "Note: running on a different version of the BRPM Content framework now: #{BrpmAuto.version} (was #{original_brpm_version})" if original_brpm_version != BrpmAuto.version
|
60
|
+
|
61
|
+
BrpmAuto.require_module(modul, module_version)
|
62
|
+
|
17
63
|
automation_script_path = "#{module_path}/automations/#{name}.rb"
|
18
64
|
|
19
65
|
BrpmAuto.log "Loading the automation script #{automation_script_path}..."
|
@@ -47,7 +93,7 @@ class BrpmScriptExecutor
|
|
47
93
|
start_time = Time.now
|
48
94
|
|
49
95
|
BrpmAuto.log "Loading module #{modul} and its dependencies..."
|
50
|
-
module_path = BrpmAuto.require_module(modul) #TODO:
|
96
|
+
module_path = BrpmAuto.require_module(modul) #TODO: get the module version of the calling script
|
51
97
|
BrpmAuto.log "Finished loading the module."
|
52
98
|
|
53
99
|
automation_script_path = "#{module_path}/resource_automations/#{name}.rb"
|
@@ -75,6 +121,38 @@ class BrpmScriptExecutor
|
|
75
121
|
end
|
76
122
|
|
77
123
|
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
|
78
155
|
end
|
79
156
|
end
|
80
157
|
|
158
|
+
|
data/lib/module_installer.rb
CHANGED
@@ -4,17 +4,13 @@ require 'rubygems/installer'
|
|
4
4
|
require "bundler"
|
5
5
|
|
6
6
|
class ModuleInstaller
|
7
|
-
def initialize
|
8
|
-
set_gem_home
|
9
|
-
end
|
10
|
-
|
11
7
|
def install_module(module_name_or_path, module_version = nil)
|
12
8
|
brpm_content_spec = nil
|
13
9
|
|
14
10
|
if true #TODO: support no-gem-install mode
|
15
11
|
module_spec, specs = install_gem(module_name_or_path, module_version)
|
16
12
|
|
17
|
-
brpm_content_spec = specs.find { |spec| spec.name == "
|
13
|
+
brpm_content_spec = specs.find { |spec| spec.name == "brpm_content_framework" } if specs
|
18
14
|
|
19
15
|
install_bundle_if_necessary(module_spec)
|
20
16
|
else
|
@@ -22,12 +18,12 @@ class ModuleInstaller
|
|
22
18
|
module_spec = Gem::Specification.find_by_name(module_name)
|
23
19
|
end
|
24
20
|
|
25
|
-
if
|
21
|
+
if BrpmAuto.brpm_installed?
|
26
22
|
BrpmAuto.log "A BRPM instance is installed locally"
|
27
23
|
|
28
24
|
if brpm_content_spec
|
29
25
|
if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?(get_symlink_path)
|
30
|
-
BrpmAuto.log "Updating the symlink to
|
26
|
+
BrpmAuto.log "Updating the symlink to brpm_content_framework-latest..."
|
31
27
|
update_symlink_to_brpm_content(brpm_content_spec.gem_dir)
|
32
28
|
end
|
33
29
|
|
@@ -63,7 +59,7 @@ class ModuleInstaller
|
|
63
59
|
end
|
64
60
|
|
65
61
|
def uninstall_module(module_name, module_version)
|
66
|
-
if
|
62
|
+
if BrpmAuto.brpm_installed?
|
67
63
|
BrpmAuto.log "A BRPM instance is installed locally"
|
68
64
|
|
69
65
|
BrpmAuto.log "Preparing the connectivity to BRPM..."
|
@@ -74,7 +70,7 @@ class ModuleInstaller
|
|
74
70
|
module_friendly_name = get_module_friendly_name(module_spec)
|
75
71
|
|
76
72
|
BrpmAuto.log "Uninstalling the automation script wrappers in the local BRPM instance..."
|
77
|
-
failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path,
|
73
|
+
failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, _|
|
78
74
|
BrpmAuto.log "Uninstalling automation script wrapper for script #{auto_script_path}..."
|
79
75
|
uninstall_auto_script_wrapper(auto_script_path, module_friendly_name)
|
80
76
|
end
|
@@ -92,11 +88,7 @@ class ModuleInstaller
|
|
92
88
|
BrpmAuto.log "Uninstalling gem #{module_name} #{module_version}..."
|
93
89
|
BrpmAuto.log `gem uninstall #{module_name} -v #{module_version} -x`
|
94
90
|
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def module_installed?(module_name, module_version = nil)
|
99
|
-
Gem::Specification.find_by_name(module_name).size > 0
|
91
|
+
true
|
100
92
|
end
|
101
93
|
|
102
94
|
private
|
@@ -137,6 +129,7 @@ class ModuleInstaller
|
|
137
129
|
require 'rubygems/name_tuple'
|
138
130
|
source = Gem::Source::SpecificFile.new module_name_or_path
|
139
131
|
module_spec = source.spec
|
132
|
+
specs = [module_spec]
|
140
133
|
|
141
134
|
gem = source.download module_spec
|
142
135
|
|
@@ -159,25 +152,12 @@ class ModuleInstaller
|
|
159
152
|
return module_spec, specs
|
160
153
|
end
|
161
154
|
|
162
|
-
def set_gem_home
|
163
|
-
if BrpmAuto.run_from_brpm or BrpmAuto.params.unit_test
|
164
|
-
# we need to override the GEM_HOME env var, otherwise the gems will be installed in BRPM's own gemset
|
165
|
-
ENV["GEM_HOME"] = BrpmAuto.get_gems_root_path
|
166
|
-
Gem.paths = ENV
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
155
|
def install_bundle_if_necessary(spec)
|
171
156
|
gemfile = File.join(spec.gem_dir, "Gemfile")
|
172
|
-
gemfile_lock = File.join(spec.gem_dir, "Gemfile.lock")
|
173
157
|
|
174
|
-
if File.exists?(gemfile)
|
175
|
-
|
176
|
-
|
177
|
-
else
|
178
|
-
command = "cd #{spec.gem_dir}; bundle install"
|
179
|
-
end
|
180
|
-
BrpmAuto.log "Found a Gemfile.lock so executing command '#{command}'..."
|
158
|
+
if File.exists?(gemfile)
|
159
|
+
command = "cd #{spec.gem_dir}; bundle install"
|
160
|
+
BrpmAuto.log "Found a Gemfile so executing command '#{command}'..."
|
181
161
|
result = BrpmAuto.execute_shell(command)
|
182
162
|
|
183
163
|
BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
|
@@ -188,7 +168,7 @@ class ModuleInstaller
|
|
188
168
|
end
|
189
169
|
|
190
170
|
def get_symlink_path
|
191
|
-
"#{ENV["GEM_HOME"]}/gems/
|
171
|
+
"#{ENV["GEM_HOME"]}/gems/brpm_content_framework-latest"
|
192
172
|
end
|
193
173
|
|
194
174
|
def update_symlink_to_brpm_content(brpm_content_path)
|
@@ -203,10 +183,6 @@ class ModuleInstaller
|
|
203
183
|
end
|
204
184
|
end
|
205
185
|
|
206
|
-
def brpm_installed_locally?
|
207
|
-
ENV["BRPM_HOME"] and !ENV["BRPM_HOME"].empty?
|
208
|
-
end
|
209
|
-
|
210
186
|
def get_module_friendly_name(module_spec)
|
211
187
|
module_config = YAML.load_file("#{module_spec.gem_dir}/config.yml")
|
212
188
|
|
@@ -351,8 +327,8 @@ class ModuleInstaller
|
|
351
327
|
wrapper_script_content = "###\n#{params_content}###\n"
|
352
328
|
end
|
353
329
|
|
330
|
+
integration_server = nil
|
354
331
|
if is_local_automation(automation_type)
|
355
|
-
integration_server = nil
|
356
332
|
if auto_script_config["integration_server_type"]
|
357
333
|
server_type_id = @brpm_rest_client.get_id_for_project_server_type(auto_script_config["integration_server_type"])
|
358
334
|
if server_type_id
|
@@ -374,13 +350,12 @@ class ModuleInstaller
|
|
374
350
|
case automation_type
|
375
351
|
when "Automation", "ResourceAutomation"
|
376
352
|
wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_config["name"])
|
377
|
-
|
378
353
|
when "Local Shell"
|
379
354
|
wrapper_script_content += "#{auto_script_path}\n"
|
380
|
-
|
381
355
|
when "Remote Shell", "Remote Dispatcher"
|
382
356
|
wrapper_script_content += File.read(auto_script_path)
|
383
|
-
|
357
|
+
else
|
358
|
+
raise "Unsupported automation type: #{automation_type}"
|
384
359
|
end
|
385
360
|
|
386
361
|
script = {}
|
@@ -558,14 +533,14 @@ params["direct_execute"] = "true"
|
|
558
533
|
params["framework_version"] = nil if params["framework_version"].empty?
|
559
534
|
params["module_version"] = nil if params["module_version"].empty?
|
560
535
|
|
561
|
-
require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/
|
536
|
+
require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content_framework-\#{params["framework_version"] || "latest"}/lib/brpm_script_executor.rb"
|
562
537
|
EOR
|
563
538
|
|
564
539
|
if automation_type == "Automation"
|
565
540
|
|
566
541
|
template += <<EOR
|
567
542
|
|
568
|
-
BrpmScriptExecutor.
|
543
|
+
BrpmScriptExecutor.execute_automation_script_in_separate_process("#{module_name}", "#{auto_script_name}", params)
|
569
544
|
EOR
|
570
545
|
|
571
546
|
elsif automation_type == "ResourceAutomation"
|
@@ -573,7 +548,7 @@ EOR
|
|
573
548
|
template += <<EOR
|
574
549
|
|
575
550
|
def execute(script_params, parent_id, offset, max_records)
|
576
|
-
BrpmScriptExecutor.
|
551
|
+
BrpmScriptExecutor.execute_resource_automation_script_in_separate_process("#{module_name}", "#{auto_script_name}", script_params, parent_id, offset, max_records)
|
577
552
|
end
|
578
553
|
EOR
|
579
554
|
end
|
data/lib/write_to.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
write_to(File.read(BrpmAuto.logger.step_run_log_file_path)) unless BrpmAuto.logger.nil?
|
1
|
+
write_to(File.read(BrpmAuto.logger.step_run_log_file_path)) unless BrpmAuto.logger.nil? or ! BrpmAuto.logger.is_a?(BrpmLogger)
|
data/tests/all_params_spec.rb
CHANGED
data/tests/brpm_auto_spec.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe 'BRPM Script Executor' do
|
4
|
+
before(:all) do
|
5
|
+
setup_brpm_env
|
6
|
+
|
7
|
+
require_relative "../lib/brpm_script_executor"
|
8
|
+
require_relative "../lib/brpm_auto"
|
9
|
+
BrpmAuto.setup(get_default_params)
|
10
|
+
|
11
|
+
BrpmAuto.log "Creating ~/.brpm file..."
|
12
|
+
create_brpm_file
|
13
|
+
|
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
|
+
BrpmAuto.log "Installing brpm_module_test..."
|
17
|
+
# `gem install brpm_module_test`
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should execute an automation script in a separate process" do
|
22
|
+
result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby", get_default_params)
|
23
|
+
|
24
|
+
expect(result).to be_truthy
|
25
|
+
end
|
26
|
+
end
|
data/tests/params_spec.rb
CHANGED
data/tests/server_yaml_spec.rb
CHANGED
data/tests/spec_helper.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'yaml'
|
3
|
-
|
3
|
+
require 'json'
|
4
4
|
|
5
5
|
FileUtils.mkdir_p "/tmp/brpm_content"
|
6
6
|
|
7
|
+
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
|
+
end
|
11
|
+
|
7
12
|
def setup_brpm_auto
|
13
|
+
require "brpm_script_executor"
|
14
|
+
require "brpm_auto"
|
8
15
|
BrpmAuto.setup(get_default_params)
|
9
16
|
end
|
10
17
|
|
@@ -1,38 +1,9 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
1
3
|
describe 'Module installer' do
|
2
4
|
before(:all) do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
brpm_version = "4.6.00.00"
|
7
|
-
ENV["BRPM_HOME"] = ENV["BRPM_STUB_HOME"]
|
8
|
-
|
9
|
-
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/modules"
|
10
|
-
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments"
|
11
|
-
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM"
|
12
|
-
|
13
|
-
knob=<<EOR
|
14
|
-
---
|
15
|
-
application:
|
16
|
-
root: #{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM
|
17
|
-
environment:
|
18
|
-
RAILS_ENV: production
|
19
|
-
web:
|
20
|
-
context: /brpm
|
21
|
-
EOR
|
22
|
-
|
23
|
-
File.open("#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml", "w") do |file|
|
24
|
-
file.puts(knob)
|
25
|
-
end
|
26
|
-
|
27
|
-
version_content=<<EOR
|
28
|
-
$VERSION=#{brpm_version}
|
29
|
-
EOR
|
30
|
-
|
31
|
-
File.open("#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM/VERSION", "w") do |file|
|
32
|
-
file.puts(version_content)
|
33
|
-
end
|
34
|
-
|
35
|
-
require_relative "spec_helper"
|
5
|
+
setup_gem_env
|
6
|
+
setup_modules_env
|
36
7
|
|
37
8
|
setup_brpm_auto
|
38
9
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
def setup_gem_env
|
2
|
+
raise "$BRPM_STUB_HOME is not set" unless ENV["BRPM_STUB_HOME"]
|
3
|
+
|
4
|
+
ENV["BRPM_HOME"] = ENV["BRPM_STUB_HOME"]
|
5
|
+
ENV["GEM_HOME"] = "#{ENV["BRPM_HOME"]}/modules"
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup_modules_env
|
9
|
+
raise "Module installer tests don't work under Bundler." if ENV["RUBYOPT"] and ENV["RUBYOPT"].include?("-rbundler/setup")
|
10
|
+
brpm_version = "4.6.00.00"
|
11
|
+
|
12
|
+
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/modules"
|
13
|
+
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments"
|
14
|
+
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM"
|
15
|
+
|
16
|
+
knob=<<EOR
|
17
|
+
---
|
18
|
+
application:
|
19
|
+
root: #{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM
|
20
|
+
environment:
|
21
|
+
RAILS_ENV: production
|
22
|
+
web:
|
23
|
+
context: /brpm
|
24
|
+
EOR
|
25
|
+
|
26
|
+
File.open("#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml", "w") do |file|
|
27
|
+
file.puts(knob)
|
28
|
+
end
|
29
|
+
|
30
|
+
version_content=<<EOR
|
31
|
+
$VERSION=#{brpm_version}
|
32
|
+
EOR
|
33
|
+
|
34
|
+
File.open("#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM/VERSION", "w") do |file|
|
35
|
+
file.puts(version_content)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_brpm_auto
|
40
|
+
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
|
+
BrpmAuto.setup(get_default_params)
|
42
|
+
end
|
43
|
+
|
@@ -67,7 +67,7 @@ else
|
|
67
67
|
end
|
68
68
|
@request_params = {} if not defined?(@request_params)
|
69
69
|
SS_output_file = @params["SS_output_file"]
|
70
|
-
BrpmAuto.require_module("
|
70
|
+
BrpmAuto.require_module("brpm_module_brpm")
|
71
71
|
@p = BrpmAuto.all_params
|
72
72
|
@request_params = BrpmAuto.request_params
|
73
73
|
ARG_PREFIX = "ARG_" unless defined?(ARG_PREFIX)
|
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.1
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -172,15 +172,17 @@ files:
|
|
172
172
|
- module.gemspec
|
173
173
|
- tests/all_params_spec.rb
|
174
174
|
- tests/brpm_auto_spec.rb
|
175
|
+
- tests/brpm_script_executor_spec.rb
|
175
176
|
- tests/customer_include/config/customer_include.rb
|
176
177
|
- tests/customer_include/config/server.yml
|
177
178
|
- tests/customer_include_spec.rb
|
178
179
|
- tests/gemspec_spec.rb
|
179
|
-
- tests/module_installer_spec.rb
|
180
180
|
- tests/params_spec.rb
|
181
181
|
- tests/request_params_spec.rb
|
182
182
|
- tests/server_yaml_spec.rb
|
183
183
|
- tests/spec_helper.rb
|
184
|
+
- tests_no_bundler/module_installer_spec.rb
|
185
|
+
- tests_no_bundler/spec_helper.rb
|
184
186
|
- to_be_migrated/brpm_framework.rb
|
185
187
|
- to_be_migrated/customer_include_default.rb
|
186
188
|
- to_be_migrated/local_jirb.rb
|