brpm_content_framework 0.2.38 → 0.2.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/config.yml +1 -1
- data/docker/Dockerfile +3 -3
- data/infrastructure/scripts/publish_module_version.sh +9 -7
- data/lib/brpm_script_executor.rb +21 -24
- data/lib/module_installer.rb +27 -10
- data/lib/utilities.rb +27 -1
- data/tests/brpm_auto_spec.rb +31 -1
- data/tests/brpm_script_executor_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGJmYTgzYjZlNDBjMzYxODY3NDIwZWIxNDNlZmNhZDkzZDNlYmJiYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjkzY2VjNzZlMGU1NmM1MGU3YTgyMGY4NTU0YjI4NTA5YmZlNWUzZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjE3N2MyMTJjY2E0MWYwYmJmZWJjZDBlNTJlZjE2ZTU4ZDBiNjYyYTgzYTRj
|
10
|
+
MzYxN2JiN2NiYzA1Y2ZiZGUyYjYzN2U0ODgzMGE1NGZjNjc0YjljNjAyZjc0
|
11
|
+
MzM0NTljNjhlNjEzNGFhYjRiYmI0NDU5ODU1ZTU5OWM1OGQxMjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODJiOTk1YmRiM2IwNGM2MzM2Nzk0NDNmYjlmY2JlNTY1OGQ0OTJkMDNjNmRi
|
14
|
+
ZmY5NjAyMDA0YTM5YjQ5YWE0N2UxMjYwODk1ZGE4ZWJkNzFhMGY2N2JlYTFh
|
15
|
+
MGQzOWQ4YzczZjQ3Yzk4YTIxZDkyMmQzZjk3Njc1ODYwYTVhYmQ=
|
data/config.yml
CHANGED
data/docker/Dockerfile
CHANGED
@@ -4,10 +4,10 @@ MAINTAINER Niek Bartholomeus <niek.bartholomeus@gmail.com>
|
|
4
4
|
ENV BRPM_CONTENT_FRAMEWORK_VERSION 1.0.0
|
5
5
|
ENV GEM_HOME /usr/lib/ruby/gems/1.9.1
|
6
6
|
|
7
|
-
RUN gem install
|
8
|
-
cd
|
7
|
+
RUN gem install brpm_content_framework -v $BRPM_CONTENT_FRAMEWORK_VERSION && \
|
8
|
+
cd $GEM_HOME/gems/brpm_content_framework-$BRPM_CONTENT_FRAMEWORK_VERSION && \
|
9
9
|
bundle install && \
|
10
|
-
rm -rf
|
10
|
+
rm -rf $GEM_HOME/cache
|
11
11
|
|
12
12
|
ADD . /
|
13
13
|
|
@@ -12,7 +12,7 @@ fi
|
|
12
12
|
cd $(dirname $0)/../../../$MODULE_NAME
|
13
13
|
|
14
14
|
echo ""
|
15
|
-
echo ">>> Publishing
|
15
|
+
echo ">>> Publishing module $MODULE_NAME as a gem to rubygems.org..."
|
16
16
|
rake release
|
17
17
|
if [ -f "docker/Dockerfile" ]; then
|
18
18
|
MODULE_VERSION=$(eval "sed -n \"s=version: \(.*\)=\1=p\" config.yml")
|
@@ -27,17 +27,19 @@ if [ -f "docker/Dockerfile" ]; then
|
|
27
27
|
sed -i "" s/$OLD_MODULE_VERSION/$MODULE_VERSION/ Dockerfile
|
28
28
|
|
29
29
|
echo ""
|
30
|
-
echo ">>> Building
|
30
|
+
echo ">>> Building docker image bmcrlm/$MODULE_NAME:$MODULE_VERSION..."
|
31
31
|
docker build -t bmcrlm/$MODULE_NAME:$MODULE_VERSION . || { echo 'Aborting' ; exit 1; }
|
32
32
|
|
33
33
|
sed -i "" s/$MODULE_VERSION/$OLD_MODULE_VERSION/ Dockerfile
|
34
34
|
|
35
35
|
echo ""
|
36
|
-
echo ">>> Publishing
|
36
|
+
echo ">>> Publishing docker image bmcrlm/$MODULE_NAME:$MODULE_VERSION to the docker hub..."
|
37
37
|
docker push bmcrlm/$MODULE_NAME:$MODULE_VERSION || { echo 'Aborting' ; exit 1; }
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
if [[ "$MODULE_NAME" == brpm_content_framework ]]; then
|
40
|
+
echo ""
|
41
|
+
echo ">>> Tagging bmcrlm/$MODULE_NAME:$MODULE_VERSION as bmcrlm/$MODULE_NAME:latest..."
|
42
|
+
docker tag -f bmcrlm/$MODULE_NAME:$MODULE_VERSION bmcrlm/$MODULE_NAME:latest || { echo 'Aborting' ; exit 1; }
|
43
|
+
docker push bmcrlm/$MODULE_NAME:latest || { echo 'Aborting' ; exit 1; }
|
44
|
+
fi
|
43
45
|
fi
|
data/lib/brpm_script_executor.rb
CHANGED
@@ -35,8 +35,9 @@ class BrpmScriptExecutor
|
|
35
35
|
use_docker = true
|
36
36
|
when "if_docker_image_exists"
|
37
37
|
BrpmAuto.log "Checking if a docker image exists for bmcrlm/#{modul}:#{module_version}..."
|
38
|
-
|
39
|
-
|
38
|
+
_, _, _, status = BrpmAuto.execute_command("docker history -q bmcrlm/#{modul}:#{module_version}")
|
39
|
+
|
40
|
+
use_docker = status.success?
|
40
41
|
else
|
41
42
|
use_docker = false
|
42
43
|
end
|
@@ -48,19 +49,19 @@ class BrpmScriptExecutor
|
|
48
49
|
automation_results_path = params["SS_automation_results_dir"] || working_path
|
49
50
|
script_support_path = params["SS_script_support_path"] || working_path
|
50
51
|
|
52
|
+
params_for_process = params.clone # we don't want to modify the current session's params
|
51
53
|
if use_docker
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
params["SS_script_support_path"] = "/script_support"
|
54
|
+
params_for_process["SS_output_dir"] = "/workdir"
|
55
|
+
params_for_process["SS_output_file"] = params_for_process["SS_output_file"].sub(working_path, "/workdir") if params_for_process["SS_output_file"]
|
56
|
+
params_for_process["SS_automation_results_dir"] = "/automation_results"
|
57
|
+
params_for_process["SS_script_support_path"] = "/script_support"
|
57
58
|
|
58
|
-
|
59
|
+
params_for_process["log_file"] = params_for_process["log_file"].sub(working_path, "/workdir") if params_for_process["log_file"]
|
59
60
|
end
|
60
61
|
|
61
62
|
BrpmAuto.log "Temporarily storing the params to #{params_path}..."
|
62
63
|
File.open(params_path, "w") do |file|
|
63
|
-
file.puts(
|
64
|
+
file.puts(params_for_process.to_yaml)
|
64
65
|
end
|
65
66
|
|
66
67
|
if use_docker
|
@@ -71,7 +72,6 @@ class BrpmScriptExecutor
|
|
71
72
|
command += " \"#{offset}\"" if offset
|
72
73
|
command += " \"#{max_records}\"" if max_records
|
73
74
|
end
|
74
|
-
result = BrpmAuto.execute_shell(command)
|
75
75
|
|
76
76
|
else
|
77
77
|
env_var_gem_home = "export GEM_HOME=#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"};"
|
@@ -96,27 +96,24 @@ class BrpmScriptExecutor
|
|
96
96
|
end
|
97
97
|
|
98
98
|
BrpmAuto.log "Executing the script in a separate process..."
|
99
|
-
|
99
|
+
ruby_command = <<EOR
|
100
100
|
#{require_bundler}
|
101
101
|
require \\"brpm_script_executor\\"
|
102
102
|
BrpmScriptExecutor.execute_automation_script_from_other_process(\\"#{modul}\\", \\"#{name}\\", \\"#{params_path}\\", \\"#{automation_type}\\", \\"#{parent_id}\\", \\"#{offset}\\", \\"#{max_records}\\")
|
103
103
|
EOR
|
104
|
-
|
104
|
+
command = "#{env_var_gem_home}#{env_var_bundler}ruby -e \"#{ruby_command}\""
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
if result["stdout"] and !result["stdout"].empty?
|
111
|
-
BrpmAuto.log "stdout of the executed process:"
|
112
|
-
BrpmAuto.log "-----------------------------------------------------------"
|
113
|
-
BrpmAuto.log result["stdout"]
|
114
|
-
BrpmAuto.log "-----------------------------------------------------------"
|
107
|
+
_, stderr, _, status = Bundler.with_clean_env do
|
108
|
+
BrpmAuto.execute_command(command) do |stdout_err|
|
109
|
+
BrpmAuto.log " #{stdout_err.chomp}"
|
115
110
|
end
|
116
|
-
|
117
|
-
raise result["stderr"]
|
118
111
|
end
|
119
112
|
|
113
|
+
FileUtils.rm(params_path) if File.exists?(params_path)
|
114
|
+
|
115
|
+
raise "The process failed with status #{status.exitstatus}.\n#{stderr}" unless status.success?
|
116
|
+
|
120
117
|
if automation_type == "resource_automation"
|
121
118
|
result_path = params_path.sub!("params", "result")
|
122
119
|
BrpmAuto.log "Loading the result from #{result_path} and cleaning it up..."
|
@@ -139,11 +136,11 @@ EOR
|
|
139
136
|
def execute_automation_script_from_other_process(modul, name, params_file, automation_type, parent_id = nil, offset = nil, max_records = nil)
|
140
137
|
raise "Params file #{params_file} doesn't exist." unless File.exists?(params_file)
|
141
138
|
|
142
|
-
puts "
|
139
|
+
puts "Loading the params from #{params_file} and cleaning it up..."
|
143
140
|
params = YAML.load_file(params_file)
|
144
141
|
FileUtils.rm(params_file)
|
145
142
|
|
146
|
-
puts "
|
143
|
+
puts "Setting up the BRPM Content framework..."
|
147
144
|
BrpmAuto.setup(params)
|
148
145
|
BrpmAuto.log " BRPM Content framework is version #{BrpmAuto.version}."
|
149
146
|
|
data/lib/module_installer.rb
CHANGED
@@ -83,8 +83,13 @@ class ModuleInstaller
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
remove_docker_image(module_name, module_version)
|
87
|
+
|
86
88
|
BrpmAuto.log "Uninstalling gem #{module_name} #{module_version}..."
|
87
|
-
BrpmAuto.
|
89
|
+
_, stderr, _, status = BrpmAuto.execute_command("gem uninstall #{module_name} -v #{module_version} -x") do |stdout_err|
|
90
|
+
BrpmAuto.log " #{stdout_err.chomp}"
|
91
|
+
end
|
92
|
+
raise "The process failed with status #{status.exitstatus}.\n#{stderr}" unless status.success?
|
88
93
|
|
89
94
|
true
|
90
95
|
end
|
@@ -156,24 +161,25 @@ class ModuleInstaller
|
|
156
161
|
if File.exists?(gemfile_path)
|
157
162
|
command = "cd #{spec.gem_dir}; bundle install"
|
158
163
|
BrpmAuto.log "Found a Gemfile so executing command '#{command}'..."
|
159
|
-
|
164
|
+
_, stderr, _, status = BrpmAuto.execute_command(command) do |stdout_err|
|
165
|
+
BrpmAuto.log " #{stdout_err.chomp}"
|
166
|
+
end
|
167
|
+
raise "The process failed with status #{status.exitstatus}.\n#{stderr}" unless status.success?
|
160
168
|
else
|
161
169
|
BrpmAuto.log "This module doesn't have a Gemfile."
|
162
170
|
end
|
163
|
-
|
164
|
-
BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
|
165
|
-
unless result["status"] == 0
|
166
|
-
raise result["stderr"]
|
167
|
-
end
|
168
171
|
end
|
169
172
|
|
170
173
|
def pull_docker_image(spec)
|
171
174
|
case BrpmAuto.global_params["execute_automation_scripts_in_docker"]
|
172
175
|
when "always", "if_docker_image_exists"
|
173
176
|
BrpmAuto.log "Pulling the docker image from the Docker Hub..."
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
+
stdout, stderr, _, status = BrpmAuto.execute_command("docker pull bmcrlm/#{spec.name}:#{spec.version}") do |stdout_err|
|
178
|
+
BrpmAuto.log " #{stdout_err.chomp}"
|
179
|
+
end
|
180
|
+
raise "The process failed with status #{status.exitstatus}.\n#{stderr}" unless status.success?
|
181
|
+
|
182
|
+
unless stdout =~ /Image is up to date for/ or output =~ /Downloaded newer image for/
|
177
183
|
if BrpmAuto.global_params["execute_automation_scripts_in_docker"] == "always"
|
178
184
|
raise "Docker image bmcrlm/#{spec.name}:#{spec.version} doesn't exist."
|
179
185
|
elsif BrpmAuto.global_params["execute_automation_scripts_in_docker"] == "if_docker_image_exists"
|
@@ -183,6 +189,17 @@ class ModuleInstaller
|
|
183
189
|
end
|
184
190
|
end
|
185
191
|
|
192
|
+
def remove_docker_image(module_name, module_version)
|
193
|
+
case BrpmAuto.global_params["execute_automation_scripts_in_docker"]
|
194
|
+
when "always", "if_docker_image_exists"
|
195
|
+
BrpmAuto.log "Removing the docker image..."
|
196
|
+
_, stderr, _, status = BrpmAuto.execute_command("docker rmi $(docker images | grep bmcrlm/#{module_name}:#{module_version} | awk {'print $3'})") do |stdout_err|
|
197
|
+
BrpmAuto.log " #{stdout_err.chomp}"
|
198
|
+
end
|
199
|
+
raise "The process failed with status #{status.exitstatus}.\n#{stderr}" unless status.success?
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
186
203
|
def get_symlink_path
|
187
204
|
"#{ENV["GEM_HOME"]}/gems/brpm_content_framework-latest"
|
188
205
|
end
|
data/lib/utilities.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Utilities
|
2
|
-
|
3
4
|
EXIT_CODE_FAILURE = 'Exit_Code_Failure'
|
4
5
|
Windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) unless defined?(Windows)
|
5
6
|
|
@@ -77,6 +78,31 @@ module Utilities
|
|
77
78
|
cmd_result
|
78
79
|
end
|
79
80
|
|
81
|
+
def execute_command(command, sensitive_data = nil)
|
82
|
+
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
83
|
+
logs = {:out => "", :err => ""}
|
84
|
+
|
85
|
+
if block_given?
|
86
|
+
{ :out => stdout, :err => stderr }.each do |key, stream|
|
87
|
+
Thread.new do
|
88
|
+
while line = stream.gets
|
89
|
+
privatized_line = BrpmAuto.privatize(line, sensitive_data)
|
90
|
+
logs[key] += privatized_line
|
91
|
+
yield privatized_line
|
92
|
+
end
|
93
|
+
end if block_given?
|
94
|
+
end
|
95
|
+
|
96
|
+
thread.join
|
97
|
+
else
|
98
|
+
logs[:out] = stdout.read
|
99
|
+
logs[:err] = stderr.read
|
100
|
+
end
|
101
|
+
|
102
|
+
return logs[:out], logs[:err], thread.pid, thread.value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
80
106
|
# Returns a timestamp to the thousanth of a second
|
81
107
|
#
|
82
108
|
# ==== Returns
|
data/tests/brpm_auto_spec.rb
CHANGED
@@ -71,7 +71,7 @@ describe 'BRPM automation framework' do
|
|
71
71
|
result = BrpmAuto.execute_shell("echo Hello")
|
72
72
|
|
73
73
|
expect(result["status"]).to eql(0)
|
74
|
-
expect(result["stdout"]).to eql("Hello
|
74
|
+
expect(result["stdout"].chomp).to eql("Hello")
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should return with a non-zero status when passing a bad command' do
|
@@ -80,6 +80,36 @@ describe 'BRPM automation framework' do
|
|
80
80
|
expect(result["status"]).not_to eql(0)
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe 'execute_shell_stream_logs' do
|
85
|
+
it 'should execute a command successfully' do
|
86
|
+
stdout, _, _, status = BrpmAuto.execute_command("echo Hello")
|
87
|
+
|
88
|
+
expect(status.success?).to be_truthy
|
89
|
+
expect(stdout.chomp).to eql("Hello")
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should execute a command successfully and stream the stdout' do
|
93
|
+
streamed_logs = ""
|
94
|
+
_, _, _, status = BrpmAuto.execute_command("echo Hello") do |stdout_err|
|
95
|
+
streamed_logs += stdout_err
|
96
|
+
end
|
97
|
+
|
98
|
+
expect(status.success?).to be_truthy
|
99
|
+
expect(streamed_logs.chomp).to eql("Hello")
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should return with a non-zero status when passing a command that raises an exception and stream the stderr' do
|
103
|
+
_, stderr, _, status = BrpmAuto.execute_command("ruby -e \"raise 'Boom'\"")
|
104
|
+
|
105
|
+
expect(status.success?).to be_falsey
|
106
|
+
expect(stderr.chomp).to eql("-e:1:in `<main>': Boom (RuntimeError)")
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should return with a non-zero status when passing a bad command' do
|
110
|
+
expect { BrpmAuto.execute_command("xxxx") }.to raise_exception
|
111
|
+
end
|
112
|
+
end
|
83
113
|
end
|
84
114
|
|
85
115
|
|
@@ -45,7 +45,7 @@ describe 'BRPM Script Executor' do
|
|
45
45
|
module_gem_path = BrpmScriptExecutor.get_module_gem_path(@module_name, module_version)
|
46
46
|
gemfile_path = "#{module_gem_path}/Gemfile"
|
47
47
|
|
48
|
-
FileUtils.move(gemfile_path, "#{gemfile_path}_tmp")
|
48
|
+
FileUtils.move(gemfile_path, "#{gemfile_path}_tmp") if File.exists?(gemfile_path)
|
49
49
|
result = BrpmScriptExecutor.execute_automation_script_in_separate_process(@module_name, "test_ruby", get_default_params)
|
50
50
|
FileUtils.move("#{gemfile_path}_tmp", gemfile_path)
|
51
51
|
|
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.2.
|
4
|
+
version: 0.2.39
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niek Bartholomeus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|