brpm_content 0.1.43 → 0.1.45

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmRkNmI4YWM5MmE0ODRhNmQ3ZGQ5ODEwZTIxZDZkYWRjNDBlYjQ2Yw==
4
+ MWM5Yjc2NzlmMDcyMTQ1YmIwMDIxODI4OWNiNTZmNDAyMGRlYWI1ZA==
5
5
  data.tar.gz: !binary |-
6
- ZDIyODhkZDRkMGVhNzk2ZGJhMmFlM2QzNTIyMzEwYTkyMzQ0NzIyZA==
6
+ YWJhNjJiZGUzYTgyNmI4MjZkMTk2MjYwNjU1M2MyZDExZTI0NDJiMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWQ1OTJiNTdlYTAxZmRmOTVjNWQzZTc0MTNjNDAxYzU2YjRlMDZiMGIwODI0
10
- ZWYyZDU2MDE4Y2MxNzYzMjA0NzEwZDU3NGYyNDk3YTkzNGY5YWZlMmEzNDQy
11
- OWJhODQ3NjM5YjQ1ZDgzZmE5MjgxYTQ1MWZmNjdhMjcwMDBhZmY=
9
+ OTU4NDAyZGE3NzdmYzIyOGYxMTdjYTIxMGNiMDZiZjdhYzU4OTIzYjU4Njgw
10
+ OWQ5OTkxMTgwNDYwNGI5NTcyZGNjNTY0MWRhMTdmMGM0YjYyMTY0Yjc4ZDE1
11
+ YjNkN2NhOTVkMjIxMWUxMmYwZDA2NmIwZDlkOWNiMGY0ZjU1MDY=
12
12
  data.tar.gz: !binary |-
13
- MzI5NTk2MzA2NTVlNmY1NTU0YTVkYTBjZDBmYTU3OGU2NzA0OGE0ZDBlZGFi
14
- OWJjYWQ1OGJkYzE0OGVlMzBiNGJkNmY2ZTQ2NTc1ZTViYjFkZmZhMTA1NTQ5
15
- ZGZmYzkzYjQzNDU5MWIwMTc1NTNiZDg3ZjRiZjI0Yjc1YzY1Zjc=
13
+ NzdkMWU0M2IwMjE2MDcxZjFkYTJkODVmMzk3ZTgwMWJmZjI1YWVhNmJhZTc3
14
+ ZTU0NzE4ZjdkYmU2ZjliZDY0NzRkNzhjNzE2NTJlMWM2YWU1MjhmZTU5MmY1
15
+ MTQ4Y2UwNWZjNGUwNzEzYjRmZGZmNWIxNjI3YjBkNzBhYTM5MTk=
data/.travis.yml CHANGED
@@ -2,6 +2,11 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
 
5
+ before_install:
6
+ - gem update --system 2.1.9
7
+
8
+ install: gem install brpm_module_brpm #needed for module installation tests
9
+
5
10
  script:
6
11
  - rspec modules/framework/tests --format documentation --color
7
12
 
data/config.yml CHANGED
@@ -1,4 +1,4 @@
1
- version: 0.1.43
1
+ version: 0.1.45
2
2
 
3
3
  author: Niek Bartholomeus
4
4
  email: niek.bartholomeus@gmail.com
@@ -42,7 +42,7 @@ class MessagingProcessor < TorqueBox::Messaging::MessageProcessor
42
42
 
43
43
  rescue Exception => e
44
44
  BrpmAuto.log_error(e)
45
- BrpmAuto.log e.backtrace.join("\n\t")
45
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
46
46
  end
47
47
  end
48
48
  end
@@ -56,7 +56,7 @@ begin
56
56
 
57
57
  rescue Exception => e
58
58
  BrpmAuto.log_error(e)
59
- BrpmAuto.log e.backtrace.join("\n\t")
59
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
60
60
 
61
61
  raise e
62
62
  end
@@ -26,7 +26,7 @@ class EventProcessor < WEBrick::HTTPServlet::AbstractServlet
26
26
  response.body = "OK"
27
27
  rescue Exception => e
