brpm_content_framework 0.1.55
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 +15 -0
- data/.gitignore +38 -0
- data/.travis.yml +17 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +308 -0
- data/Rakefile +23 -0
- data/TO_BE_MIGRATED.txt +9 -0
- data/architecture.png +0 -0
- data/automations/direct_execute.meta +10 -0
- data/automations/direct_execute.rb +10 -0
- data/automations/install_module.meta +10 -0
- data/automations/install_module.rb +13 -0
- data/bin/brpm_install +30 -0
- data/bin/brpm_uninstall +30 -0
- data/bin/event_handler +63 -0
- data/bin/webhook_receiver +49 -0
- data/brpm_content.gemspec +31 -0
- data/config.yml +8 -0
- data/infrastructure/.bashrc +6 -0
- data/infrastructure/.brpm +2 -0
- data/infrastructure/config/customer_include.rb +26 -0
- data/infrastructure/config/server.yml +3 -0
- data/infrastructure/log.html +39 -0
- data/infrastructure/scripts/backup_database.sh +19 -0
- data/infrastructure/scripts/ddns.sh +10 -0
- data/infrastructure/scripts/install_brpm.sh +63 -0
- data/infrastructure/scripts/maintenance.sh +4 -0
- data/infrastructure/scripts/patch_brpm.sh +90 -0
- data/infrastructure/scripts/restore_database.sh +33 -0
- data/infrastructure/scripts/run_event_handler.cmd +19 -0
- data/infrastructure/scripts/run_event_handler.sh +20 -0
- data/infrastructure/scripts/run_webhook_receiver.cmd +15 -0
- data/infrastructure/scripts/run_webhook_receiver.sh +15 -0
- data/infrastructure/silent_install_options_4.6.txt +93 -0
- data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
- data/infrastructure/smtp_settings.rb +42 -0
- data/lib/brpm_auto.rb +358 -0
- data/lib/brpm_script_executor.rb +80 -0
- data/lib/logging/brpm_logger.rb +39 -0
- data/lib/logging/logger_base.rb +36 -0
- data/lib/logging/simple_logger.rb +27 -0
- data/lib/module_installer.rb +483 -0
- data/lib/params/all_params.rb +80 -0
- data/lib/params/integration_settings.rb +27 -0
- data/lib/params/params.rb +174 -0
- data/lib/params/params_base.rb +81 -0
- data/lib/params/request_params.rb +38 -0
- data/lib/rest_api.rb +155 -0
- data/lib/semaphore.rb +79 -0
- data/lib/utilities.rb +317 -0
- data/lib/version_control/git.rb +192 -0
- data/lib/version_control/svn.rb +221 -0
- data/lib/write_to.rb +1 -0
- data/tests/all_params_spec.rb +116 -0
- data/tests/brpm_auto_spec.rb +84 -0
- data/tests/customer_include/config/customer_include.rb +10 -0
- data/tests/customer_include/config/server.yml +3 -0
- data/tests/customer_include_spec.rb +29 -0
- data/tests/gemspec_spec.rb +11 -0
- data/tests/module_installer_spec.rb +46 -0
- data/tests/params_spec.rb +172 -0
- data/tests/request_params_spec.rb +86 -0
- data/tests/server_yaml_spec.rb +19 -0
- data/tests/spec_helper.rb +64 -0
- data/to_be_migrated/brpm_framework.rb +88 -0
- data/to_be_migrated/customer_include_default.rb +25 -0
- data/to_be_migrated/local_jirb.rb +15 -0
- data/to_be_migrated/resource_framework.rb +211 -0
- data/transport/dispatch_baa.rb +355 -0
- data/transport/dispatch_base.rb +345 -0
- data/transport/dispatch_nsh.rb +248 -0
- data/transport/dispatch_ssh.rb +154 -0
- data/transport/transport_baa.rb +1095 -0
- data/transport/transport_nsh.rb +359 -0
- data/transport/transport_ssh.rb +220 -0
- metadata +204 -0
@@ -0,0 +1,172 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe 'Params' do
|
4
|
+
before(:each) do
|
5
|
+
cleanup_request_params
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should get a param' do
|
9
|
+
input_params = get_default_params
|
10
|
+
input_params["key1"] = "value1"
|
11
|
+
|
12
|
+
BrpmAuto.setup(input_params)
|
13
|
+
params = BrpmAuto.params
|
14
|
+
|
15
|
+
expect(params).to have_key("key1")
|
16
|
+
expect(params["key1"]).to eql("value1")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should resolve a tokenized param' do
|
20
|
+
input_params = get_default_params
|
21
|
+
input_params["key1"] = "value1"
|
22
|
+
input_params["tokenized_key"] = "The value is rpm{key1}!"
|
23
|
+
|
24
|
+
BrpmAuto.setup(input_params)
|
25
|
+
params = BrpmAuto.params
|
26
|
+
|
27
|
+
expect(params).to have_key("tokenized_key")
|
28
|
+
expect(params["tokenized_key"]).to eql("The value is value1!")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should get a param via its dedicated method' do
|
32
|
+
input_params = get_default_params
|
33
|
+
input_params["request_id"] = "123456"
|
34
|
+
|
35
|
+
BrpmAuto.setup(input_params)
|
36
|
+
params = BrpmAuto.params
|
37
|
+
|
38
|
+
expect(params.request_id).to eql("123456")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should get the servers' do
|
42
|
+
input_params = get_default_params
|
43
|
+
|
44
|
+
input_params["server1000_name"] = "server1"
|
45
|
+
input_params["server1001_dns"] = "server1.com"
|
46
|
+
input_params["server1002_ip_address"] = "192.168.1.1"
|
47
|
+
input_params["server1003_os_platform"] = "linux"
|
48
|
+
|
49
|
+
input_params["server2000_name"] = "server2"
|
50
|
+
input_params["server2001_dns"] = "server2.com"
|
51
|
+
input_params["server2002_ip_address"] = "192.168.1.2"
|
52
|
+
input_params["server2003_os_platform"] = "linux"
|
53
|
+
|
54
|
+
BrpmAuto.setup(input_params)
|
55
|
+
params = BrpmAuto.params
|
56
|
+
|
57
|
+
expect(params.servers.count).to eql(2)
|
58
|
+
|
59
|
+
expect(params.servers).to have_key("server1")
|
60
|
+
|
61
|
+
expect(params.servers["server1"]).to have_key("dns")
|
62
|
+
expect(params.servers["server1"]["dns"]).to eql("server1.com")
|
63
|
+
expect(params.servers["server1"]).to have_key("ip_address")
|
64
|
+
expect(params.servers["server1"]["ip_address"]).to eql("192.168.1.1")
|
65
|
+
expect(params.servers["server1"]).to have_key("os_platform")
|
66
|
+
expect(params.servers["server1"]["os_platform"]).to eql("linux")
|
67
|
+
|
68
|
+
expect(params.servers).to have_key("server2")
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should get the servers by os platform' do
|
72
|
+
input_params = get_default_params
|
73
|
+
|
74
|
+
input_params["server1000_name"] = "server1"
|
75
|
+
input_params["server1003_os_platform"] = "linux"
|
76
|
+
|
77
|
+
input_params["server2000_name"] = "server2"
|
78
|
+
input_params["server2003_os_platform"] = "linux"
|
79
|
+
|
80
|
+
input_params["server3000_name"] = "server3"
|
81
|
+
input_params["server3003_os_platform"] = "windows"
|
82
|
+
|
83
|
+
BrpmAuto.setup(input_params)
|
84
|
+
params = BrpmAuto.params
|
85
|
+
|
86
|
+
linux_servers = params.get_servers_by_os_platform("linux")
|
87
|
+
expect(linux_servers.count).to eql(2)
|
88
|
+
|
89
|
+
windows_servers = params.get_servers_by_os_platform("windows")
|
90
|
+
expect(windows_servers.count).to eql(1)
|
91
|
+
|
92
|
+
windows_servers = params.get_servers_by_os_platform("xxx")
|
93
|
+
expect(windows_servers.count).to eql(0)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should get a server property' do
|
97
|
+
input_params = get_default_params
|
98
|
+
|
99
|
+
input_params["server1000_name"] = "server1"
|
100
|
+
input_params["server1003_property1"] = "value1"
|
101
|
+
|
102
|
+
BrpmAuto.setup(input_params)
|
103
|
+
params = BrpmAuto.params
|
104
|
+
|
105
|
+
expect(params.get_server_property("server1", "property1")).to eql("value1")
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should get an encrypted param' do
|
109
|
+
input_params = get_default_params
|
110
|
+
|
111
|
+
#trick it into thinking that it is run from BRPM
|
112
|
+
input_params["run_key"] = "123"
|
113
|
+
input_params["automation_results_dir"] = input_params["output_dir"]
|
114
|
+
input_params["request_id"] = "123"
|
115
|
+
input_params["step_id"] = "123"
|
116
|
+
|
117
|
+
input_params["key1_encrypt"] = "brpm_encrypted"
|
118
|
+
input_params["key2_enc"] = "brpm_encrypted"
|
119
|
+
|
120
|
+
BrpmAuto.setup(input_params)
|
121
|
+
params = BrpmAuto.params
|
122
|
+
|
123
|
+
expect(params["key1"]).to eql("brpm")
|
124
|
+
expect(params["key2"]).to eql("brpm")
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should get a param by the get method' do
|
128
|
+
input_params = get_default_params
|
129
|
+
input_params["key1"] = "value1"
|
130
|
+
|
131
|
+
BrpmAuto.setup(input_params)
|
132
|
+
params = BrpmAuto.params
|
133
|
+
|
134
|
+
expect(params.get("key1")).to eql("value1")
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should add a param by the add method' do
|
138
|
+
BrpmAuto.setup(get_default_params)
|
139
|
+
params = BrpmAuto.params
|
140
|
+
|
141
|
+
params.add("key1", "value1")
|
142
|
+
|
143
|
+
expect(params["key1"]).to eql("value1")
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should find or add a param' do
|
147
|
+
input_params = get_default_params
|
148
|
+
input_params["key1"] = "value1"
|
149
|
+
|
150
|
+
BrpmAuto.setup(input_params)
|
151
|
+
params = BrpmAuto.params
|
152
|
+
|
153
|
+
expect(params.find_or_add("key1", "value1-bis")).to eql("value1")
|
154
|
+
expect(params.count).to eql(input_params.count)
|
155
|
+
|
156
|
+
expect(params.find_or_add("key2", "value2")).to eql("value2")
|
157
|
+
expect(params.count).to eql(input_params.count + 1)
|
158
|
+
expect(params["key2"]).to eql("value2")
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should calculate the REST request id' do
|
162
|
+
input_params = get_default_params
|
163
|
+
input_params["request_id"] = "1234"
|
164
|
+
|
165
|
+
BrpmAuto.setup(input_params)
|
166
|
+
params = BrpmAuto.params
|
167
|
+
|
168
|
+
expect(params.rest_request_id).to eql("234")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe 'Request params' do
|
4
|
+
before(:each) do
|
5
|
+
cleanup_request_params
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should get a param' do
|
9
|
+
input_request_params = {}
|
10
|
+
input_request_params["key1"] = "value1"
|
11
|
+
set_request_params(input_request_params)
|
12
|
+
|
13
|
+
BrpmAuto.setup(get_default_params)
|
14
|
+
request_params = BrpmAuto.request_params
|
15
|
+
|
16
|
+
expect(request_params).to have_key("key1")
|
17
|
+
expect(request_params["key1"]).to eql("value1")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should resolve a tokenized param' do
|
21
|
+
input_request_params = {}
|
22
|
+
input_request_params["key1"] = "value1"
|
23
|
+
input_request_params["tokenized_key"] = "The value is rpm{key1}!"
|
24
|
+
set_request_params(input_request_params)
|
25
|
+
|
26
|
+
BrpmAuto.setup(get_default_params)
|
27
|
+
request_params = BrpmAuto.request_params
|
28
|
+
|
29
|
+
expect(request_params).to have_key("tokenized_key")
|
30
|
+
expect(request_params["tokenized_key"]).to eql("The value is value1!")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should get a param by the get method' do
|
34
|
+
input_request_params = {}
|
35
|
+
input_request_params["key1"] = "value1"
|
36
|
+
set_request_params(input_request_params)
|
37
|
+
|
38
|
+
BrpmAuto.setup(get_default_params)
|
39
|
+
request_params = BrpmAuto.request_params
|
40
|
+
|
41
|
+
expect(request_params).to have_key("key1")
|
42
|
+
expect(request_params.get("key1")).to eql("value1")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should add a param using []=' do
|
46
|
+
BrpmAuto.setup(get_default_params)
|
47
|
+
request_params = BrpmAuto.request_params
|
48
|
+
|
49
|
+
request_params["key1"] = "value1"
|
50
|
+
|
51
|
+
output_request_params = get_request_params
|
52
|
+
|
53
|
+
expect(output_request_params).to have_key("key1")
|
54
|
+
expect(output_request_params["key1"]).to eql("value1")
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should add a param by the add method' do
|
58
|
+
BrpmAuto.setup(get_default_params)
|
59
|
+
request_params = BrpmAuto.request_params
|
60
|
+
|
61
|
+
request_params.add("key1", "value1")
|
62
|
+
|
63
|
+
output_request_params = get_request_params
|
64
|
+
|
65
|
+
expect(output_request_params).to have_key("key1")
|
66
|
+
expect(output_request_params["key1"]).to eql("value1")
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should find or add a param' do
|
70
|
+
input_request_params = {}
|
71
|
+
input_request_params["key1"] = "value1"
|
72
|
+
set_request_params(input_request_params)
|
73
|
+
|
74
|
+
BrpmAuto.setup(get_default_params)
|
75
|
+
request_params = BrpmAuto.request_params
|
76
|
+
|
77
|
+
expect(request_params.find_or_add("key1", "value1-bis")).to eql("value1")
|
78
|
+
expect(request_params.count).to eql(1)
|
79
|
+
|
80
|
+
expect(request_params.find_or_add("key2", "value2")).to eql("value2")
|
81
|
+
expect(request_params.count).to eql(2)
|
82
|
+
expect(request_params["key2"]).to eql("value2")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe 'Server yaml' do
|
4
|
+
before(:each) do
|
5
|
+
cleanup_request_params
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should get the parameters' do
|
9
|
+
input_params = get_default_params
|
10
|
+
input_params["home_dir"] = "#{File.dirname(__FILE__)}/customer_include"
|
11
|
+
|
12
|
+
BrpmAuto.setup(input_params)
|
13
|
+
|
14
|
+
params = BrpmAuto.params
|
15
|
+
|
16
|
+
expect(params).to have_key("key2")
|
17
|
+
expect(params["key2"]).to eql("value2")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative "../lib/brpm_auto"
|
4
|
+
|
5
|
+
FileUtils.mkdir_p "#{ENV["BRPM_HOME"]}/modules" if ENV["BRPM_HOME"]
|
6
|
+
FileUtils.mkdir_p "/tmp/brpm_content"
|
7
|
+
|
8
|
+
def setup_brpm_auto
|
9
|
+
BrpmAuto.setup(get_default_params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_default_params
|
13
|
+
params = {}
|
14
|
+
params['unit_test'] = 'true'
|
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
|
+
|
20
|
+
params['output_dir'] = "/tmp/brpm_content"
|
21
|
+
|
22
|
+
params
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_request_params(request_params)
|
26
|
+
File.open("/tmp/brpm_content/request_data.json", "w") do |file|
|
27
|
+
file.puts(request_params.to_json)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_request_params
|
32
|
+
if File.exist?("/tmp/brpm_content/request_data.json")
|
33
|
+
json = File.read("/tmp/brpm_content/request_data.json")
|
34
|
+
JSON.parse(json)
|
35
|
+
else
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def cleanup_request_params
|
41
|
+
request_params_file = "/tmp/brpm_content/request_data.json"
|
42
|
+
File.delete(request_params_file) if File.exist?(request_params_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
def decrypt_string_with_prefix(input) # mocked method
|
46
|
+
return nil if input.nil? || !input.kind_of?(String)
|
47
|
+
|
48
|
+
input.gsub("_encrypted", "")
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_brpm_file
|
52
|
+
if File.exists?("~/.brpm")
|
53
|
+
FileUtils.rm("~/.brpm")
|
54
|
+
end
|
55
|
+
|
56
|
+
params = get_default_params
|
57
|
+
brpm_params = {}
|
58
|
+
brpm_params["brpm_url"] = params["brpm_url"]
|
59
|
+
brpm_params["brpm_api_token"] = params["brpm_api_token"]
|
60
|
+
|
61
|
+
File.open(File.expand_path("~/.brpm"), "w") do |file|
|
62
|
+
file.puts(brpm_params.to_yaml)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# = BRPM Automation Framework
|
2
|
+
# BMC Software - BJB 8/22/2014, BJB 9/17/14
|
3
|
+
# ==== A collection of classes to simplify building BRPM automation
|
4
|
+
# === Instructions
|
5
|
+
# In your BRPM automation include a block like this to pull in the library
|
6
|
+
# <tt> params["direct_execute"] = true #Set for local execution
|
7
|
+
# <tt> require @params["SS_automation_results_dir"].gsub("automation_results","persist/automation_lib/brpm_framework.rb")
|
8
|
+
require 'popen4'
|
9
|
+
require 'timeout'
|
10
|
+
require 'rest-client'
|
11
|
+
|
12
|
+
SleepDelay = [5,10,25,60] # Pattern for sleep pause in polling
|
13
|
+
RLM_BASE_PROPERTIES = ["SS_application", "SS_environment", "SS_component", "SS_component_version", "request_id", "step_name"]
|
14
|
+
KEYWORD_SWITCHES = ["RPM_PARAMS_FILTER","RPM_SRUN_WRAPPER","RPM_INCLUDE"] unless defined?(KEYWORD_SWITCHES)
|
15
|
+
FRAMEWORK_DIR = File.dirname(File.expand_path(__FILE__)) unless defined?(FRAMEWORK_DIR)
|
16
|
+
|
17
|
+
def rpm_load_module(*module_names)
|
18
|
+
result = ""
|
19
|
+
module_names.each do |mod_name|
|
20
|
+
user_load_path = defined?(CUSTOMER_LIB_DIR) ? "#{CUSTOMER_LIB_DIR}/lib/#{mod_name}" : nil
|
21
|
+
load_path = "#{FRAMEWORK_DIR}/lib/#{mod_name}"
|
22
|
+
transport_load_path = "#{FRAMEWORK_DIR}/transport/#{mod_name}"
|
23
|
+
if File.exist?("#{load_path}.rb")
|
24
|
+
require load_path
|
25
|
+
result += "success - #{load_path}\n"
|
26
|
+
elsif File.exist?("#{transport_load_path}.rb")
|
27
|
+
require transport_load_path
|
28
|
+
result += "success - #{load_path}\n"
|
29
|
+
elsif !user_load_path.nil? && File.exist?("#{user_load_path}.rb")
|
30
|
+
require user_load_path
|
31
|
+
result += "success - #{load_path}\n"
|
32
|
+
else
|
33
|
+
result += "ERROR - file not found #{load_path}\n"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_output
|
40
|
+
load "#{FRAMEWORK_DIR}/write_to.rb" if BrpmAuto.params.run_from_brpm
|
41
|
+
end
|
42
|
+
|
43
|
+
# == Initialization on Include
|
44
|
+
# Objects are set for most of the classes on requiring the file
|
45
|
+
# these will be available in the BRPM automation
|
46
|
+
# Customers should modify the BAA_BASE_PATH constant
|
47
|
+
# == Note the customer_include.rb reference. To add your own routines and override methods use this file.
|
48
|
+
customer_include_file = File.join(FRAMEWORK_DIR.gsub("/brpm_content/modules/framework", ""), "/customer_include.rb")
|
49
|
+
customer_include_file = File.join(CUSTOMER_LIB_DIR,"customer_include.rb") if defined?(CUSTOMER_LIB_DIR)
|
50
|
+
customer_include_file = File.join(FRAMEWORK_DIR,"customer_include_default.rb") if !File.exist?(customer_include_file)
|
51
|
+
|
52
|
+
conts = File.open(customer_include_file).read
|
53
|
+
eval conts # Use eval for resource automation to be dynamic
|
54
|
+
|
55
|
+
if @params.nil? || @params["SS_script_target"] == "resource_automation"
|
56
|
+
puts "Loading customer include file: #{customer_include_file}"
|
57
|
+
conts = File.open(File.join(File.dirname(FRAMEWORK_DIR),"brpm", "lib","resource_framework.rb")).read
|
58
|
+
eval conts
|
59
|
+
else
|
60
|
+
require "#{FRAMEWORK_DIR}/brpm_auto"
|
61
|
+
@rpm = BrpmAuto
|
62
|
+
@rpm.setup(@params)
|
63
|
+
@rpm.log "Loading customer include file: #{customer_include_file}"
|
64
|
+
if @params["SS_script_type"] != 'test' && @params["SS_script_target"] != "resource_automation" && !@params.has_key?("SS_no_framework")
|
65
|
+
automation_settings = @params["SS_script_support_path"].gsub("lib/script_support","config/automation_settings.rb")
|
66
|
+
require "#{automation_settings}" if File.exist?(automation_settings)
|
67
|
+
end
|
68
|
+
@request_params = {} if not defined?(@request_params)
|
69
|
+
SS_output_file = @params["SS_output_file"]
|
70
|
+
BrpmAuto.require_module("brpm")
|
71
|
+
@p = BrpmAuto.all_params
|
72
|
+
@request_params = BrpmAuto.request_params
|
73
|
+
ARG_PREFIX = "ARG_" unless defined?(ARG_PREFIX)
|
74
|
+
@rest = BrpmRest.new(@p.SS_base_url)
|
75
|
+
if @p.get("SS_skip_transport") == ""
|
76
|
+
#Load the transport for the step, transport follows environment property SS_transport
|
77
|
+
transport = @p.get("ss_transport")
|
78
|
+
if transport == ""
|
79
|
+
transport = @p.get("SS_transport", "nsh")
|
80
|
+
@p.assign_local_param("ss_transport", transport)
|
81
|
+
@p.find_or_add("SS_transport", transport)
|
82
|
+
@p.save_local_params
|
83
|
+
end
|
84
|
+
@rpm.log "Loading transport modules for: #{transport}"
|
85
|
+
res = rpm_load_module("transport_#{transport}", "dispatch_#{transport}")
|
86
|
+
@rpm.log res if res.include?("ERROR")
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# = BRPM Automation Framework
|
2
|
+
# == Customer Include Automation
|
3
|
+
# BMC Software - BJB 9/16/2014
|
4
|
+
# ===== Use this routine to override and provide global methods for all your automation
|
5
|
+
|
6
|
+
# set your own automation token
|
7
|
+
Token = "a56d64cbcffcce91d306670489fa4cf51b53316c" #"<YOUR_AUTOMATION_TOKEN>" #decrypt_string_with_prefix(@params["SS_api_token"])
|
8
|
+
# Hostname so nsh paths can be constructed from local paths
|
9
|
+
BAA_RPM_HOSTNAME = "localhost"
|
10
|
+
# Change this to set BAA base path
|
11
|
+
BAA_BASE_PATH = "/opt/bmc/bladelogic"
|
12
|
+
# This is the root path for use in BAA/BSA
|
13
|
+
BAA_BASE_GROUP = "BRPM"
|
14
|
+
# The location and name of the standard NSH script for script execution
|
15
|
+
BAA_FRAMEWORK_NSH_SCRIPT = "/BRPM/NSHScripts/FrameworkScriptExecute"
|
16
|
+
# This path will get any files staged by the framework
|
17
|
+
RPM_STAGING_PATH = "/opt/bmc/staging"
|
18
|
+
# This defines a path for a library of automations (from Git or Svn for instance)
|
19
|
+
ACTION_LIBRARY_PATH = "/opt/bmc/RLM/persist/script_library"
|
20
|
+
# Custom Lib/Module directory (to add customer content to framework)
|
21
|
+
CUSTOMER_LIB_DIR = "/opt/bmc/RLM/persist/brpm_lib"
|
22
|
+
# Place your own global constants
|
23
|
+
DATA_CENTER_NAMES = ["HOU", "LEX", "PUNE"]
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
rlm_base_path = "/Users/brady/Documents/dev_rpm/brpm_brady/brpm/branches/rpm-sustaining/Portal"
|
3
|
+
#rlm_base_path = "/opt/bmc/rlm4"
|
4
|
+
script_support = "#{rlm_base_path}/lib/script_support"
|
5
|
+
persist = "/Users/brady/Documents/dev_rpm/brpm_content/modules/framework"
|
6
|
+
FileUtils.cd script_support, :verbose => true
|
7
|
+
require "#{script_support}/ssh_script_header"
|
8
|
+
|
9
|
+
input_file = "#{rlm_base_path}/public/automation_results/request/Sales-Billing/1304/step_3722/sshinput_6_1433379304.txt"
|
10
|
+
|
11
|
+
script_params = params = load_input_params(input_file)
|
12
|
+
Token = "a56d64cbcffcce91d306670489fa4cf51b53316c"
|
13
|
+
|
14
|
+
require "#{persist}/brpm_framework.rb"
|
15
|
+
@rest = BrpmRest.new(@rpm.params.brpm_url)
|
@@ -0,0 +1,211 @@
|
|
1
|
+
|
2
|
+
module ResourceFramework
|
3
|
+
#DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
|
4
|
+
def create_request_params_file
|
5
|
+
request_data_file_dir = File.dirname(@params["SS_output_dir"])
|
6
|
+
request_data_file = "#{request_data_file_dir}/request_data.json"
|
7
|
+
fil = File.open(request_data_file,"w")
|
8
|
+
fil.puts "{\"request_data_file\":\"Created #{Time.now.strftime("%m/%d/%Y %H:%M:%S")}\"}"
|
9
|
+
fil.close
|
10
|
+
file_part = request_data_file[request_data_file.index("/automation_results")..255]
|
11
|
+
data_file_url = "#{@params["SS_base_url"]}#{file_part}"
|
12
|
+
write_to "Request Run Data: #{data_file_url}"
|
13
|
+
request_data_file
|
14
|
+
end
|
15
|
+
|
16
|
+
#DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
|
17
|
+
def init_request_params
|
18
|
+
request_data_file_dir = File.dirname(@params["SS_output_dir"])
|
19
|
+
request_data_file = "#{request_data_file_dir}/request_data.json"
|
20
|
+
sleep(2) unless File.exist?(request_data_file)
|
21
|
+
unless File.exist?(request_data_file)
|
22
|
+
create_request_params_file
|
23
|
+
end
|
24
|
+
file_part = request_data_file[request_data_file.index("/automation_results")..255]
|
25
|
+
data_file_url = "#{@params["SS_base_url"]}#{file_part}"
|
26
|
+
write_to "Request Run Data: #{data_file_url}"
|
27
|
+
request_data_file
|
28
|
+
end
|
29
|
+
|
30
|
+
#DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
|
31
|
+
def get_request_params
|
32
|
+
# Uses a json document in automation_results to store free-form information
|
33
|
+
cur = init_request_params
|
34
|
+
#message_box("Current Request Data","sep")
|
35
|
+
@request_params = JSON.parse(File.open(cur).read)
|
36
|
+
@request_params.each{ |k,v| write_to("#{k} => #{v.is_a?(String) ? v : v.inspect}") }
|
37
|
+
@orig_request_params = @request_params.dup
|
38
|
+
@request_params
|
39
|
+
end
|
40
|
+
|
41
|
+
#DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
|
42
|
+
def save_request_params
|
43
|
+
# Uses a json document in automation_results to store free-form information
|
44
|
+
cur = init_request_params
|
45
|
+
unless @orig_request_params == @request_params
|
46
|
+
sleep(2) unless File.exist?(cur)
|
47
|
+
fil = File.open(cur,"w+")
|
48
|
+
fil.write @request_params.to_json
|
49
|
+
fil.flush
|
50
|
+
fil.close
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#DEPRECATED: is this specific to a particular use case?
|
55
|
+
def default_table(other_rows = nil)
|
56
|
+
totalItems = 1
|
57
|
+
table_entries = [["#","Status","Information"]]
|
58
|
+
table_entries << ["1","Error", "Insufficient Data"] if other_rows.nil?
|
59
|
+
other_rows.each{|row| table_entries << row } unless other_rows.nil?
|
60
|
+
per_page=10
|
61
|
+
{:totalItems => totalItems, :perPage => per_page, :data => table_entries }
|
62
|
+
end
|
63
|
+
|
64
|
+
#DEPRECATED: what does this method do?
|
65
|
+
def default_list(msg)
|
66
|
+
result = [{msg => 0}]
|
67
|
+
select_hash = {}
|
68
|
+
result.unshift(select_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
#DEPRECATED: this functionality already exists, see modules/framework/lib/logger.rb
|
72
|
+
def log_it(it)
|
73
|
+
log_path = File.join(@params["SS_automation_results_dir"], "resource_logs")
|
74
|
+
txt = it.is_a?(String) ? it : it.inspect
|
75
|
+
write_to txt
|
76
|
+
Dir.mkdir(log_path) unless File.exist?(log_path)
|
77
|
+
s_handle = defined?(@script_name_handle) ? @script_name_handle : "rsc_output"
|
78
|
+
fil = File.open("#{log_path}/#{s_handle}_#{@params["SS_run_key"]}", "a")
|
79
|
+
fil.puts txt
|
80
|
+
fil.flush
|
81
|
+
fil.close
|
82
|
+
end
|
83
|
+
|
84
|
+
#DEPRECATED: OK - implemented it with a server.yml file instead (located in BRPM_HOME/config)
|
85
|
+
def load_customer_include(framework_dir)
|
86
|
+
customer_include_file = File.join(framework_dir, "customer_include.rb")
|
87
|
+
begin
|
88
|
+
if File.exist?(customer_include_file)
|
89
|
+
log_it "Loading customer include file: #{customer_include_file}"
|
90
|
+
eval(File.open(customer_include_file).read)
|
91
|
+
elsif File.exist customer_include_file = File.join(framework_dir,"customer_include_default.rb")
|
92
|
+
log_it "Loading default customer include file: #{customer_include_file}"
|
93
|
+
eval(File.open(customer_include_file).read)
|
94
|
+
end
|
95
|
+
rescue Exception => e
|
96
|
+
log_it "Error loading customer include: #{e.message}\n#{e.backtrace}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#DEPRECATED: what does this method do?
|
101
|
+
def hashify_list(list)
|
102
|
+
response = {}
|
103
|
+
list.each do |item,val|
|
104
|
+
response[val] = item
|
105
|
+
end
|
106
|
+
return [response]
|
107
|
+
end
|
108
|
+
|
109
|
+
#DEPRECATED: already implemented differently
|
110
|
+
def action_library_path
|
111
|
+
raise "Command_Failed: no library path defined, set property: ACTION_LIBRARY_PATH" if !defined?(ACTION_LIBRARY_PATH)
|
112
|
+
ACTION_LIBRARY_PATH
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
#DEPRECATED: what's the difference with the method with the same name from brpm_automation?
|
117
|
+
|
118
|
+
# Makes an http method call and returns data in JSON
|
119
|
+
#
|
120
|
+
# ==== Attributes
|
121
|
+
#
|
122
|
+
# * +url+ - the url for the request
|
123
|
+
# * +method+ - the http method [get, put, post]
|
124
|
+
# * +options+ - a hash of options
|
125
|
+
# +verbose+: gives verbose output (yes/no)
|
126
|
+
# +data+: required for put and post methods a hash of post data
|
127
|
+
# +username+: username for basic http authentication
|
128
|
+
# +password+: password for basic http authentication
|
129
|
+
# +suppress_errors+: continues after errors if true
|
130
|
+
#
|
131
|
+
# ==== Returns
|
132
|
+
#
|
133
|
+
# * returns a hash of the http response with these keys
|
134
|
+
# * +status+ - success or ERROR
|
135
|
+
# * +message+ - if status is ERROR this will hold an error message
|
136
|
+
# * +code+ - the http status code 200=ok, 404=not found, 500=error, 504=not authorized
|
137
|
+
# * +data+ - the body of the http response
|
138
|
+
def rest_call(url, method, options = {})
|
139
|
+
methods = %w{get post put}
|
140
|
+
result = {"status" => "ERROR", "response" => "", "message" => ""}
|
141
|
+
method = method.downcase
|
142
|
+
verbose = get_option(options, "verbose") == "yes" || get_option(options, "verbose")
|
143
|
+
headers = get_option(options, "headers", {:accept => :json, :content_type => :json})
|
144
|
+
return result["message"] = "ERROR - #{method} not recognized" unless methods.include?(method)
|
145
|
+
log "Rest URL: #{url}" if verbose
|
146
|
+
begin
|
147
|
+
data = get_option(options, "data")
|
148
|
+
rest_params = {}
|
149
|
+
rest_params[:url] = url
|
150
|
+
rest_params[:method] = method.to_sym
|
151
|
+
rest_params[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE if url.start_with?("https")
|
152
|
+
rest_params[:payload] = data.to_json unless data == ""
|
153
|
+
if options.has_key?("username") && options.has_key?("password")
|
154
|
+
rest_params[:user] = options["username"]
|
155
|
+
rest_params[:password] = options["password"]
|
156
|
+
end
|
157
|
+
rest_params[:headers] = headers
|
158
|
+
log "RestParams: #{rest_params.inspect}" if verbose
|
159
|
+
if %{put post}.include?(method)
|
160
|
+
return result["message"] = "ERROR - no data param for post" if data == ""
|
161
|
+
response = RestClient::Request.new(rest_params).execute
|
162
|
+
else
|
163
|
+
response = RestClient::Request.new(rest_params).execute
|
164
|
+
end
|
165
|
+
rescue Exception => e
|
166
|
+
result["message"] = e.message
|
167
|
+
raise "RestError: #{result["message"]}" unless get_option(options, "suppress_errors") == true
|
168
|
+
return result
|
169
|
+
end
|
170
|
+
log "Rest Response:\n#{response.inspect}" if verbose
|
171
|
+
if headers[:accept] == :json
|
172
|
+
parsed_response = JSON.parse(response) rescue nil
|
173
|
+
else
|
174
|
+
parsed_response = response
|
175
|
+
end
|
176
|
+
parsed_response = {"info" => "no data returned"} if parsed_response.nil?
|
177
|
+
result["code"] = response.code
|
178
|
+
if response.code < 300
|
179
|
+
result["status"] = "success"
|
180
|
+
result["data"] = parsed_response
|
181
|
+
elsif response.code == 422
|
182
|
+
result["message"] = "REST call returned code 422 usually a bad token"
|
183
|
+
else
|
184
|
+
result["message"] = "REST call returned HTTP code #{response.code}"
|
185
|
+
end
|
186
|
+
if result["status"] == "ERROR"
|
187
|
+
raise "RestError: #{result["message"]}" unless get_option(options, "suppress_errors") == true
|
188
|
+
end
|
189
|
+
result
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
#DEPRECATED: what's the difference with the method with the same name from brpm_automation?
|
194
|
+
|
195
|
+
# Provides a simple failsafe for working with hash options
|
196
|
+
# returns "" if the option doesn't exist or is blank
|
197
|
+
# ==== Attributes
|
198
|
+
#
|
199
|
+
# * +options+ - the hash
|
200
|
+
# * +key+ - key to find in options
|
201
|
+
# * +default_value+ - if entered will be returned if the option doesn't exist or is blank
|
202
|
+
def get_option(options, key, default_value = "")
|
203
|
+
result = options.has_key?(key) ? options[key] : nil
|
204
|
+
result = default_value if result.nil? || result == ""
|
205
|
+
result
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
extend ResourceFramework
|
211
|
+
|