razorrisk-razor-control 0.1
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 +7 -0
- data/RakeFile +46 -0
- data/lib/razor_risk/razor/control/cucumber_helpers/consolidate_reports.rb +80 -0
- data/lib/razor_risk/razor/control/cucumber_helpers/executor.rb +108 -0
- data/lib/razor_risk/razor/control/cucumber_helpers.rb +3 -0
- data/lib/razor_risk/razor/control/diagnostics/util_functions.rb +203 -0
- data/lib/razor_risk/razor/control/diagnostics/zeroth_include.rb +27 -0
- data/lib/razor_risk/razor/control/exceptions.rb +121 -0
- data/lib/razor_risk/razor/control/gem/gem_helpers.rb +397 -0
- data/lib/razor_risk/razor/control/rake_helpers/aborter.rb +90 -0
- data/lib/razor_risk/razor/control/rake_helpers/diagnostic_tasks.rb +74 -0
- data/lib/razor_risk/razor/control/rake_helpers/gem_tasks.rb +128 -0
- data/lib/razor_risk/razor/control/rake_helpers/razor_tasks.rb +195 -0
- data/lib/razor_risk/razor/control/rake_helpers/task_helpers.rb +86 -0
- data/lib/razor_risk/razor/control/rake_helpers.rb +3 -0
- data/lib/razor_risk/razor/control/razor/executor.rb +131 -0
- data/lib/razor_risk/razor/control/razor/razor_instance.rb +227 -0
- data/lib/razor_risk/razor/control/razor.rb +2 -0
- data/lib/razor_risk/razor/control/version.rb +41 -0
- data/test/unit/control/cucumber_helpers/reports/expected/groups.html +213 -0
- data/test/unit/control/cucumber_helpers/reports/expected/no_groups.html +170 -0
- data/test/unit/control/cucumber_helpers/reports/groups/LbbwConfig/LbbwConfig.json +69 -0
- data/test/unit/control/cucumber_helpers/reports/groups/StandardConfig/StandardConfig.json +69 -0
- data/test/unit/control/cucumber_helpers/reports/no_groups/LbbwConfig.json +69 -0
- data/test/unit/control/cucumber_helpers/reports/no_groups/StandardConfig/StandardConfig.json +69 -0
- data/test/unit/control/cucumber_helpers/tc_consolidate_reports.rb +73 -0
- data/test/unit/control/cucumber_helpers/tc_executor.rb +406 -0
- data/test/unit/control/gem/tc_gem_helpers.rb +405 -0
- data/test/unit/control/rake_helpers/tc_aborter.rb +131 -0
- data/test/unit/control/rake_helpers/tc_task_helpers.rb +228 -0
- data/test/unit/control/razor/tc_executor.rb +129 -0
- data/test/unit/control/razor/tc_razor_instance.rb +517 -0
- data/test/unit/control/razor/test_scripts/exit_failure.cmd +3 -0
- data/test/unit/control/razor/test_scripts/exit_strange.cmd +3 -0
- data/test/unit/control/razor/test_scripts/exit_success.cmd +3 -0
- data/test/unit/control/razor/test_scripts/pause.cmd +5 -0
- data/test/unit/control/razor/test_scripts/print.cmd +6 -0
- data/test/unit/control/tc_exceptions.rb +120 -0
- metadata +192 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Rakefile for Razor Risk Razor Control library.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
|
12
|
+
# ##########################################################
|
13
|
+
# requires
|
14
|
+
|
15
|
+
require 'razor_risk/razor/control/razor'
|
16
|
+
require 'razor_risk/razor/control/rake_helpers/aborter'
|
17
|
+
require 'razor_risk/core/diagnostics/logger'
|
18
|
+
|
19
|
+
require 'pantheios'
|
20
|
+
require 'xqsr3/quality/parameter_checking'
|
21
|
+
|
22
|
+
require 'rake'
|
23
|
+
|
24
|
+
module RazorRisk
|
25
|
+
module Razor
|
26
|
+
module Control
|
27
|
+
module RakeHelpers
|
28
|
+
|
29
|
+
# Rake tasks for controlling a Razor instance.
|
30
|
+
module RazorTasks
|
31
|
+
|
32
|
+
extend ::Rake::DSL
|
33
|
+
|
34
|
+
include ::RazorRisk::Razor::Control
|
35
|
+
include ::RazorRisk::Razor::Control::Exceptions
|
36
|
+
|
37
|
+
include ::Pantheios
|
38
|
+
include ::Xqsr3::Quality::ParameterChecking
|
39
|
+
|
40
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
41
|
+
|
42
|
+
# ##########################################################
|
43
|
+
# Constants
|
44
|
+
|
45
|
+
# Default config to include for all Razor instances.
|
46
|
+
DefaultConfig = Razor::Config.new(
|
47
|
+
'StandardConfig',
|
48
|
+
'config/StandardConfig',
|
49
|
+
'config',
|
50
|
+
'1_start.cmd',
|
51
|
+
'4_rebuild.cmd',
|
52
|
+
)
|
53
|
+
|
54
|
+
|
55
|
+
# ##########################################################
|
56
|
+
# variables
|
57
|
+
|
58
|
+
razor_instance = nil
|
59
|
+
|
60
|
+
|
61
|
+
# ##########################################################
|
62
|
+
# tasks
|
63
|
+
|
64
|
+
namespace :razor do
|
65
|
+
|
66
|
+
# Initializes the Razor insance.
|
67
|
+
#
|
68
|
+
# @param directory [::String] The path to the Razor instance.
|
69
|
+
# @param environment [::String] The Razor instance environment.
|
70
|
+
# @param configs [Array<Razor::Config>] An array of configs available in
|
71
|
+
# the razor instance.
|
72
|
+
#
|
73
|
+
task :init_instance, [ :directory, :environment, :configs ] do |task, args|
|
74
|
+
|
75
|
+
trace ParamNames[ :task, :args ], task, args
|
76
|
+
|
77
|
+
configs = [ args[:configs], DefaultConfig ].flatten.compact
|
78
|
+
|
79
|
+
begin
|
80
|
+
razor_instance = Razor::RazorInstance.new(
|
81
|
+
args[:directory],
|
82
|
+
args[:environment],
|
83
|
+
configs,
|
84
|
+
)
|
85
|
+
rescue RazorControlException => x
|
86
|
+
abort x.message
|
87
|
+
end
|
88
|
+
|
89
|
+
# Ensure that razor is always stopped if initialized.
|
90
|
+
RakeHelpers::RakeAborter.abort_hook do
|
91
|
+
log :critical, 'Aborting: Killing Razor'
|
92
|
+
::Rake::Task[:'razor:kill'].invoke
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Kills the running Razor instance.
|
97
|
+
#
|
98
|
+
task :kill do |task|
|
99
|
+
|
100
|
+
trace ParamNames[ :task ], task
|
101
|
+
|
102
|
+
log :informational, "Killing Razor '#{razor_instance.environment}'"
|
103
|
+
|
104
|
+
begin
|
105
|
+
status = razor_instance.kill
|
106
|
+
rescue RazorControlException => x
|
107
|
+
abort x.message
|
108
|
+
end
|
109
|
+
|
110
|
+
abort "Failed to kill Razor isntance '#{razor_instance.environment}'" unless status
|
111
|
+
|
112
|
+
task.reenable
|
113
|
+
end
|
114
|
+
|
115
|
+
# Rebuilds the Razor instance to used the specified config.
|
116
|
+
#
|
117
|
+
# @param config [::String] (DefaultConfig) The name of the config.
|
118
|
+
#
|
119
|
+
task :rebuild, [ :config ] do |task, args|
|
120
|
+
|
121
|
+
trace ParamNames[ :task, :args ], task, args
|
122
|
+
|
123
|
+
args.with_defaults(config: DefaultConfig.name)
|
124
|
+
|
125
|
+
log :informational, "Executing rebuild on '#{args[:config]}'"
|
126
|
+
|
127
|
+
begin
|
128
|
+
status = razor_instance.rebuild args[:config]
|
129
|
+
rescue RazorControlException => x
|
130
|
+
abort x.message
|
131
|
+
end
|
132
|
+
|
133
|
+
abort "Failed to rebuild '#{razor_instance.environment}' with '#{config}" unless status
|
134
|
+
|
135
|
+
task.reenable
|
136
|
+
end
|
137
|
+
|
138
|
+
# Executes a Turn of Day the Razor instance to used the specified
|
139
|
+
# config.
|
140
|
+
#
|
141
|
+
# @param config [::String] (DefaultConfig) The name of the config.
|
142
|
+
#
|
143
|
+
task :turn_of_day, [ :config ] do |task, args|
|
144
|
+
|
145
|
+
trace ParamNames[ :task, :args ], task, args
|
146
|
+
|
147
|
+
args.with_defaults(config: DefaultConfig.name)
|
148
|
+
|
149
|
+
log :informational, "Starting Razor with '#{args[:config]}'"
|
150
|
+
|
151
|
+
begin
|
152
|
+
status = razor_instance.turn_of_day args[:config]
|
153
|
+
rescue RazorControlException => x
|
154
|
+
abort x.message
|
155
|
+
end
|
156
|
+
|
157
|
+
abort "Failed execute Turn of Day for '#{razor_instance.environment}' with '#{args[:config]}" unless status
|
158
|
+
|
159
|
+
task.reenable
|
160
|
+
end
|
161
|
+
|
162
|
+
# Copies the razor logs to an output location.
|
163
|
+
#
|
164
|
+
# @param directory [::String] A path to the directory the logs are to
|
165
|
+
# be copied to.
|
166
|
+
# @param config [::String] (DefaultConfig) The name of the config.
|
167
|
+
#
|
168
|
+
task :copy_logs, [:directory, :config] do |task, args|
|
169
|
+
|
170
|
+
trace ParamNames[ :task, :args ], task, args
|
171
|
+
|
172
|
+
args.with_defaults(config: DefaultConfig.name)
|
173
|
+
|
174
|
+
log :informational, "Copying razor logs into output log directory"
|
175
|
+
|
176
|
+
begin
|
177
|
+
razor_instance.copy_logs args[:directory], args[:config]
|
178
|
+
rescue RazorControlException => x
|
179
|
+
abort x.message
|
180
|
+
end
|
181
|
+
|
182
|
+
task.reenable
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end # module RazorTasks
|
186
|
+
|
187
|
+
end # module RakeHelpers
|
188
|
+
end # module Control
|
189
|
+
end # module Razor
|
190
|
+
end # module RazorRisk
|
191
|
+
|
192
|
+
# ############################## end of file ############################# #
|
193
|
+
|
194
|
+
|
195
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Rake Task helpers.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
# ##########################################################
|
12
|
+
# requires
|
13
|
+
|
14
|
+
require 'pantheios'
|
15
|
+
|
16
|
+
require 'rake'
|
17
|
+
|
18
|
+
# ##########################################################
|
19
|
+
# RazorInstance
|
20
|
+
|
21
|
+
module RazorRisk
|
22
|
+
module Razor
|
23
|
+
module Control
|
24
|
+
module RakeHelpers
|
25
|
+
|
26
|
+
# Helper methods for Rake tasks.
|
27
|
+
class TaskHelpers
|
28
|
+
|
29
|
+
include ::Pantheios
|
30
|
+
|
31
|
+
# Adds First, Before and After hooks. This must be called AFTER all other
|
32
|
+
# tasks have been defined.
|
33
|
+
def self.add_hooks
|
34
|
+
|
35
|
+
first = ::Rake::Task.task_defined? :first
|
36
|
+
before = ::Rake::Task.task_defined? :before
|
37
|
+
after = ::Rake::Task.task_defined? :after
|
38
|
+
|
39
|
+
prereq = []
|
40
|
+
prereq << :first if first
|
41
|
+
prereq << :before if before
|
42
|
+
|
43
|
+
reject = [
|
44
|
+
:default,
|
45
|
+
:clean,
|
46
|
+
:clobber,
|
47
|
+
]
|
48
|
+
|
49
|
+
if first
|
50
|
+
reject << :first
|
51
|
+
reject << ::Rake::Task[:first].prerequisites
|
52
|
+
end
|
53
|
+
if before
|
54
|
+
reject << :before
|
55
|
+
reject << ::Rake::Task[:before].prerequisites
|
56
|
+
end
|
57
|
+
if after
|
58
|
+
reject << :after
|
59
|
+
reject << ::Rake::Task[:after].prerequisites
|
60
|
+
end
|
61
|
+
|
62
|
+
reject.flatten!
|
63
|
+
reject.map! { |r| r.is_a?(::String) ? r.to_sym : r }.uniq!
|
64
|
+
|
65
|
+
::Rake::Task.tasks.reject do |t|
|
66
|
+
reject.include? t.name.to_sym
|
67
|
+
end.each do |t|
|
68
|
+
t.enhance(prereq) do
|
69
|
+
if after
|
70
|
+
::Rake::Task[:after].invoke
|
71
|
+
::Rake::Task[:after].reenable
|
72
|
+
end
|
73
|
+
::Rake::Task[:before].reenable if before
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end # class TaskHelpers
|
78
|
+
|
79
|
+
end # module RakeHelpers
|
80
|
+
end # module Control
|
81
|
+
end # module Razor
|
82
|
+
end # module RazorRisk
|
83
|
+
|
84
|
+
# ############################## end of file ############################# #
|
85
|
+
|
86
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Razor Control Operations.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
# ##########################################################
|
12
|
+
# requires
|
13
|
+
|
14
|
+
require 'razor_risk/razor/control/diagnostics/util_functions'
|
15
|
+
require 'razor_risk/core/diagnostics/logger'
|
16
|
+
|
17
|
+
require 'pantheios'
|
18
|
+
require 'xqsr3/quality/parameter_checking'
|
19
|
+
|
20
|
+
# ##########################################################
|
21
|
+
# RazorInstance
|
22
|
+
|
23
|
+
module RazorRisk
|
24
|
+
module Razor
|
25
|
+
module Control
|
26
|
+
module Razor
|
27
|
+
|
28
|
+
# Executes operations on a Razor instance.
|
29
|
+
class Executor
|
30
|
+
|
31
|
+
include ::Pantheios
|
32
|
+
include ::Xqsr3::Quality::ParameterChecking
|
33
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
34
|
+
|
35
|
+
# Executes the provided system command and logs its output. The system
|
36
|
+
# command will be fed new lines to prevent getting stuck on any 'pause'
|
37
|
+
# statements. The program will be terminated if this process is
|
38
|
+
# interupeted.
|
39
|
+
#
|
40
|
+
# @param command [::String] The system command to execute.
|
41
|
+
def execute command, **opts
|
42
|
+
|
43
|
+
check_parameter command, 'command', type: ::String
|
44
|
+
|
45
|
+
rout,wout = IO.pipe
|
46
|
+
rerr,werr = IO.pipe
|
47
|
+
rin,win = IO.pipe
|
48
|
+
|
49
|
+
tout = Thread.new do
|
50
|
+
while line = rout.readline do
|
51
|
+
log :informational, "#{command}: #{line}".strip
|
52
|
+
end
|
53
|
+
end
|
54
|
+
terr = Thread.new do
|
55
|
+
while line = rerr.readline do
|
56
|
+
log :warning, "#{command}: #{line}".strip
|
57
|
+
end
|
58
|
+
end
|
59
|
+
tin = Thread.new do
|
60
|
+
while true do
|
61
|
+
win.write "\n"
|
62
|
+
sleep(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.merge!({
|
67
|
+
out: wout,
|
68
|
+
err: werr,
|
69
|
+
in: rin,
|
70
|
+
})
|
71
|
+
|
72
|
+
begin
|
73
|
+
pid = Process.spawn(
|
74
|
+
command,
|
75
|
+
opts
|
76
|
+
)
|
77
|
+
Process.wait pid
|
78
|
+
ensure
|
79
|
+
begin
|
80
|
+
Process.kill('SIGKILL', pid)
|
81
|
+
rescue Errno::ESRCH
|
82
|
+
# Process exited normally
|
83
|
+
end
|
84
|
+
|
85
|
+
win.close
|
86
|
+
tout.exit
|
87
|
+
terr.exit
|
88
|
+
tin.exit
|
89
|
+
end
|
90
|
+
$?.success?
|
91
|
+
end
|
92
|
+
end # class Executor
|
93
|
+
|
94
|
+
# Executes operations on a Razor instance.
|
95
|
+
class MockExecutor
|
96
|
+
|
97
|
+
# @return [Array<::String>] An array of commands sent to {#execute}.
|
98
|
+
attr_reader :commands
|
99
|
+
# @return [Array<::Hash>] An array of option hashes sent to {#execute}.
|
100
|
+
attr_reader :opts
|
101
|
+
|
102
|
+
# method description
|
103
|
+
#
|
104
|
+
# @param codes [Array<Numeric>] The return codes to uses.
|
105
|
+
#
|
106
|
+
def initialize *codes
|
107
|
+
|
108
|
+
@commands = []
|
109
|
+
@opts = []
|
110
|
+
@codes = codes
|
111
|
+
end
|
112
|
+
|
113
|
+
# Mocks the execute command. This will store the command and options in
|
114
|
+
# {#commands} and {#opts}.
|
115
|
+
def execute command, **opts
|
116
|
+
|
117
|
+
@commands << command
|
118
|
+
@opts << opts
|
119
|
+
|
120
|
+
return @codes.shift
|
121
|
+
end
|
122
|
+
end # class Executor
|
123
|
+
|
124
|
+
end # module Razor
|
125
|
+
end # module Control
|
126
|
+
end # module Razor
|
127
|
+
end # module Razor
|
128
|
+
|
129
|
+
# ############################## end of file ############################# #
|
130
|
+
|
131
|
+
|
@@ -0,0 +1,227 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Razor Control Operations.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
# ##########################################################
|
12
|
+
# requires
|
13
|
+
|
14
|
+
require 'razor_risk/razor/control/diagnostics/util_functions'
|
15
|
+
|
16
|
+
require 'razor_risk/razor/control/exceptions'
|
17
|
+
require 'razor_risk/razor/control/razor/executor'
|
18
|
+
|
19
|
+
require 'razor_risk/core/diagnostics/logger'
|
20
|
+
|
21
|
+
require 'xqsr3/quality/parameter_checking'
|
22
|
+
require 'pantheios'
|
23
|
+
|
24
|
+
# ##########################################################
|
25
|
+
# RazorInstance
|
26
|
+
|
27
|
+
module RazorRisk
|
28
|
+
module Razor
|
29
|
+
module Control
|
30
|
+
module Razor
|
31
|
+
|
32
|
+
# Details required for a razor config.
|
33
|
+
#
|
34
|
+
# @attr name [String] The name of the config, this is for specifying the
|
35
|
+
# config and does not need to match the directory.
|
36
|
+
# @attr path [String] The relative path of the config to the razor instace,
|
37
|
+
# e.g. 'config/StandardConfig'
|
38
|
+
# @attr script_dir [String] The relative path to where the config scripts
|
39
|
+
# (e.g. '4_rebuild.cmd') are from the config directory, e.g. 'config'.
|
40
|
+
# @attr tod_script [String] The name of the script to execute a Turn of Day
|
41
|
+
# with.
|
42
|
+
# @attr rebuild_script [String] The name of the script to rebuild the config.
|
43
|
+
#
|
44
|
+
Config = Struct.new(
|
45
|
+
:name,
|
46
|
+
:path,
|
47
|
+
:script_dir,
|
48
|
+
:tod_script,
|
49
|
+
:rebuild_script
|
50
|
+
)
|
51
|
+
|
52
|
+
LogLocation = 'master/log'
|
53
|
+
|
54
|
+
# Executes operations on a Razor instance.
|
55
|
+
class RazorInstance
|
56
|
+
|
57
|
+
include ::RazorRisk::Razor::Control::Exceptions
|
58
|
+
|
59
|
+
include ::Xqsr3::Quality::ParameterChecking
|
60
|
+
include ::Pantheios
|
61
|
+
|
62
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
63
|
+
|
64
|
+
# @return [::String] Path to the razor instance.
|
65
|
+
attr_reader :directory
|
66
|
+
# @return [::String] The razor environment.
|
67
|
+
attr_reader :environment
|
68
|
+
# @return [Array<Config>] An array of Razor configs supported by this
|
69
|
+
# instance.
|
70
|
+
attr_reader :configs
|
71
|
+
|
72
|
+
# Initializer.
|
73
|
+
#
|
74
|
+
# @param directory [::String] Path to the razor instance.
|
75
|
+
# @param environment [::String] The razor environment.
|
76
|
+
# @param configs [Array<Config>] An array of Razor configs supported by this
|
77
|
+
# instance.
|
78
|
+
# @param options [Hash] The options hash.
|
79
|
+
#
|
80
|
+
# @option executor [#execute]
|
81
|
+
# (::RazorRisk::Razor::Control::Razor::Executor) The object that will
|
82
|
+
# execute the scripts.
|
83
|
+
def initialize directory, environment, configs, **options
|
84
|
+
|
85
|
+
trace ParamNames[ :directory, :environment, :configs ], directory, environment, configs
|
86
|
+
|
87
|
+
@directory = check_parameter directory, 'directory', type: ::String
|
88
|
+
@environment = check_parameter environment, 'environment', type: ::String
|
89
|
+
check_parameter configs, 'configs', type: [ ::RazorRisk::Razor::Control::Razor::Config ]
|
90
|
+
|
91
|
+
raise RazorControlException.new(
|
92
|
+
"Razor directory '#{@directory}' does not exist or is not a directory."
|
93
|
+
) unless File.directory? @directory
|
94
|
+
raise RazorControlException.new(
|
95
|
+
"Razor Instance must have at least one config defined"
|
96
|
+
) if configs.empty?
|
97
|
+
|
98
|
+
@configs = configs.map do |c|
|
99
|
+
|
100
|
+
p = File.join(@directory, c.path)
|
101
|
+
raise RazorControlException.new(
|
102
|
+
"Razor config '#{c.name}' did not have an existing directory path; was '#{p}'."
|
103
|
+
) unless File.directory?(p)
|
104
|
+
|
105
|
+
[ c.name, c ]
|
106
|
+
end.to_h
|
107
|
+
|
108
|
+
@commands = {
|
109
|
+
kill: 'razor_kill.cmd',
|
110
|
+
}
|
111
|
+
|
112
|
+
@executor = options[:executor] || Executor.new
|
113
|
+
end
|
114
|
+
|
115
|
+
# Kills the razor instance.
|
116
|
+
#
|
117
|
+
# @return [boolean] if the exit process succeeded.
|
118
|
+
def kill
|
119
|
+
|
120
|
+
trace
|
121
|
+
|
122
|
+
raise RazorControlException.new(
|
123
|
+
"Command file '#{@commands[:kill]}' does not exist"
|
124
|
+
) unless File.file?(File.join(@directory, @commands[:kill]))
|
125
|
+
|
126
|
+
log :debug, "Killing Razor with '#{@commands[:kill]}' in '#{@directory}'"
|
127
|
+
@executor.execute @commands[:kill], chdir: @directory
|
128
|
+
end
|
129
|
+
|
130
|
+
# Execute a rebuild on the specified config.
|
131
|
+
#
|
132
|
+
# @param config [String] The name of the config to rebuild.
|
133
|
+
#
|
134
|
+
# @return [boolean] if the rebuild process succeeded.
|
135
|
+
def rebuild config
|
136
|
+
|
137
|
+
trace ParamNames[ :config ], config
|
138
|
+
|
139
|
+
check_parameter config, 'config', type: ::String, values: @configs.keys
|
140
|
+
|
141
|
+
con = @configs[config]
|
142
|
+
dir = File.join(@directory, con.path, con.script_dir)
|
143
|
+
|
144
|
+
raise RazorControlException.new(
|
145
|
+
"Command file '#{con.rebuild_script}' does not exist"
|
146
|
+
) unless File.file?(File.join(dir, con.rebuild_script))
|
147
|
+
|
148
|
+
log :debug, "Executing rebuild script '#{con.rebuild_script}' in '#{dir}'"
|
149
|
+
@executor.execute con.rebuild_script, chdir: dir
|
150
|
+
end
|
151
|
+
|
152
|
+
# Starts Razor with the specified config.
|
153
|
+
#
|
154
|
+
# @param config [String] The name of the config execute a Turn of Day for.
|
155
|
+
#
|
156
|
+
# @return [boolean] if the turn of day process succeeded.
|
157
|
+
def turn_of_day config
|
158
|
+
|
159
|
+
trace ParamNames[ :config ], config
|
160
|
+
|
161
|
+
check_parameter config, 'config', type: ::String, values: @configs.keys
|
162
|
+
|
163
|
+
con = @configs[config]
|
164
|
+
dir = File.join(@directory, con.path, con.script_dir)
|
165
|
+
|
166
|
+
raise RazorControlException.new(
|
167
|
+
"Command file '#{con.tod_script}' does not exist"
|
168
|
+
) unless File.file?(File.join(dir, con.tod_script))
|
169
|
+
|
170
|
+
log :debug, "Executing turn of day script '#{con.tod_script}' in '#{dir}'"
|
171
|
+
@executor.execute con.tod_script, chdir: dir
|
172
|
+
end
|
173
|
+
|
174
|
+
# Copy razor logs to output directory. Copies logs to
|
175
|
+
# +<directory>/razor/<config>+.
|
176
|
+
#
|
177
|
+
# @param directory [::String] Path to the output directory.
|
178
|
+
# @param config [::String] The name of the current config.
|
179
|
+
#
|
180
|
+
# @raise [RazorControlException] if Razor log directory does not exist.
|
181
|
+
# @raise [RazorControlException] if no Razor logs can be found.
|
182
|
+
#
|
183
|
+
def copy_logs directory, config
|
184
|
+
|
185
|
+
trace ParamNames[ :directory, :config ], directory, config
|
186
|
+
|
187
|
+
check_parameter directory, 'directory', type: ::String
|
188
|
+
check_parameter config, 'config', type: ::String
|
189
|
+
|
190
|
+
razor_log_dir = File.join(
|
191
|
+
@directory,
|
192
|
+
Razor::LogLocation
|
193
|
+
)
|
194
|
+
out_log_dir = File.join(
|
195
|
+
directory,
|
196
|
+
'razor',
|
197
|
+
config
|
198
|
+
)
|
199
|
+
|
200
|
+
raise RazorControlException.new(
|
201
|
+
"Razor log directory '#{razor_log_dir}' does not exist"
|
202
|
+
) unless Dir.exists? razor_log_dir
|
203
|
+
|
204
|
+
logs = Dir[ File.join(razor_log_dir, '**', '*.log').gsub('\\', '/') ]
|
205
|
+
raise RazorControlException.new(
|
206
|
+
"Razor logs could not be found in '#{razor_log_dir}'"
|
207
|
+
) if logs.empty?
|
208
|
+
|
209
|
+
FileUtils.mkdir_p out_log_dir unless Dir.exists? out_log_dir
|
210
|
+
|
211
|
+
logs.each do |f|
|
212
|
+
src = f
|
213
|
+
dst = File.join(out_log_dir, File.basename(f))
|
214
|
+
log :debug, "Copying '#{src}' to '#{dst}'"
|
215
|
+
FileUtils.cp src, dst
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end # class RazorInstance
|
219
|
+
|
220
|
+
end # module Razor
|
221
|
+
end # module Control
|
222
|
+
end # module Razor
|
223
|
+
end # module RazorRisk
|
224
|
+
|
225
|
+
# ############################## end of file ############################# #
|
226
|
+
|
227
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Version file for Razor Risk Razor Control library.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
|
12
|
+
module RazorRisk
|
13
|
+
module Razor
|
14
|
+
module Control
|
15
|
+
|
16
|
+
# Current version of the RazorRisk::Razor::Control library
|
17
|
+
VERSION = '0.1'
|
18
|
+
|
19
|
+
private
|
20
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
21
|
+
public
|
22
|
+
# Major version of the RazorRisk::Razor:Control library
|
23
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
24
|
+
# Minor version of the RazorRisk::Razor::Control library
|
25
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
26
|
+
# Patch version of the RazorRisk::Razor::Control library
|
27
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
28
|
+
# Commit version of the RazorRisk::Razor::Control library
|
29
|
+
VERSION_COMMIT = VERSION_PARTS_[3] || 0 # :nodoc:
|
30
|
+
|
31
|
+
|
32
|
+
# The description of the framework
|
33
|
+
DESCRIPTION = 'Support library for controlling razor testing environments.'
|
34
|
+
|
35
|
+
end # module Control
|
36
|
+
end # module Razor
|
37
|
+
end # module RazorRisk
|
38
|
+
|
39
|
+
# ############################## end of file ############################# #
|
40
|
+
|
41
|
+
|