28
28
  BrpmAuto.log_error(e)
29
- BrpmAuto.log e.backtrace.join("\n\t")
29
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
30
30
  end
31
31
  end
32
32
  end
@@ -43,7 +43,7 @@ begin
43
43
  server.start
44
44
  rescue Exception => e
45
45
  BrpmAuto.log_error(e)
46
- BrpmAuto.log e.backtrace.join("\n\t")
46
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
47
47
 
48
48
  raise e
49
49
  end
@@ -1,23 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
- require "rubygems"
3
- require "bundler"
4
2
  require "yaml"
5
-
6
3
  require "brpm_auto"
7
4
 
8
5
  params = {}
9
6
  params["log_file"] = "/tmp/brpm_install.log"
10
7
  params["also_log_to_console"] = "true"
11
- params["unit_test"] = "true" if ENV["UNIT_TEST"] == "1"
12
- BrpmAuto.setup(params)
13
8
 
14
- if ARGV.size < 1
15
- BrpmAuto.log "Missing arguments."
16
- BrpmAuto.log "Usage: brpm_install <module name> [<module version>]"
17
- end
9
+ begin
10
+ BrpmAuto.setup(params)
11
+
12
+ if ARGV.size < 1
13
+ BrpmAuto.log "Missing arguments."
14
+ BrpmAuto.log "Usage: \n brpm_install <module name> [<module version>]\n brpm_install <path to module>"
15
+ end
16
+
17
+ module_name_or_path = ARGV[0]
18
+ module_version = ARGV[1] # optional
19
+
20
+ BrpmAuto.log "Installing module #{module_name_or_path}#{module_version.nil? ? "" : " " + module_version}..."
21
+ module_installer = ModuleInstaller.new
22
+ module_installer.install_module(module_name_or_path, module_version)
18
23
 
19
- module_name = ARGV[0]
20
- module_version = ARGV[1] # optional
24
+ rescue Exception => e
25
+ BrpmAuto.log_error "#{e}"
26
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
21
27
 
22
- module_installer = ModuleInstaller.new
23
- module_installer.install_module(module_name, module_version)
28
+ raise e
29
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require "yaml"
3
+ require "brpm_auto"
4
+
5
+ params = {}
6
+ params["log_file"] = "/tmp/brpm_install.log"
7
+ params["also_log_to_console"] = "true"
8
+
9
+ begin
10
+ BrpmAuto.setup(params)
11
+
12
+ if ARGV.size < 2
13
+ BrpmAuto.log "Missing arguments."
14
+ BrpmAuto.log "Usage: \n brpm_uninstall <module name> <module version>"
15
+ end
16
+
17
+ module_name = ARGV[0]
18
+ module_version = ARGV[1] # optional
19
+
20
+ BrpmAuto.log "Uninstalling module #{module_name} #{module_version}..."
21
+ module_installer = ModuleInstaller.new
22
+ module_installer.uninstall_module(module_name, module_version)
23
+
24
+ rescue Exception => e
25
+ BrpmAuto.log_error "#{e}"
26
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
27
+
28
+ raise e
29
+ end
@@ -43,7 +43,7 @@ class MessagingProcessor < TorqueBox::Messaging::MessageProcessor
43
43
 
44
44
  rescue Exception => e
45
45
  BrpmAuto.log_error(e)
46
- BrpmAuto.log e.backtrace.join("\n\t")
46
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
47
47
  end
48
48
  end
49
49
  end
@@ -57,7 +57,7 @@ begin
57
57
 
58
58
  rescue Exception => e
59
59
  BrpmAuto.log_error(e)
60
- BrpmAuto.log e.backtrace.join("\n\t")
60
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
61
61
 
62
62
  raise e
63
63
  end
@@ -26,7 +26,7 @@ class EventProcessor < WEBrick::HTTPServlet::AbstractServlet
26
26
  response.body = "OK"
27
27
  rescue Exception => e
28
28
  BrpmAuto.log_error(e)
29
- BrpmAuto.log e.backtrace.join("\n\t")
29
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
30
30
  end
