brpm_content_framework 0.2.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjQ4ZmU3ZDk0Y2Q1NWJhM2UyN2Q4MGE1YTkyMGU0NjUzNDc4MDgzYw==
4
+ ZTdiNGY5ZTI3YTQxZWYxOTdiYmEyODlmY2Y1ZTJhYTlkNDRlMzY0Nw==
5
5
  data.tar.gz: !binary |-
6
- NDFmMzJlNzNiZTg2YTA4MTA5ZjA0MTYzMzlmY2Y5OGI5ZDU3NmRhOA==
6
+ ZjQxNjNhMGM3MjZhNTE3ODAxNzVhZDM3NjZmODE4ZjM1NTM2YjBmYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmQ4OGM3ZjkzODdlMzQ1NjU0MmNkOTc5MGM5MGZjNmE2ZGJhMzYzNmI3NDA3
10
- Zjk1Njc2NmQ2OGYxMjliN2I1NzA4MmRhMWQ4MjJiY2E0Y2M2OTYzYzU1ZmIw
11
- YTc2NTQxMzI3ODc5ZTA0MTI2YTZkMGZmNjAwNDdhOGExMDQzZTk=
9
+ ZmExMWE0MzFjMWNlMGFmYWJjZmQ3MGY4N2IxYTZjYmU0ZDEwYjQ1NjBmNWVh
10
+ NjY2NDIwNjU5ZTAwMzk0ZTE0OGU4MDNkNjY3ZjkwYzQzYWJhYTE3NWFiMGU0
11
+ ODY1ODhmMzgxZmViNWU5ODIwNmRhNjkyZDU4MDg0Y2U3MDZiMjE=
12
12
  data.tar.gz: !binary |-
