brpm_content_framework 0.1.59 → 0.1.60

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
- NzIzOTUzOTY3ZWU0NGUyYmY1NmFkNDg4MzE0Y2VmZTk5NWJlZDFhNA==
4
+ NjFmNjQ0NmMyOWM0ZTMwM2QxMmUwZGU1OTBhYzZmMTEzYzkwODcyYg==
5
5
  data.tar.gz: !binary |-
6
- ODUyN2Q0NGM1NzdiYjVmYTY2YzVhMThmNDJiMDg1ZWE4YmNmZWJmYg==
6
+ ODA4ODJlZmJiODhmODdjOTFlY2JhZDBmY2U5NDg1YTM4N2E4NzY5Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2Q3MmVkMWU0NTlkNzI2MTZkNTY3ZjZlYzQyZWI4M2VlNmFhNDliYTU2ZDU1
10
- MjE5Nzg5ZmZkZDdlOTkxNWRhOTVlZmQ0N2IxMzMxYzlmYjcxODE2OTNmNDMy
11
- ZjkzNzI5ODhiZDk3YmE0YmJjNjFkNzYxMjkyZjMyZTlkNWI2NDg=
9
+ MDI0OTM0NmQ2MjlmZmI2NWMzMTQ5NTI4NWE3Njc0YjI0YjMyMTkzMmI2MDkw
10
+ NzUyYTVkOWVkMjVjZGIyYmQyY2ZlODY1NDUyYjFhYjlhNzdiMWJlOGM1MzJh
11
+ OWFhOGE5YTlhYzdkN2U1MDlhMTkwNjQxMWJiZmY5ODc5MTgzNGQ=
12
12
  data.tar.gz: !binary |-
13
- MjY3ZWRmMTc3OTMzZGViODNlYzA2YjgxYWYzMjBlZGQ4NjQ5ZmUwNzEwNTkx
14
- YjljODQ2NzNjOTZjMDQzODQzODE0NTVkMDA4ZDU2MzZiNzU5ZWZjZjk2YjZi
15
- YWE5NTE2OWVkZDY5M2JlMzhmZDZiMjQ1NTk4YzM0ZDc4MmQ0MWI=
13
+ YjA4MWQxMDM0ZGQ4NjZiNGM0NGQ1OWM0MzE4NTYyZTNiZGUxOTAyYWM4M2Iz
14
+ NzM3NTVlN2YwNTkyYTdhMDQ5Nzk2ZDNlYzJjM2Y0OThjOTFhMTdjNjQyOTUz
15
+ NTQ4NjcwMmJkNDc1NmEwNjQzYWUxNGMzYjI1YjRhNjdlMDU2NDE=
data/config.yml CHANGED
@@ -1,8 +1,8 @@
1
- version: 0.1.59
1
+ version: 0.1.60
2
2
 
3
3
  author: Niek Bartholomeus
4
4
  email: niek.bartholomeus@gmail.com
5
- homepage: https://github.com/BMC-RLM/brpm_content
5
+ homepage: https://github.com/BMC-RLM/brpm_content_framework
6
6
  license: MIT
7
7
  summary: BRPM Content Framework
8
8
  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
@@ -7,6 +7,7 @@ class BrpmAuto
7
7
  class << self
8
8
  attr_reader :config
9
9
  attr_reader :version
10
+ attr_reader :brpm_version
10
11
  attr_reader :logger
11
12
  attr_reader :params
12
13
  attr_reader :request_params
@@ -30,6 +31,8 @@ class BrpmAuto
30
31
  @config = get_config
31
32
  @version = @config["version"]
32
33
 
34
+ @brpm_version = get_brpm_version if ENV["BRPM_HOME"]
35
+
33
36
  @gems_root_path = get_gems_root_path
34
37
  end
35
38
 
@@ -326,6 +329,12 @@ class BrpmAuto
326
329
  YAML.load_file("#{@framework_root_path}/config.yml")
327
330
  end
328
331
 
332
+ def get_brpm_version
333
+ knob = YAML.load_file("#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml")
334
+ version_content = File.read("#{knob["application"]["root"]}/VERSION")
335
+ version_content.scan(/VERSION=([0-9\.]*)/)[0][0]
336
+ end
337
+
329
338
  def get_module_gem_path(module_name, module_version)
330
339
  "#{@gems_root_path}/gems/#{module_name}-#{module_version}"
331
340
  end
@@ -76,7 +76,7 @@ class ModuleInstaller
76
76
  BrpmAuto.log "Uninstalling the automation script wrappers in the local BRPM instance..."
77
77
  failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, automation_type|
78
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)
79
+ uninstall_auto_script_wrapper(auto_script_path, module_friendly_name)
80
80
  end