31
31
  end
32
32
  end
@@ -43,7 +43,7 @@ begin
43
43
  server.start
44
44
  rescue Exception => e
45
45
  BrpmAuto.log_error(e)
46
- BrpmAuto.log e.backtrace.join("\n\t")
46
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
47
47
 
48
48
  raise e
49
49
  end
@@ -220,7 +220,7 @@ class BrpmAuto
220
220
  @integration_settings = IntegrationSettings.new(dns, username, password, details)
221
221
  end
222
222
 
223
- def get_gems_root_path
223
+ def get_gems_root_path
224
224
  if ENV["BRPM_CONTENT_HOME"]
225
225
  ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
226
226
  elsif ENV["BRPM_HOME"]
@@ -21,7 +21,7 @@ class BrpmScriptExecutor
21
21
 
22
22
  rescue Exception => e
23
23
  BrpmAuto.log_error "#{e}"
24
- BrpmAuto.log e.backtrace.join("\n\t")
24
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
25
25
 
26
26
  raise e
27
27
  ensure
@@ -58,7 +58,7 @@ class BrpmScriptExecutor
58
58
 
59
59
  rescue Exception => e
60
60
  BrpmAuto.log_error "#{e}"
61
- BrpmAuto.log e.backtrace.join("\n\t")
61
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
62
62
 
63
63
  raise e
64
64
  ensure
@@ -91,7 +91,7 @@ class BrpmScriptExecutor
91
91
 
92
92
  rescue Exception => e
93
93
  BrpmAuto.log_error "#{e}"
94
- BrpmAuto.log e.backtrace.join("\n\t")
94
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
95
95
 
96
96
  raise e
97
97
  ensure
@@ -128,7 +128,7 @@ class BrpmScriptExecutor
128
128
 
129
129
  rescue Exception => e
130
130
  BrpmAuto.log_error "#{e}"
131
- BrpmAuto.log e.backtrace.join("\n\t")
131
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
132
132
 
133
133
  raise e
134
134
  ensure
@@ -1,21 +1,30 @@
1
+ require "rubygems"
2
+ require 'rubygems/package'
3
+ require 'rubygems/installer'
4
+ require "bundler"
5
+
1
6
  class ModuleInstaller
2
- def install_module(module_name, module_version)
3
- BrpmAuto.log "Installing module #{module_name} #{module_version.nil? ? "" : module_version}..."
7
+ def initialize
8
+ set_gem_home
9
+ end
10
+
11
+ def install_module(module_name_or_path, module_version = nil)
12
+ brpm_content_spec = nil
4
13
 
5
- if true #TODO: support non-gem-install mode
6
- specs = install_gem(module_name, module_version)
7
- module_spec = specs.find { |spec| spec.name == module_name}
14
+ if true #TODO: support no-gem-install mode
15
+ module_spec, specs = install_gem(module_name_or_path, module_version)
16
+
17
+ brpm_content_spec = specs.find { |spec| spec.name == "brpm_content" } if specs
8
18
 
9
19
  install_bundle_if_necessary(module_spec)
10
20
  else
11
- specs = [ Gem::Specification.find_by_name(module_name) ]
12
- module_spec = specs.find { |spec| spec.name == module_name}
21
+ module_name = module_name_or_path
22
+ module_spec = Gem::Specification.find_by_name(module_name)
13
23
  end
14
24
 
15
25
  if brpm_installed_locally?
16
26
  BrpmAuto.log "A BRPM instance is installed locally"
17
27
 
18
- brpm_content_spec = specs.find { |spec| spec.name == "brpm_content" }
19
28
  if brpm_content_spec
20
29
  if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?(get_symlink_path)
21
30
  BrpmAuto.log "Updating the symlink to brpm_content-latest..."
@@ -37,12 +46,63 @@ class ModuleInstaller
37
46
  BrpmAuto.log "Creating an automation category for #{module_friendly_name} if one doesn't exist yet..."
38
47
  create_automation_category_if_not_exists(module_friendly_name)
39
48
 