13
- YjE5YTY4MjhlYmRhNDg0YWZmYzNjODQ2ZDJlMjhjNDllZmNmOTg3ZDRhZDQ2
14
- YzdhMWEyYTQyMTQ1NTI3Y2YxNzc4NDYzODU1ZjM0MjE4Mzc2MDdhNTRmMjVk
15
- NmVkZDQ2YzZkMTY1NWRhNjUyMzA3NGVlNDVhMjVmYzdhNzZjOTk=
13
+ YmFjMzcxYmY4ZmQ4MjM0ZDNhYmFmNTFlOWI4MjJjZGU2ZjY4YmJhNzk5ZjQ0
14
+ NjVmZGFhZmYzN2RlOGQ3YWQ1N2ZmNTU0OTg1OTBlOTNjOTNkNmNkMDc1OGJj
15
+ NTkyOTlkODg0ODAzODM0YjkzMzUxNjYwZTcyNzNkMjRlNTg3Nzg=
data/README.md CHANGED
@@ -107,6 +107,7 @@ Just make sure to stick with the following [file structure](https://github.com/B
107
107
  | +-- my_automation_script_spec.rb
108
108
  | +-- spec_helper.rb
109
109
  +-- config.yml
110
+ +-- Gemfile
110
111
  +-- module.gemspec
111
112
  +-- Rakefile
112
113
  ```
@@ -117,7 +118,7 @@ The automations directory contains the actual automation scripts and the resourc
117
118
 
118
119
  See the example files from the module_template directory for more information on the mandatory and optional fields.
119
120
 
120
- In order to publish your module, two more files are needed: a module.gemspec file and a Rakefile. These two files can be copied from the module_template directory unmodified.
121
+ In order to publish your module, three more files are needed: a Gemfile, a module.gemspec file and a Rakefile. These files can be copied from the module_template directory unmodified.
121
122
 
122
123
  During the development life cycle, after you have committed the changes to your automation scripts and bumped the version number from the config.yml file, you can now publish the new version of your module with a simple command:
123
124
  ```shell
data/config.yml CHANGED
@@ -1,4 +1,4 @@
1
- version: 0.2.6
1
+ version: 0.2.8
2
2
 
3
3
  author: Niek Bartholomeus
4
4
  email: niek.bartholomeus@gmail.com
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -3,7 +3,7 @@ require "yaml"
3
3
  config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = File.basename(File.expand_path(File.dirname(__FILE__)))
6
+ spec.name = File.basename(File.expand_path(File.dirname(__FILE__))).sub("-#{config["version"]}", "")
7
7
  spec.version = config["version"]
8
8
  spec.platform = Gem::Platform::RUBY
9
9
  spec.license = config["license"]
@@ -1,3 +1,4 @@
1
- require 'bundler/setup';
2
- require 'brpm_script_executor';
3
- BrpmScriptExecutor.execute_automation_script_from_other_process('brpm_module_test', 'test_ruby_raises_error', '/private/tmp/brpm_content/params_000_tmp.yml')
1
+ require 'bundler/setup'
2
+ require 'brpm_script_executor'
3
+ puts `bundle show`
4
+ BrpmScriptExecutor.execute_automation_script_from_other_process('brpm_module_test', 'test_ruby', '/private/tmp/brpm_content/params_000.yml', "automation")
data/lib/brpm_auto.rb CHANGED
@@ -15,9 +15,6 @@ class BrpmAuto
15
15
 
16
16
  attr_reader :framework_root_path
17
17
 
18
- attr_reader :gems_root_path
19
- attr_reader :gemfile_lock
20
-
21
18
  def init
22
19
  @framework_root_path = File.expand_path("#{File.dirname(__FILE__)}/..")
23
20
 
@@ -31,7 +28,6 @@ class BrpmAuto
31
28
  @version = @config["version"]
32
29
 
33
30
  @brpm_version = get_brpm_version if self.brpm_installed?
34
- @gems_root_path = get_gems_root_path
35
31
  end
36
32
 
37
33
  def setup(params = {})
@@ -130,9 +126,9 @@ class BrpmAuto
130
126
  ENV["BRPM_HOME"] and ! ENV["BRPM_HOME"].empty?
131
127
  end
132
128
 
133
- def require_module(module_name, module_version = nil)
134
- module_version ||= get_latest_installed_version(module_name)
135
- module_path = get_module_gem_path(module_name, module_version)
129
+ def require_module(module_name)
130
+ module_spec = Gem::Specification.find_by_name(module_name) # will raise an error when the module is not installed
131
+ module_path = module_spec.gem_dir
136
132
 
137
133
  module_config_file_path = "#{module_path}/config.yml"
138
134
 
@@ -144,23 +140,12 @@ class BrpmAuto
144
140
  module_config["dependencies"].each do |dependency|
145
141
  if dependency.is_a?(Hash)
146
142
  dep_module_name = dependency.keys[0]
147
- if @gemfile_lock
148
- dep_module_version = get_version_from_gemfile_lock(dep_module_name)
149
- else
150
- dep_module_version = dependency.values[0]["version"]
151
- end
152
143
  else
153
144
  dep_module_name = dependency
154
-
155
- if @gemfile_lock
156
- dep_module_version = get_version_from_gemfile_lock(dep_module_name)
157
- else
158
- dep_module_version = get_latest_installed_version(dep_module_name)
159
- end
160
145
  end
161
146
 
162
- BrpmAuto.log "Loading module #{dep_module_name} version #{dep_module_version}..."
163
- require_module(dep_module_name, dep_module_version)
147
+ BrpmAuto.log "Loading module #{dep_module_name}..."
148
+ require_module(dep_module_name)
164
149
  end
165
150
  end
166
151
  else
@@ -173,29 +158,6 @@ class BrpmAuto
173
158
  module_path
174
159
  end
175
160
 
176
- def get_module_gem_path(module_name, module_version)
177
- "#{@gems_root_path}/gems/#{module_name}-#{module_version}"
178
- end
179
-
180
- def get_latest_installed_version(module_name)
181
- latest_version_path = get_module_gem_path(module_name, "latest")
182
- return "latest" if File.exists?(latest_version_path)
183
-
184
- # TODO: use Gem::Specification.find_by_name(@module_name, Gem::Requirement.create(Gem::Version.new(@module_version)))
185
- all_version_search = get_module_gem_path(module_name, "*")
186
- version_paths = Dir.glob(all_version_search)
187
-
188
- 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?
189
-
190
- versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }
191
-
192
- versions.sort{ |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
193
- end
194
-
195
- def refresh_gems_root_path
196
- @gems_root_path = get_gems_root_path
197
- end
198
-
199
161
  private
200
162
 
201
163
  def require_libs_no_file_logging(module_path)
@@ -233,18 +195,6 @@ class BrpmAuto
233
195
  end
234
196
  end
235
197
 
236
- def get_gems_root_path
237
- if ENV["BRPM_CONTENT_HOME"]
238
- ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
239
- elsif ENV["BRPM_HOME"]
240
- "#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed
241
- elsif ENV["GEM_HOME"]
242
- ENV["GEM_HOME"] # default gemset location when BRPM is not installed
243
- else
244
- raise "Unable to find out the gems root path."
245
- end
246
- end
247
-
248
198
  def get_config
249
199
  YAML.load_file("#{@framework_root_path}/config.yml")
250
200
  end
@@ -6,7 +6,48 @@ 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
+
9
17
  def execute_automation_script_in_separate_process(modul, name, params)
18
+ execute_automation_script_in_separate_process_internal(modul, name, params, "automation")
19
+ end
20
+
21
+ def execute_resource_automation_script_in_separate_process(modul, name, params, parent_id, offset, max_records)
22
+ execute_automation_script_in_separate_process_internal(modul, name, params, "resource_automation", parent_id, offset, max_records)
23
+ end
24
+
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 params["SS_run_key"] and params["SS_script_support_path"]
39
+ BrpmAuto.log "Loading script_support libraries..."
40
+ require "#{params["SS_script_support_path"]}/ssh_script_header.rb"
41
+ require "#{params["SS_script_support_path"]}/script_helper.rb"
42
+ require "#{params["SS_script_support_path"]}/file_in_utf.rb"
43
+ end
44
+
45
+ execute_automation_script_internal(modul, name, params, automation_type, parent_id, offset, max_records)
46
+ end
47
+
48
+ private
49
+
50
+ def execute_automation_script_in_separate_process_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
10
51
  BrpmAuto.setup(params)
11
52
 
12
53
  params_file = "#{File.expand_path(params["SS_output_dir"] || params["output_dir"] || Dir.pwd)}/params_#{params["SS_run_key"] || params["run_key"] || "000"}.yml"
@@ -20,8 +61,15 @@ class BrpmScriptExecutor
20
61
  env_vars["GEM_HOME"] = ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"
21
62
 
22
63
  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)