81
81
 
82
82
  if failed_scripts.size > 0
@@ -281,6 +281,42 @@ class ModuleInstaller
281
281
  end
282
282
  end
283
283
 
284
+ if Gem::Version.new(BrpmAuto.brpm_version) >= Gem::Version.new("4.8")
285
+ # For Local Shell
286
+ automation_dir = "#{module_path}/automations"
287
+ automation_script_paths = Dir.glob("#{automation_dir}/*.sh")
288
+
289
+ if automation_script_paths.size > 0
290
+ automation_script_paths.each do |auto_script_path|
291
+ begin
292
+ yield auto_script_path, "Local Shell"
293
+ rescue Exception => e
294
+ failed_scripts << auto_script_path
295
+ BrpmAuto.log_error(e)
296
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ if Gem::Version.new(BrpmAuto.brpm_version) >= Gem::Version.new("4.8")
303
+ # For Remote Shell
304
+ automation_dir = "#{module_path}/remote_automations"
305
+ automation_script_paths = Dir.glob("#{automation_dir}/*.sh")
306
+
307
+ if automation_script_paths.size > 0
308
+ automation_script_paths.each do |auto_script_path|
309
+ begin
310
+ yield auto_script_path, "RemoteAutomation"
311
+ rescue Exception => e
312
+ failed_scripts << auto_script_path
313
+ BrpmAuto.log_error(e)
314
+ BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
315
+ end
316
+ end
317
+ end
318
+ end
319
+
284
320
  if failed_scripts.size > 0
285
321
  BrpmAuto.log "The following wrapper scripts generated errors:"
286
322
  failed_scripts.each do |failed_script|
@@ -294,12 +330,19 @@ class ModuleInstaller
294
330
  def install_auto_script_wrapper(auto_script_path, automation_type, module_name, module_friendly_name, integration_servers)
295
331
  auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
296
332
 
333
+ if automation_type == "RemoteAutomation"
334
+ automation_type = auto_script_config["automation_type"] || "Remote Shell"
335
+ end
336
+ automation_type == "ResourceAutomation" if automation_type == "Data Retriever"
337
+
297
338
  BrpmAuto.log "Installing the wrapper script for automation script #{auto_script_config["name"]} (friendly name: #{auto_script_config["friendly_name"]}, automation type: #{automation_type})..."
298
339
 
299
- if automation_type == "Automation"
340
+ if automation_type != "ResourceAutomation"
300
341
  add_version_params(auto_script_config["params"])
301
342
  end
302
343
 
344
+ automation_language = get_automation_language(automation_type)
345
+
303
346
  wrapper_script_content = ""
304
347
  if auto_script_config["params"].size > 0
305
348
  params_content = auto_script_config["params"].to_yaml
@@ -308,31 +351,45 @@ class ModuleInstaller
308
351
  wrapper_script_content = "###\n#{params_content}###\n"
309
352
  end
310
353
 
311
- integration_server = nil
312
- if auto_script_config["integration_server_type"]
313
- server_type_id = @brpm_rest_client.get_id_for_project_server_type(auto_script_config["integration_server_type"])
314
- if server_type_id
315
- integration_server = integration_servers.find { |integr_server| integr_server["server_name_id"] == server_type_id } #TODO: support multiple integration servers of same type (user should pick one)
316
- else
317
- integration_server = integration_servers.find { |integr_server| integr_server["name"].include?(auto_script_config["integration_server_type"]) } #TODO: support multiple integration servers of same type (user should pick one)
318
- end
354
+ if is_local_automation(automation_type)
355
+ integration_server = nil
356
+ if auto_script_config["integration_server_type"]
357
+ server_type_id = @brpm_rest_client.get_id_for_project_server_type(auto_script_config["integration_server_type"])
358
+ if server_type_id
359
+ integration_server = integration_servers.find { |integr_server| integr_server["server_name_id"] == server_type_id } #TODO: support multiple integration servers of same type (user should pick one)
360
+ else
361
+ integration_server = integration_servers.find { |integr_server| integr_server["name"].include?(auto_script_config["integration_server_type"]) } #TODO: support multiple integration servers of same type (user should pick one)
362
+ end
319
363
 
320
- if integration_server
321
- wrapper_script_content += "\n"
322
- wrapper_script_content += get_integration_server_template(integration_server["id"], integration_server["name"], auto_script_config["integration_server_type"])
323
- else
324
- BrpmAuto.log "WARNING - An integration server of type #{auto_script_config["integration_server_type"]} (or that has #{auto_script_config["integration_server_type"]} in its name if the integration server type is not supported) doesn't exist so not setting the integration server in the wrapper script."
364
+ if integration_server
365
+ wrapper_script_content += "\n"
366
+ wrapper_script_content += get_integration_server_template(integration_server["id"], integration_server["name"], auto_script_config["integration_server_type"], automation_language)
367
+ else
368
+ BrpmAuto.log "WARNING - An integration server of type #{auto_script_config["integration_server_type"]} (or that has #{auto_script_config["integration_server_type"]} in its name if the integration server type is not supported) doesn't exist so not setting the integration server in the wrapper script."
369
+ end
325
370
  end