49
+ BrpmAuto.log "Retrieving the integration servers..."
50
+ integration_servers = @brpm_rest_client.get_project_servers
51
+
40
52
  BrpmAuto.log "Installing the automation script wrappers in the local BRPM instance..."
41
- install_auto_script_wrappers(module_spec.gem_dir, module_spec.name, module_friendly_name)
53
+ failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, automation_type|
54
+ BrpmAuto.log "Installing automation script wrapper for script #{auto_script_path}..."
55
+ install_auto_script_wrapper(auto_script_path, automation_type, module_spec.name, module_friendly_name, integration_servers)
56
+ end
57
+
58
+ if failed_scripts.size > 0
59
+ return false
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def uninstall_module(module_name, module_version)
66
+ if brpm_installed_locally?
67
+ BrpmAuto.log "A BRPM instance is installed locally"
68
+
69
+ BrpmAuto.log "Preparing the connectivity to BRPM..."
70
+ if prepare_brpm_connection
71
+ version_req = Gem::Requirement.create(Gem::Version.new(module_version))
72
+ module_spec = Gem::Specification.find_by_name(module_name, version_req)
73
+
74
+ module_friendly_name = get_module_friendly_name(module_spec)
75
+
76
+ 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, automation_type|
78
+ BrpmAuto.log "Uninstalling automation script wrapper for script #{auto_script_path}..."
79
+ uninstall_auto_script_wrapper(auto_script_path, automation_type, module_friendly_name)
80
+ end
81
+
82
+ if failed_scripts.size > 0
83
+ BrpmAuto.log "Aborting the uninstall."
84
+ return false
85
+ end
86
+
87
+ BrpmAuto.log "Deleting the automation category for #{module_friendly_name}..."
88
+ delete_automation_category(module_friendly_name)
42
89
  end
43
90
  end
91
+
92
+ BrpmAuto.log "Uninstalling module #{module_name}#{module_version.nil? ? "" : " " + module_version}..."
93
+ `gem uninstall #{module_name}#{module_version.nil? ? "" : " -v " + module_version}`
94
+
95
+ return true
44
96
  end
45
97
 
98
+ def module_installed?(module_name)
99
+ set_gem_home
100
+
101
+ Gem::Specification.find_all_by_name(module_name).size > 0
102
+ end
103
+
104
+ private
105
+
46
106
  def prepare_brpm_connection
47
107
  brpm_file = File.expand_path("~/.brpm")
48
108
 
@@ -73,25 +133,39 @@ class ModuleInstaller
73
133
  true
74
134
  end
75
135
 
76
- def install_gem(module_name, module_version)
136
+ def install_gem(module_name_or_path, module_version)
137
+ if module_name_or_path =~ /\.gem$/ and File.file? module_name_or_path
138
+ BrpmAuto.log "Installing gem #{module_name_or_path}#{module_version.nil? ? "" : " " + module_version} from file..."
139
+ source = Gem::Source::SpecificFile.new module_name_or_path
140
+ module_spec = source.spec
141
+
142
+ gem = source.download module_spec
143
+
144
+ inst = Gem::Installer.new gem
145
+ inst.install
146
+ BrpmAuto.log "Done."
147
+ else
148
+ BrpmAuto.log "Installing gem #{module_name_or_path}#{module_version.nil? ? "" : " " + module_version}..."
149
+ version_req = module_version ? Gem::Requirement.create(Gem::Version.new(module_version)) : Gem::Requirement.default
150
+ specs = Gem.install(module_name_or_path, version_req)
151
+
152
+ BrpmAuto.log "Installed gems:"
153
+ specs.each do |spec|
154
+ BrpmAuto.log " - #{spec.name} #{spec.version}"
155
+ end
156
+
157
+ module_spec = specs.find { |spec| spec.name == module_name_or_path}
158
+ end
159
+
160
+ return module_spec, specs
161
+ end
162
+
163
+ def set_gem_home
77
164
  if BrpmAuto.run_from_brpm or BrpmAuto.params.unit_test
78
165
  # we need to override the GEM_HOME env var, otherwise the gems will be installed in BRPM's own gemset