64
+ case automation_type
65
+ when "automation"
66
+ module_version = params["module_version"] || get_latest_installed_version(modul)
67
+ when "resource_automation"
68
+ module_version = get_latest_installed_version(modul) #TODO: get the module version of the calling script
69
+ else
70
+ raise "Automation type #{automation_type} is not supported."
71
+ end
72
+ module_path = get_module_gem_path(modul, module_version)
25
73
 
26
74
  if File.exists?(module_path)
27
75
  BrpmAuto.log "Found module #{modul} #{module_version || ""} in path #{module_path}."
@@ -36,13 +84,13 @@ class BrpmScriptExecutor
36
84
  return
37
85
  end
38
86
 
39
- BrpmAuto.log "Found a Gemfile (#{gemfile_path}) so the automation script will have to run inside bundler."
87
+ BrpmAuto.log "Using Gemfile #{gemfile_path}."
40
88
  env_vars["BUNDLE_GEMFILE"] = gemfile_path
41
89
  require_statements += "require 'bundler/setup'; "
42
90
  # TODO Bundler.require
43
91
 
44
92
  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}\")")
93
+ 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}\", \"#{automation_type}\", \"#{parent_id}\", \"#{offset}\", \"#{max_records}\")")
46
94
  if result.nil?
47
95
  BrpmAuto.log_error("The process that executed the automation script returned with 'Command execution failed'.")
48
96
  elsif result == false
@@ -52,53 +100,31 @@ class BrpmScriptExecutor
52
100
  result
53
101
  end