326
371
  end
327
372
 
328
373
  wrapper_script_content += "\n"
329
- wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_config["name"])
374
+ case automation_type
375
+ when "Automation", "ResourceAutomation"
376
+ wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_config["name"])
377
+
378
+ when "Local Shell"
379
+ wrapper_script_content += "#{auto_script_path}\n"
380
+
381
+ when "Remote Shell", "Remote Dispatcher"
382
+ wrapper_script_content += File.read(auto_script_path)
383
+
384
+ end
330
385
 
331
386
  script = {}
332
387
  script["name"] = auto_script_config["friendly_name"]
333
388
  script["description"] = auto_script_config["description"] || ""
334
389
  script["automation_type"] = automation_type
335
390
  script["automation_category"] = module_friendly_name
391
+ script["agent_type"] = auto_script_config["agent_type"] if automation_type == "Remote Dispatcher" and auto_script_config["agent_type"]
392
+ script["os_type_ids"] = get_os_type_ids(auto_script_config["os_types"]) if automation_type == "Remote Shell" and auto_script_config["os_types"]
336
393
  script["content"] = wrapper_script_content
337
394
  script["integration_id"] = integration_server["id"] if auto_script_config["integration_server_type"] and integration_server
338
395
  if automation_type == "ResourceAutomation"
@@ -367,7 +424,7 @@ class ModuleInstaller
367
424
  end
368
425
  end
369
426
 
370
- def uninstall_auto_script_wrapper(auto_script_path, automation_type, module_friendly_name)
427
+ def uninstall_auto_script_wrapper(auto_script_path, module_friendly_name)
371
428
  auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
372
429
 
373
430
  script = @brpm_rest_client.get_script_by_name(auto_script_config["friendly_name"])
@@ -402,18 +459,49 @@ class ModuleInstaller
402
459
  end
403
460
 
404
461
  def get_auto_script_config(auto_script_path, module_friendly_name)
405
- auto_script_name = File.basename(auto_script_path, ".rb")
462
+ auto_script_name = File.basename(auto_script_path, ".*")
406
463
  auto_script_config_path = "#{File.dirname(auto_script_path)}/#{auto_script_name}.meta"
407
464
 
408
465
  auto_script_config_content = File.exists?(auto_script_config_path) ? File.read(auto_script_config_path) : ""
409
466
  auto_script_config = YAML.load(auto_script_config_content) || {}
467
+ auto_script_config["name"] = auto_script_name
410
468
  auto_script_config["params"] = auto_script_config["params"] || {}
411
- auto_script_config["name"] = File.basename(auto_script_path, ".rb")
412
469
  auto_script_config["friendly_name"] = auto_script_config["friendly_name"] || "#{module_friendly_name} - #{auto_script_config["name"].gsub("_", " ").capitalize}"
413
470
 
414
471
  auto_script_config
415
472
  end
416
473
 
474
+ def get_os_type_ids(os_types)
475
+ @os_type_map ||= { "200" => "Any", "201" => "Linux", "202" => "Windows" }
476
+ os_type_ids = []
477
+
478
+ os_types ||= ["Any"]
479
+
480
+ os_types.each do |os_type|
481
+ os_type_ids << @os_type_map.key(os_type)
482
+ end
483
+
484
+ os_type_ids
485
+ end
486
+
487
+ def is_local_automation(automation_type)
488
+ case automation_type
489
+ when "Automation", "Local Shell", "ResourceAutomation"
490
+ true
491
+ else
492
+ false
493
+ end
494
+ end
495
+
496
+ def get_automation_language(automation_type)
497
+ case automation_type
498
+ when "Automation", "ResourceAutomation"
499
+ "ruby"
500
+ else
501
+ "shell"
502
+ end
503
+ end
504
+
417
505
  def add_version_params(auto_script_params)
418
506
  include_position_attribute = false
419
507
  if auto_script_params.find { |_, param| param.has_key?("position") }
@@ -438,8 +526,10 @@ class ModuleInstaller
438
526
  auto_script_params["framework_version"] = framework_version_param
439
527
  end
440
528
 