79
166
  ENV["GEM_HOME"] = BrpmAuto.get_gems_root_path
80
167
  Gem.paths = ENV
81
168
  end
82
-
83
- if module_version
84
- BrpmAuto.log "Executing command 'gem install #{module_name} -v #{module_version}'..."
85
- specs = Gem.install(module_name, module_version)
86
- else
87
- BrpmAuto.log "Executing command 'gem install #{module_name}'..."
88
- specs = Gem.install(module_name)
89
- end
90
- BrpmAuto.log "Installed gems:"
91
- specs.each do |spec|
92
- BrpmAuto.log " - #{spec.name} #{spec.version}"
93
- end
94
- specs
95
169
  end
96
170
 
97
171
  def install_bundle_if_necessary(spec)
@@ -141,7 +215,6 @@ class ModuleInstaller
141
215
  end
142
216
 
143
217
  def create_automation_error_if_not_exists(automation_error)
144
-
145
218
  list_item = @brpm_rest_client.get_list_item_by_name("AutomationErrors", automation_error)
146
219
 
147
220
  unless list_item
@@ -165,25 +238,30 @@ class ModuleInstaller
165
238
  end
166
239
  end
167
240
 
168
- def install_auto_script_wrappers(module_path, module_name, module_friendly_name)
169
- BrpmAuto.log "Retrieving the integration servers..."
170
- integration_servers = @brpm_rest_client.get_project_servers
241
+ def delete_automation_category(module_friendly_name)
242
+ #TODO: first check if there are any manually created automation scripts added to this automation category. If yes then dont delete it
243
+ list_item = @brpm_rest_client.get_list_item_by_name("AutomationCategory", module_friendly_name)
244
+
245
+ if list_item
246
+ @brpm_rest_client.archive_list_item(list_item["id"])
247
+ @brpm_rest_client.delete_list_item(list_item["id"])
248
+ end
249
+ end
171
250
 
251
+ def each_auto_script_wrapper(module_path)
172
252
  # For resource automations
173
253
  resource_automation_dir = "#{module_path}/resource_automations"
174
254
  resource_automation_script_paths = Dir.glob("#{resource_automation_dir}/*.rb")
175
255
 
176
256
  failed_scripts = []
177
257
  if resource_automation_script_paths.size > 0
178
- BrpmAuto.log "Installing the wrapper scripts for the resource automations..."
179
-
180
258
  resource_automation_script_paths.each do |auto_script_path|
181
259
  begin
182
- install_auto_script_wrapper(auto_script_path, "ResourceAutomation", module_name, module_friendly_name, integration_servers)
260
+ yield auto_script_path, "ResourceAutomation"
183
261
  rescue Exception => e
184
262
  failed_scripts << auto_script_path
185
263
  BrpmAuto.log_error(e)
186
- BrpmAuto.log e.backtrace.join("\n\t")
264
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
187
265
  end
188
266
  end
189
267
  end
@@ -193,38 +271,31 @@ class ModuleInstaller
193
271
  automation_script_paths = Dir.glob("#{automation_dir}/*.rb")
194
272
 
195
273
  if automation_script_paths.size > 0
196
- BrpmAuto.log "Installing the wrapper scripts for the automations..."
197
-
198
274
  automation_script_paths.each do |auto_script_path|
199
275
  begin
200
- install_auto_script_wrapper(auto_script_path, "Automation", module_name, module_friendly_name, integration_servers)
276
+ yield auto_script_path, "Automation"
201
277
  rescue Exception => e
202
278
  failed_scripts << auto_script_path
203
279
  BrpmAuto.log_error(e)
204
- BrpmAuto.log e.backtrace.join("\n\t")
280
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
205
281
  end
206
282
  end
207
283
  end
208
284
 
209
285
  if failed_scripts.size > 0
210
- BrpmAuto.log "The following wrapper scripts generated errors during the installation:"
286
+ BrpmAuto.log "The following wrapper scripts generated errors:"
211
287
  failed_scripts.each do |failed_script|