54
102
 
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
-
58
- puts "Loading params file #{params_file}..."
59
- params = YAML.load_file(params_file)
60
-
61
- puts "Loading the BRPM Content framework..."
62
- BrpmAuto.setup(params)
63
- BrpmAuto.log "The BRPM Content framework is loaded now. (version: #{BrpmAuto.version})"
64
-
65
- BrpmAuto.log "Deleting params file #{params_file}..."
66
- FileUtils.rm(params_file)
67
-
68
- if params["SS_run_key"] and params["SS_script_support_path"]
69
- BrpmAuto.log "Loading script_support libraries..."
70
- require "#{params["SS_script_support_path"]}/ssh_script_header.rb"
71
- require "#{params["SS_script_support_path"]}/script_helper.rb"
72
- require "#{params["SS_script_support_path"]}/file_in_utf.rb"
73
- end
74
-
75
- execute_automation_script(modul, name, params)
76
- end
77
-
78
- def execute_automation_script(modul, name, params)
103
+ def execute_automation_script_internal(modul, name, params, automation_type, parent_id = nil, offset = nil, max_records = nil)
79
104
  begin
80
105
  BrpmAuto.setup(params)
81
106
 
82
107
  BrpmAuto.log ""
83
- BrpmAuto.log ">>>>>>>>>>>>>> START automation #{name}"
108
+ BrpmAuto.log ">>>>>>>>>>>>>> START #{automation_type} #{name}"
84
109
  start_time = Time.now
85
110
 
86
- module_version = params["module_version"] || BrpmAuto.get_latest_installed_version(modul)
87
- module_path = BrpmAuto.get_module_gem_path(modul, module_version)
88
-
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
111
+ module_spec = Gem::Specification.find_by_name(modul) # will raise an error when the module is not installed
112
+ module_path = module_spec.gem_dir
94
113
 
95
- BrpmAuto.require_module(modul, module_version)
114
+ BrpmAuto.require_module(modul)
96
115
 
97
- automation_script_path = "#{module_path}/automations/#{name}.rb"
116
+ automation_script_path = "#{module_path}/#{automation_type}s/#{name}.rb"
117
+ unless File.exists?(automation_script_path)
118
+ raise "Could not find automation #{name} in module #{modul}. Expected it on path #{automation_script_path}."
119
+ end
98
120
 
99
- BrpmAuto.log "Executing the automation script #{automation_script_path}..."
121
+ BrpmAuto.log "Executing the #{automation_type} script #{name} from #{automation_script_path}..."
100
122
  load automation_script_path
101
123
 
124
+ if automation_type == "resource_automation"
125
+ BrpmAuto.log "Calling execute_resource_automation_script(params, parent_id, offset, max_records)..."
126
+ execute_script(params, parent_id, offset, max_records)
127
+ end
102
128
  rescue Exception => e
103
129
  BrpmAuto.log_error "#{e}"
104
130
  BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
@@ -109,52 +135,42 @@ class BrpmScriptExecutor
109
135
  duration = 0
110
136
  duration = stop_time - start_time unless start_time.nil?
111
137
 
112
- BrpmAuto.log ">>>>>>>>>>>>>> STOP automation #{name} - total duration: #{Time.at(duration).utc.strftime("%H:%M:%S")}"
138
+ BrpmAuto.log ">>>>>>>>>>>>>> STOP #{automation_type} #{name} - total duration: #{Time.at(duration).utc.strftime("%H:%M:%S")}"
113
139
  BrpmAuto.log ""
114
140
 
115
141
  #load "#{File.dirname(__FILE__)}/write_to.rb" if BrpmAuto.params.run_from_brpm
116
142
  end
117
143
  end
144
+ def get_module_gem_path(module_name, module_version)
145
+ "#{get_gems_root_path}/gems/#{module_name}-#{module_version}"
146
+ end
118
147
 