441
- def get_integration_server_template(integration_server_id, integration_server_name, integration_server_type)
442
- <<EOR
529
+ def get_integration_server_template(integration_server_id, integration_server_name, integration_server_type, automation_language)
530
+ case automation_language
531
+ when "ruby"
532
+ <<EOR
443
533
  #=== #{integration_server_type} Integration Server: #{integration_server_name} ===#
444
534
  # [integration_id=#{integration_server_id}]
445
535
  #=== End ===#
@@ -449,6 +539,16 @@ params["SS_integration_username"] = SS_integration_username
449
539
  params["SS_integration_password_enc"] = SS_integration_password_enc
450
540
  params["SS_integration_details"] = YAML.load(SS_integration_details)
451
541
  EOR
542
+ when "shell"
543
+ <<EOR
544
+ #=== #{integration_server_type} Integration Server: #{integration_server_name} ===#
545
+ # [integration_id=#{integration_server_id}]
546
+ #=== End ===#
547
+ EOR
548
+ else
549
+ BrpmAuto.log "WARNING - automation language #{automation_language} is not supported"
550
+ ""
551
+ end
452
552
  end
453
553
 
454
554
  def get_script_executor_template(automation_type, module_name, auto_script_name)
@@ -1,18 +1,44 @@
1
- require_relative "spec_helper"
2
-
3
1
  describe 'Module installer' do
4
2
  before(:all) do
5
3
  raise "Module installation tests don't work under Bundler." if ENV["RUBYOPT"] and ENV["RUBYOPT"].include?("-rbundler/setup")
4
+ raise "$BRPM_HOME is not set" unless ENV["BRPM_HOME"]
6
5
 
6
+ brpm_version = "4.6.00.00"
7
7
  FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/modules"
8
+ FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments"
9
+ FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM"
10
+
11
+ knob=<<EOR
12
+ ---
13
+ application:
14
+ root: #{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM
15
+ environment:
16
+ RAILS_ENV: production
17
+ web:
18
+ context: /brpm
19
+ EOR
20
+
21
+ File.open("#{ENV["BRPM_HOME"]}/server/jboss/standalone/deployments/RPM-knob.yml", "w") do |file|
22
+ file.puts(knob)
23
+ end
24
+
25
+ version_content=<<EOR
26
+ $VERSION=#{brpm_version}
27
+ EOR
28
+
29
+ File.open("#{ENV["BRPM_HOME"]}/releases/#{brpm_version}/RPM/VERSION", "w") do |file|
30
+ file.puts(version_content)
31
+ end
32
+
33
+ require_relative "spec_helper"
8
34
 
9
35
  setup_brpm_auto
10
36
 
11
37
  BrpmAuto.log "Creating ~/.brpm file..."
12
38
  create_brpm_file
13
39
 
14
- @module_name = "brpm_module_bladelogic"
15
- @module_version = "0.1.22"
40
+ @module_name = "brpm_module_test"
41
+ @module_version = "0.1.3"
16
42
  end
17
43
 
18
44
  before(:each) do
@@ -28,21 +54,21 @@ describe 'Module installer' do
28
54
  end
29
55
  end
30
56
 
31
- it "should install #{@module_name} from rubygems.org" do
57
+ it "should install a module from rubygems.org" do
32
58
  module_installer = ModuleInstaller.new
33
59
  module_installer.install_module(@module_name)
34
60
 
35
61
  expect{Gem::Specification.find_by_name(@module_name)}.not_to raise_error #(Gem::LoadError)
36
62
  end
37
63
 
38
- it "should install a specific version of #{@module_name} from rubygems.org" do
64
+ it "should install a specific version of a module from rubygems.org" do
39
65
  module_installer = ModuleInstaller.new
40
66
  module_installer.install_module(@module_name, @module_version)
41
67
 
42
68
  expect{Gem::Specification.find_by_name(@module_name, Gem::Requirement.create(Gem::Version.new(@module_version)))}.not_to raise_error #(Gem::LoadError)
43
69
  end
44
70
 
45
- it "should install #{@module_name} from a local gem file" do
71
+ it "should install a module from a local gem file" do
46
72
  `mkdir -p temp && cd temp && wget https://rubygems.org/downloads/#{@module_name}-#{@module_version}.gem` unless File.exists?("temp/#{@module_name}-#{@module_version}.gem")
47
73
 
48
74
  module_installer = ModuleInstaller.new
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.59
4
+ version: 0.1.60
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-08-27 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -192,7 +192,7 @@ files:
192
192
  - transport/transport_baa.rb
193
193
  - transport/transport_nsh.rb
194
194
  - transport/transport_ssh.rb
195
- homepage: https://github.com/BMC-RLM/brpm_content
195
+ homepage: https://github.com/BMC-RLM/brpm_content_framework
196
196
  licenses:
197
197
  - MIT
198
198
  metadata: {}