212
288
  BrpmAuto.log " - #{failed_script}"
213
289
  end
214
- else
215
- BrpmAuto.log "All wrapper scripts were installed successfully."
216
290
  end
291
+
292
+ failed_scripts
217
293
  end
218
294
 
219
295
  def install_auto_script_wrapper(auto_script_path, automation_type, module_name, module_friendly_name, integration_servers)
220
- auto_script_name = File.basename(auto_script_path, ".rb")
221
- BrpmAuto.log "Installing the wrapper script for resource automation #{auto_script_name}..."
222
-
223
- auto_script_config_path = "#{File.dirname(auto_script_path)}/#{auto_script_name}.meta"
296
+ auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
224
297
 
225
- auto_script_config_content = File.exists?(auto_script_config_path) ? File.read(auto_script_config_path) : ""
226
- auto_script_config = YAML.load(auto_script_config_content) || {}
227
- auto_script_config["params"] = {} unless auto_script_config["params"]
298
+ BrpmAuto.log "Installing the wrapper script for automation script #{auto_script_config["name"]} (friendly name: #{auto_script_config["friendly_name"]}, automation type: #{automation_type})..."
228
299
 
229
300
  if automation_type == "Automation"
230
301
  add_version_params(auto_script_config["params"])
@@ -256,33 +327,24 @@ class ModuleInstaller
256
327
  end
257
328
 
258
329
  wrapper_script_content += "\n"
259
- wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_name)
260
-
261
- if auto_script_config["automation_category"]
262
- automation_category = auto_script_config["automation_category"]
263
- create_automation_category_if_not_exists(automation_category)
264
-
265
- module_friendly_name = automation_category
266
- end
267
-
268
- auto_script_friendly_name = auto_script_config["friendly_name"] || "#{module_friendly_name} - #{auto_script_name.gsub("_", " ").capitalize}"
330
+ wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_config["name"])
269
331
 
270
332
  script = {}
271
- script["name"] = auto_script_friendly_name
333
+ script["name"] = auto_script_config["friendly_name"]
272
334
  script["description"] = auto_script_config["description"] || ""
273
335
  script["automation_type"] = automation_type
274
336
  script["automation_category"] = module_friendly_name
275
337
  script["content"] = wrapper_script_content
276
338
  script["integration_id"] = integration_server["id"] if auto_script_config["integration_server_type"] and integration_server
277
339
  if automation_type == "ResourceAutomation"
278
- script["unique_identifier"] = auto_script_config["resource_id"] || auto_script_name
340
+ script["unique_identifier"] = auto_script_config["resource_id"] || auto_script_config["name"]
279
341
  script["render_as"] = auto_script_config["render_as"] || "List"
280
342
  end
281
343
 
282
344
  script = @brpm_rest_client.create_or_update_script(script)
283
345
 
284
346
  if script["aasm_state"] == "draft"
285
- BrpmAuto.log "Updating the aasm_state of the script to 'pending'..."
347
+ BrpmAuto.log "Updating the aasm_state of the wrapper script to 'pending'..."
286
348
  script_to_update = {}
287
349
  script_to_update["id"] = script["id"]
288
350
  script_to_update["aasm_state"] = "pending"
@@ -290,7 +352,7 @@ class ModuleInstaller
290
352
  end
291
353
 
292
354
  if script["aasm_state"] == "pending"
293
- BrpmAuto.log "Updating the aasm_state of the script to 'released'..."
355
+ BrpmAuto.log "Updating the aasm_state of the wrapper script to 'released'..."
294
356
  script_to_update = {}
295
357
  script_to_update["id"] = script["id"]
296
358
  script_to_update["aasm_state"] = "released"
@@ -298,6 +360,53 @@ class ModuleInstaller
298
360
  end
299
361
  end
300
362
 