119
- alias_method :execute_automation_script_from_gem, :execute_automation_script
120
-
121
- def execute_resource_automation_script(modul, name, params, parent_id, offset, max_records)
122
- begin
123
- BrpmAuto.setup(params)
124
-
125
- BrpmAuto.log ""
126
- BrpmAuto.log ">>>>>>>>>>>>>> START resource automation #{name}"
127
- start_time = Time.now
128
-
129
- BrpmAuto.log "Loading module #{modul} and its dependencies..."
130
- module_path = BrpmAuto.require_module(modul) #TODO: get the module version of the calling script
131
- BrpmAuto.log "Finished loading the module."
132
-
133
- automation_script_path = "#{module_path}/resource_automations/#{name}.rb"
148
+ def get_latest_installed_version(module_name)
149
+ latest_version_path = get_module_gem_path(module_name, "latest")
150
+ return "latest" if File.exists?(latest_version_path)
134
151
 
135
- BrpmAuto.log "Executing the resource automation script #{automation_script_path}..."
136
- load automation_script_path
152
+ # TODO: use Gem::Specification.find_by_name(@module_name, Gem::Requirement.create(Gem::Version.new(@module_version)))
153
+ all_version_search = get_module_gem_path(module_name, "*")
154
+ version_paths = Dir.glob(all_version_search)
137
155
 
138
- BrpmAuto.log "Calling execute_resource_automation_script(params, parent_id, offset, max_records)..."
139
- execute_script(params, parent_id, offset, max_records)
140
-
141
- rescue Exception => e
142
- BrpmAuto.log_error "#{e}"
143
- BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
156
+ 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?
144
157
 
145
- raise e
146
- ensure
147
- stop_time = Time.now
148
- duration = stop_time - start_time
158
+ versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }
149
159
 
150
- BrpmAuto.log ">>>>>>>>>>>>>> STOP resource automation #{name} - total duration: #{Time.at(duration).utc.strftime("%H:%M:%S")}"
151
- BrpmAuto.log ""
160
+ versions.sort{ |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
161
+ end
152
162
 
153
- #load "#{File.dirname(__FILE__)}/write_to.rb" if BrpmAuto.params.run_from_brpm
163
+ def get_gems_root_path
164
+ if ENV["BRPM_CONTENT_HOME"]
165
+ ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
166
+ elsif ENV["BRPM_HOME"]
167
+ "#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed
168
+ elsif ENV["GEM_HOME"]
169
+ ENV["GEM_HOME"] # default gemset location when BRPM is not installed
170
+ else
171
+ raise "Unable to find out the gems root path."
154
172
  end
155
173
  end
156
-
157
- alias_method :execute_resource_automation_script_from_gem, :execute_resource_automation_script
158
174
  end
159
175
  end
160
176
 
data/module.gemspec CHANGED
@@ -3,7 +3,7 @@ require "yaml"
3
3
  config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = File.basename(File.expand_path(File.dirname(__FILE__)))
6
+ spec.name = File.basename(File.expand_path(File.dirname(__FILE__))).sub("-#{config["version"]}", "")
7
7
  spec.version = config["version"]
8
8
  spec.platform = Gem::Platform::RUBY
9
9
  spec.license = config["license"]
@@ -6,7 +6,6 @@ describe 'BRPM Script Executor' do
6
6
 
7
7
  require_relative "../lib/brpm_script_executor"
8
8
  require_relative "../lib/brpm_auto"
9
- BrpmAuto.refresh_gems_root_path # TODO: find a better way to make sur ethe newly set BRPM_HOME is taken into account in cases where BrpmAuto was already loaded during earlier tests without the BRPM_HOME set
10
9
  BrpmAuto.setup(get_default_params)
11
10
 
12
11
  test_gems = Dir.glob("#{ENV["BRPM_HOME"]}/modules/gems/brpm_module_test*")
@@ -30,19 +29,18 @@ describe 'BRPM Script Executor' do
30
29
  end
31
30
  end
32
31
 
33
- it "should execute an automation script in-process" do
34
- result = BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby", get_default_params)
35
-
36
- expect(result).to be_truthy
37
- end
38
-
39
- it "should return false when executing an non-existing automation script in-process" do
40
- expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "xxx", get_default_params)}.to raise_exception
41
- end
42
-
43
- it "should return false when executing an erroneous automation script in-process" do
44
- expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby_raises_error", get_default_params)}.to raise_exception
45
- end
32
+ # these tests dont work because the gem brpm_module_test is not included in the Gemfile, best to move them out to a separate project
33
+ # it "should execute an automation script in-process" do
34
+ # expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby", get_default_params)}.not_to raise_exception
35
+ # end
36
+ #
37
+ # it "should return false when executing an non-existing automation script in-process" do
38
+ # expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "xxx", get_default_params)}.to raise_exception
39
+ # end
40
+ #
41
+ # it "should return false when executing an erroneous automation script in-process" do
42
+ # expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby_raises_error", get_default_params)}.to raise_exception
43
+ # end
46
44
 