363
+ def uninstall_auto_script_wrapper(auto_script_path, automation_type, module_friendly_name)
364
+ auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
365
+
366
+ script = @brpm_rest_client.get_script_by_name(auto_script_config["friendly_name"])
367
+
368
+ unless script
369
+ BrpmAuto.log "Script #{auto_script_config["friendly_name"]} was not found, probably already deleted. Continuing."
370
+ return
371
+ end
372
+
373
+ if script["aasm_state"] == "released"
374
+ BrpmAuto.log "Updating the aasm_state of the wrapper script to 'retired'..."
375
+ script_to_update = {}
376
+ script_to_update["id"] = script["id"]
377
+ script_to_update["aasm_state"] = "retired"
378
+ script = @brpm_rest_client.update_script_from_hash(script_to_update)
379
+ end
380
+
381
+ if script["aasm_state"] == "retired"
382
+ BrpmAuto.log "Updating the aasm_state of the wrapper script to 'archived'..."
383
+ script_to_update = {}
384
+ script_to_update["id"] = script["id"]
385
+ script_to_update["aasm_state"] = "archived"
386
+ script = @brpm_rest_client.update_script_from_hash(script_to_update)
387
+ end
388
+
389
+ if script["aasm_state"] == "archived_state"
390
+ BrpmAuto.log "Deleting the wrapper script..."
391
+ @brpm_rest_client.delete_script(script["id"])
392
+ else
393
+ raise "Script #{auto_script_config["friendly_name"]} is not in aasm_state 'archived' so unable to delete it."
394
+ end
395
+ end
396
+
397
+ def get_auto_script_config(auto_script_path, module_friendly_name)
398
+ auto_script_name = File.basename(auto_script_path, ".rb")
399
+ auto_script_config_path = "#{File.dirname(auto_script_path)}/#{auto_script_name}.meta"
400
+
401
+ auto_script_config_content = File.exists?(auto_script_config_path) ? File.read(auto_script_config_path) : ""
402
+ auto_script_config = YAML.load(auto_script_config_content) || {}
403
+ auto_script_config["params"] = auto_script_config["params"] || {}
404
+ auto_script_config["name"] = File.basename(auto_script_path, ".rb")
405
+ auto_script_config["friendly_name"] = auto_script_config["friendly_name"] || "#{module_friendly_name} - #{auto_script_config["name"].gsub("_", " ").capitalize}"
406
+
407
+ auto_script_config
408
+ end
409
+
301
410
  def add_version_params(auto_script_params)
302
411
  include_position_attribute = false
303
412
  if auto_script_params.find { |_, param| param.has_key?("position") }
@@ -0,0 +1,42 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe 'Module installer' do
4
+ before(:all) do
5
+ create_brpm_file
6
+ setup_brpm_auto
7
+ end
8
+
9
+ before(:each) do
10
+ module_installer = ModuleInstaller.new
11
+
12
+ brpm_specs = Gem::Specification.find_all_by_name("brpm_module_brpm")
13
+
14
+ brpm_specs.each do |brpm_spec|
15
+ BrpmAuto.log "Module brpm_module_brpm (#{brpm_spec.version.to_s}) is already installed, uninstalling it..."
16
+ module_installer.uninstall_module("brpm_module_brpm", brpm_spec.version.to_s)
17
+ end
18
+ end
19
+
20
+ it 'should install the BRPM module from rubygems.org' do
21
+ module_installer = ModuleInstaller.new
22
+ module_installer.install_module("brpm_module_brpm")
23
+
24
+ expect{Gem::Specification.find_by_name("brpm_module_brpm")}.not_to raise_error #(Gem::LoadError)
25
+ end
26
+
27
+ it 'should install a specific version of the BRPM module from rubygems.org' do
28
+ module_installer = ModuleInstaller.new
29
+ module_installer.install_module("brpm_module_brpm", "0.1.29")
30
+
31
+ expect{Gem::Specification.find_by_name("brpm_module_brpm", Gem::Requirement.create(Gem::Version.new("0.1.29")))}.not_to raise_error #(Gem::LoadError)
32
+ end
33
+
34
+ it 'should install a BRPM module from a local gem file' do
35
+ `wget https://rubygems.org/downloads/brpm_module_brpm-0.1.29.gem` unless File.exists?("./brpm_module_brpm-0.1.29.gem")
36
+
37
+ module_installer = ModuleInstaller.new
38
+ module_installer.install_module("./brpm_module_brpm-0.1.29.gem")
39
+
40
+ expect{Gem::Specification.find_by_name("brpm_module_brpm", Gem::Requirement.create(Gem::Version.new("0.1.29")))}.not_to raise_error #(Gem::LoadError)
41
+ end
42
+ end
@@ -1,6 +1,8 @@
1
1
  require 'fileutils'