47
45
  it "should execute an automation script in a separate process" do
48
46
  result = BrpmScriptExecutor.execute_automation_script_in_separate_process("brpm_module_test", "test_ruby", get_default_params)
@@ -0,0 +1,42 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe 'BRPM Script Executor' do
4
+ before(:all) do
5
+ setup_gem_env
6
+
7
+ require_relative "../lib/brpm_script_executor"
8
+ require_relative "../lib/brpm_auto"
9
+ BrpmAuto.setup(get_default_params)
10
+
11
+ ENV["GEM_HOME"] = "#{ENV["BRPM_HOME"]}/modules"
12
+ Gem.paths = ENV
13
+ test_gems = Gem::Specification.find_all_by_name("brpm_module_test")
14
+
15
+ if test_gems.empty?
16
+ # TODO: get this to work to avoid race conditions waiting for the new gem version to be 'rake release'ed to rubygems
17
+ # BrpmAuto.log "Doing a 'rake install' to install brpm_content_framework as a gem..."
18
+ # result = Bundler.clean_system("export GEM_HOME=#{ENV["GEM_HOME"]} && cd .. && rake install")
19
+ # raise "rake install failed" unless result
20
+
21
+ BrpmAuto.log "Installing brpm_module_test..."
22
+ specs = Gem.install("brpm_module_test")
23
+ spec = specs.find { |spec| spec.name == "brpm_module_test"}
24
+ BrpmAuto.log "Bundle install..."
25
+ result = Bundler.clean_system("export GEM_HOME=#{ENV["GEM_HOME"]} && export BUNDLE_GEMFILE=#{spec.gem_dir}/Gemfile && bundle install")
26
+ raise "bundle install failed" unless result
27
+ end
28
+ end
29
+
30
+ # these tests have to be executed outside bundler because they need the gem brpm_module_test which is not included in the Gemfile of brpm_content_framework
31
+ it "should execute an automation script in-process" do
32
+ expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby", get_default_params)}.not_to raise_exception
33
+ end
34
+
35
+ it "should return false when executing an non-existing automation script in-process" do
36
+ expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "xxx", get_default_params)}.to raise_exception
37
+ end
38
+
39
+ it "should return false when executing an erroneous automation script in-process" do
40
+ expect{BrpmScriptExecutor.execute_automation_script("brpm_module_test", "test_ruby_raises_error", get_default_params)}.to raise_exception
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brpm_content_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niek Bartholomeus
@@ -128,6 +128,7 @@ files:
128
128
  - infrastructure/config/customer_include.rb
129
129
  - infrastructure/config/server.yml
130
130
  - infrastructure/log.html
131
+ - infrastructure/module_template/Gemfile
131
132
  - infrastructure/module_template/Rakefile
132
133
  - infrastructure/module_template/Rakefile_for_private_gem_repo
133
134
  - infrastructure/module_template/automations/my_automation_script.meta
@@ -182,6 +183,7 @@ files:
182
183
  - tests/request_params_spec.rb
183
184
  - tests/server_yaml_spec.rb
184
185
  - tests/spec_helper.rb
186
+ - tests_no_bundler/brpm_script_executor_spec.rb
185
187
  - tests_no_bundler/module_installer_spec.rb
186
188
  - tests_no_bundler/spec_helper.rb
187
189
  - to_be_migrated/brpm_framework.rb