2
+ require 'yaml'
2
3
  require_relative "../brpm_auto"
3
4
 
5
+ FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/modules" if ENV["BRPM_HOME"]
4
6
  FileUtils.mkdir_p "/tmp/brpm_content"
5
7
 
6
8
  def setup_brpm_auto
@@ -9,7 +11,12 @@ end
9
11
 
10
12
  def get_default_params
11
13
  params = {}
14
+ params['unit_test'] = 'true'
12
15
  params['also_log_to_console'] = 'true'
16
+
17
+ params['brpm_url'] = 'http://brpm-content.pulsar-it.be:8088/brpm'
18
+ params['brpm_api_token'] = ENV["BRPM_API_TOKEN"]
19
+
13
20
  params['output_dir'] = "/tmp/brpm_content"
14
21
 
15
22
  params
@@ -40,3 +47,16 @@ def decrypt_string_with_prefix(input) # mocked method
40
47
 
41
48
  input.gsub("_encrypted", "")
42
49
  end
50
+
51
+ def create_brpm_file
52
+ unless File.exists?("~/.brpm")
53
+ params = get_default_params
54
+ brpm_params = {}
55
+ brpm_params["brpm_url"] = params["brpm_url"]
56
+ brpm_params["brpm_api_token"] = params["brpm_api_token"]
57
+
58
+ File.open(File.expand_path("~/.brpm"), "w") do |file|
59
+ file.puts(brpm_params.to_yaml)
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brpm_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.43
4
+ version: 0.1.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niek Bartholomeus
8
8
  autorequire:
9
9
  bindir: modules/framework/bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -100,6 +100,7 @@ description: The BRPM Content Framework is a lightweight framework that allows t
100
100
  email: niek.bartholomeus@gmail.com
101
101
  executables:
102
102
  - brpm_install
103
+ - brpm_uninstall
103
104
  - event_handler
104
105
  - webhook_receiver
105
106
  extensions: []
@@ -283,12 +284,12 @@ files:
283
284
  - modules/framework/automations/install_module.meta
284
285
  - modules/framework/automations/install_module.rb
285
286
  - modules/framework/bin/brpm_install
287
+ - modules/framework/bin/brpm_uninstall
286
288
  - modules/framework/bin/event_handler
287
289
  - modules/framework/bin/webhook_receiver
288
290
  - modules/framework/brpm_auto.rb
289
291
  - modules/framework/brpm_framework.rb
290
292
  - modules/framework/brpm_script_executor.rb
291
- - modules/framework/config.yml
292
293
  - modules/framework/config/customer_include.rb
293
294
  - modules/framework/config/server.yml
294
295
  - modules/framework/customer_include_default.rb
@@ -314,6 +315,7 @@ files:
314
315
  - modules/framework/tests/customer_include/config/server.yml
315
316
  - modules/framework/tests/customer_include_spec.rb
316
317
  - modules/framework/tests/local_jirb.rb
318
+ - modules/framework/tests/module_installer_spec.rb
317
319
  - modules/framework/tests/params_spec.rb
318
320
  - modules/framework/tests/request_params_spec.rb
319
321
  - modules/framework/tests/server_yaml_spec.rb
@@ -1,7 +0,0 @@
1
- version: 0.1.42
2
-
3
- author: Niek Bartholomeus
4
- email: niek.bartholomeus@gmail.com
5
- homepage: https://github.com/BMC-RLM/brpm_content
6
- summary: BRPM Content Framework
7
- description: The BRPM Content Framework is a lightweight framework that allows to run automation logic on top of BRPM in a modular, re-usable, testable and developer-friendly way