kaya 0.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/.gitignore +26 -0
- data/CHANGELOG +52 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/NOTAS +19 -0
- data/README.md +279 -0
- data/Rakefile +1 -0
- data/bin/kaya +4 -0
- data/documentation/api.md +47 -0
- data/documentation/api_execution_data.md +47 -0
- data/documentation/configuration.md +13 -0
- data/documentation/custom_parameters.md +117 -0
- data/documentation/document_kaya.md +122 -0
- data/documentation/link.md +12 -0
- data/documentation/results.md +119 -0
- data/documentation/start.md +19 -0
- data/documentation/suites.md +60 -0
- data/documentation/test_suite_information.md +9 -0
- data/kaya.gemspec +42 -0
- data/lib/generators/task_rack.rb +160 -0
- data/lib/generators/templates/Gemfile.tt +2 -0
- data/lib/generators/templates/config.ru.tt +2 -0
- data/lib/generators/templates/kaya_conf.tt +49 -0
- data/lib/generators/templates/kaya_log.tt +0 -0
- data/lib/generators/templates/sidekiq_log.tt +0 -0
- data/lib/generators/templates/tasks.kaya.tt +10 -0
- data/lib/generators/templates/unicorn.rb.tt +21 -0
- data/lib/kaya/API/error.rb +17 -0
- data/lib/kaya/API/execution.rb +141 -0
- data/lib/kaya/API/result.rb +49 -0
- data/lib/kaya/API/results.rb +31 -0
- data/lib/kaya/API/suite.rb +42 -0
- data/lib/kaya/API/suites.rb +36 -0
- data/lib/kaya/background_jobs/sidekiq.rb +35 -0
- data/lib/kaya/background_jobs/workers/execution_checker.rb +20 -0
- data/lib/kaya/background_jobs/workers/garbage_cleaner.rb +31 -0
- data/lib/kaya/commands/bye.rb +12 -0
- data/lib/kaya/commands/help.rb +13 -0
- data/lib/kaya/commands/install.rb +27 -0
- data/lib/kaya/commands/reset.rb +39 -0
- data/lib/kaya/commands/reset_suites.rb +40 -0
- data/lib/kaya/commands/restart.rb +9 -0
- data/lib/kaya/commands/start.rb +104 -0
- data/lib/kaya/commands/stop.rb +53 -0
- data/lib/kaya/cuba.rb +287 -0
- data/lib/kaya/cucumber/features.rb +15 -0
- data/lib/kaya/cucumber/task.rb +64 -0
- data/lib/kaya/custom/execution_data.rb +50 -0
- data/lib/kaya/custom/params.rb +34 -0
- data/lib/kaya/database/mongo_connector.rb +285 -0
- data/lib/kaya/error/errors.rb +55 -0
- data/lib/kaya/execution.rb +57 -0
- data/lib/kaya/results/result.rb +493 -0
- data/lib/kaya/results/results.rb +47 -0
- data/lib/kaya/suites/custom/params.rb +151 -0
- data/lib/kaya/suites/suite.rb +177 -0
- data/lib/kaya/suites/suites.rb +130 -0
- data/lib/kaya/support/clean.rb +12 -0
- data/lib/kaya/support/configuration.rb +254 -0
- data/lib/kaya/support/console.rb +11 -0
- data/lib/kaya/support/documentation.rb +34 -0
- data/lib/kaya/support/error_handler_helper.rb +24 -0
- data/lib/kaya/support/files_cleanner.rb +136 -0
- data/lib/kaya/support/git.rb +161 -0
- data/lib/kaya/support/if_config.rb +14 -0
- data/lib/kaya/support/logo.rb +23 -0
- data/lib/kaya/support/logs.rb +37 -0
- data/lib/kaya/support/notification.rb +127 -0
- data/lib/kaya/support/processes.rb +96 -0
- data/lib/kaya/support/query_string.rb +22 -0
- data/lib/kaya/support/request.rb +32 -0
- data/lib/kaya/support/risk.rb +9 -0
- data/lib/kaya/support/time_helper.rb +11 -0
- data/lib/kaya/support/update.rb +65 -0
- data/lib/kaya/version.rb +3 -0
- data/lib/kaya/view/body.mote +60 -0
- data/lib/kaya/view/custom/params/select_list.mote +14 -0
- data/lib/kaya/view/custom/params/text.mote +9 -0
- data/lib/kaya/view/custom/params.mote +9 -0
- data/lib/kaya/view/error_handler.mote +40 -0
- data/lib/kaya/view/features/feature.mote +14 -0
- data/lib/kaya/view/features/features_list.mote +10 -0
- data/lib/kaya/view/features.mote +57 -0
- data/lib/kaya/view/footer.mote +10 -0
- data/lib/kaya/view/git_information.mote +21 -0
- data/lib/kaya/view/help/main.mote +21 -0
- data/lib/kaya/view/help/page.mote +2 -0
- data/lib/kaya/view/help/search_result.mote +29 -0
- data/lib/kaya/view/help.mote +72 -0
- data/lib/kaya/view/javascript.mote +96 -0
- data/lib/kaya/view/logs/log.mote +3 -0
- data/lib/kaya/view/modals.mote +31 -0
- data/lib/kaya/view/navigation_bar.mote +48 -0
- data/lib/kaya/view/not_found.mote +40 -0
- data/lib/kaya/view/parser.rb +79 -0
- data/lib/kaya/view/results/all.mote +59 -0
- data/lib/kaya/view/results/console.mote +106 -0
- data/lib/kaya/view/results/detailed_info.mote +112 -0
- data/lib/kaya/view/results/report.mote +1 -0
- data/lib/kaya/view/results/result.mote +23 -0
- data/lib/kaya/view/results/results.mote +52 -0
- data/lib/kaya/view/screenshot.mote +42 -0
- data/lib/kaya/view/sections.rb +25 -0
- data/lib/kaya/view/styles.mote +58 -0
- data/lib/kaya/view/suites/suite.mote +73 -0
- data/lib/kaya/view/suites/suites.mote +9 -0
- data/lib/kaya/view/view.rb +72 -0
- data/lib/kaya.rb +175 -0
- data/test/features/install.feature +18 -0
- data/test/features/support/env.rb +3 -0
- metadata +395 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
module Kaya
|
|
4
|
+
module Support
|
|
5
|
+
class FilesCleanner
|
|
6
|
+
|
|
7
|
+
# Delete all kaya_reports html files
|
|
8
|
+
def self.start!
|
|
9
|
+
begin
|
|
10
|
+
self.delete_kaya_reports_dir
|
|
11
|
+
rescue
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.delete_file file_name
|
|
18
|
+
begin
|
|
19
|
+
File.delete("#{file_name}") and true
|
|
20
|
+
rescue
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.delete_kaya_reports_dir
|
|
26
|
+
location = "#{Dir.pwd}/kaya/kaya_reports"
|
|
27
|
+
FileUtils.rm_rf(location)
|
|
28
|
+
Dir.mkdir(location)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.delete_report_which_has text
|
|
32
|
+
text = text.to_s if text.respond_to? :to_s
|
|
33
|
+
report = all_kaya_reports.select do |file|
|
|
34
|
+
file.include? text
|
|
35
|
+
end.first
|
|
36
|
+
|
|
37
|
+
delete_file(report)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.delete_html_report_for result_id
|
|
41
|
+
file = all_kaya_reports.select do |file|
|
|
42
|
+
file.include? result_id
|
|
43
|
+
end.first
|
|
44
|
+
delete_file(file) if file
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.all_kaya_reports
|
|
48
|
+
Dir["#{Dir.pwd}/kaya/temp/*.*"].select do |file|
|
|
49
|
+
!file.scan(/kaya_report_\d+\.html/).empty?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Deletes all kaya html reports
|
|
54
|
+
def self.delete_kaya_reports
|
|
55
|
+
# Get all html report files
|
|
56
|
+
(Kaya::Support::Git.reset_hard and Kaya::Support::Git.pull) if Kaya::Support::Configuration.use_git?
|
|
57
|
+
begin
|
|
58
|
+
self.delete_all_kaya_reports
|
|
59
|
+
rescue
|
|
60
|
+
false
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Deletes all kaya html reports files
|
|
65
|
+
# @return [Boolean] if has deleted reports
|
|
66
|
+
def self.delete_all_kaya_reports
|
|
67
|
+
not all_kaya_reports.each do |file|
|
|
68
|
+
self.delete_file(file)
|
|
69
|
+
end.empty?
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Deletes kaya execution output files
|
|
74
|
+
# @return [Boolean] for success
|
|
75
|
+
def self.delete_console_outputs_files
|
|
76
|
+
(Kaya::Support::Git.reset_hard and Kaya::Support::Git.pull) if Kaya::Support::Configuration.use_git?
|
|
77
|
+
begin
|
|
78
|
+
self.delete_all_console_output_files
|
|
79
|
+
true
|
|
80
|
+
rescue
|
|
81
|
+
false
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Deletes all kaya execution output files
|
|
86
|
+
# @return [Boolean] if has deleted files
|
|
87
|
+
def self.delete_all_console_output_files
|
|
88
|
+
not all_console_output_reports.each do |file|
|
|
89
|
+
delete_file(file)
|
|
90
|
+
end.empty?
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def self.all_console_output_reports
|
|
94
|
+
Dir["#{Dir.pwd}/kaya/temp/*.*"].select do |file|
|
|
95
|
+
!file.scan(/kaya_co_\d+\.out/).empty?
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def self.delete_console_output_for result_id
|
|
100
|
+
file=all_console_output_reports.select do |file|
|
|
101
|
+
file.include? result_id
|
|
102
|
+
end.first
|
|
103
|
+
delete_file(file) if file
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def self.clear_sidekiq_log
|
|
107
|
+
sidekiq_file_path = "#{Dir.pwd}/kaya/sidekiq_log"
|
|
108
|
+
if File.exist? sidekiq_file_path
|
|
109
|
+
File.delete(sidekiq_file_path)
|
|
110
|
+
File.open(sidekiq_file_path, "a+"){}
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def self.clear_kaya_log
|
|
115
|
+
kaya_log_file_path = "#{Dir.pwd}/kaya/kaya_log"
|
|
116
|
+
if File.exist? kaya_log_file_path
|
|
117
|
+
File.delete(kaya_log_file_path)
|
|
118
|
+
File.open(kaya_log_file_path, "a+"){}
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Deletes kaya folder. Used by 'bye command'
|
|
123
|
+
# @return [Boolean] for success
|
|
124
|
+
def self.delete_kaya_folder
|
|
125
|
+
begin
|
|
126
|
+
location = "#{Dir.pwd}/kaya"
|
|
127
|
+
FileUtils.rm_rf(location)
|
|
128
|
+
true
|
|
129
|
+
rescue
|
|
130
|
+
false
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# require "git"
|
|
2
|
+
|
|
3
|
+
module Kaya
|
|
4
|
+
module Support
|
|
5
|
+
class Git
|
|
6
|
+
|
|
7
|
+
def self.branch_list
|
|
8
|
+
self.remote_branches.map do |branch|
|
|
9
|
+
branch.gsub("*","").gsub(" ","").gsub("origin/","")
|
|
10
|
+
end.select do |branch|
|
|
11
|
+
not (branch.include? "HEAD" or branch.include? "/")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.remote_branches
|
|
16
|
+
Kaya::Support::Console.execute("git branch -r").split("\n")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.fetch
|
|
20
|
+
Kaya::Support::Console.execute("git fetch")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.branch
|
|
24
|
+
self.branches.select{|branch| branch.include? "*"}.first.gsub("*","").gsub(" ","")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.actual_branch; self.branch; end
|
|
28
|
+
|
|
29
|
+
def self.branches
|
|
30
|
+
Kaya::Support::Console.execute("git branch").split("\n")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.git_add_commit msg=nil
|
|
34
|
+
self.add_all
|
|
35
|
+
self.commit msg
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.add_all
|
|
39
|
+
Kaya::Support::Console.execute("git add .")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.add_file filename
|
|
43
|
+
Kaya::Support::Console.execute("git add #{filename}")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.push
|
|
47
|
+
Kaya::Support::Console.execute("git push")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.git_push_origin_to branch_name=nil
|
|
51
|
+
branch_name = self.branch if branch_name.nil?
|
|
52
|
+
Kaya::Support::Console.execute("git push origin #{branch_name}")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.reset_hard
|
|
56
|
+
Kaya::Support::Console.execute("git reset --hard")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.git_push_origin_to_actual_branch
|
|
60
|
+
branch_name = self.branch
|
|
61
|
+
self.git_push_origin_to branch_name
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.git_push_origin_to_actual_branch
|
|
65
|
+
git_push_origin_to(self.actual_branch)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.commit msg = nil
|
|
69
|
+
# self.ensure_being_at_kaya_branch
|
|
70
|
+
msg = "KAYA COMMIT #{Time.new.strftime('%d %m %Y %H:%M:%S')}" if msg.nil?
|
|
71
|
+
Kaya::Support::Console.execute"git commit -m '#{msg}'"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.create_branch_and_checkout branch
|
|
75
|
+
Kaya::Support::Console.execute("git checkout -b #{branch}")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.delete_branch branch
|
|
79
|
+
checkout_to "master"
|
|
80
|
+
Kaya::Support::Console.execute("git branch -D #{branch}")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Performs pull from actual branc
|
|
84
|
+
def self.pull
|
|
85
|
+
self.pull_from(self.actual_branch)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.pull_from(branch_name=nil)
|
|
89
|
+
branch_name = self.branch if branch_name.nil?
|
|
90
|
+
Kaya::Support::Console.execute("git pull origin #{branch_name}")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def self.return_to_branch branch
|
|
94
|
+
self.checkout_to branch
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.checkout_to branch
|
|
98
|
+
Kaya::Support::Console.execute("git checkout #{branch}") unless self.actual_branch == branch
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.checkout_and_pull_from branch_name=nil
|
|
102
|
+
self.checkout_to(branch_name) if branch_name
|
|
103
|
+
branch_name = self.branch if branch_name.nil?
|
|
104
|
+
self.pull_from branch_name
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Returns las commit id.
|
|
108
|
+
# This method is used by Execution class to verify changes before each execution
|
|
109
|
+
# @param [String] the name of the project (folder project)
|
|
110
|
+
# @return [String] the id for the las commit
|
|
111
|
+
def self.get_last_commit_id
|
|
112
|
+
self.commits_ids.map do |commit|
|
|
113
|
+
commit.gsub("commit ","")
|
|
114
|
+
end.first
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def self.commits_ids
|
|
118
|
+
self.log.split("\n").select do |line|
|
|
119
|
+
self.is_commit_id? line
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.commits
|
|
124
|
+
self.log.split("commit")[1..-1]
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def self.is_commit_id? line
|
|
128
|
+
line.start_with? "commit "
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def self.log
|
|
132
|
+
Kaya::Support::Console.execute "git log"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def self.log_last_commit
|
|
136
|
+
"Commit: #{self.commits.first}"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.is_there_commit_id_diff? obtained_commit
|
|
140
|
+
obtained_commit != self.last_commit_id
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def self.remote_url
|
|
144
|
+
|
|
145
|
+
res = Kaya::Support::Console.execute("git config --get remote.origin.url").gsub(":","/").gsub("git@", 'http://').chop
|
|
146
|
+
res[0..-5] if res.end_with? ".git"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Returns an Array with the existing files on .gitignore
|
|
150
|
+
# @param [Array]
|
|
151
|
+
def self.get_actual_lines
|
|
152
|
+
f = File.open("#{Dir.pwd}/.gitignore","r")
|
|
153
|
+
files_list = []
|
|
154
|
+
f.each_line do |line|
|
|
155
|
+
files_list << line.gsub("\n","").gsub(" ","")
|
|
156
|
+
end
|
|
157
|
+
files_list
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Kaya
|
|
4
|
+
module Support
|
|
5
|
+
module Logo
|
|
6
|
+
def self.show
|
|
7
|
+
puts self.logo
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.logo
|
|
11
|
+
"
|
|
12
|
+
██╗ ██╗ █████╗ ██╗ ██╗ █████╗
|
|
13
|
+
██║ ██╔╝██╔══██╗╚██╗ ██╔╝██╔══██╗
|
|
14
|
+
█████╔╝ ███████║ ╚████╔╝ ███████║
|
|
15
|
+
██╔═██╗ ██╔══██║ ╚██╔╝ ██╔══██║
|
|
16
|
+
██║ ██╗██║ ██║ ██║ ██║ ██║
|
|
17
|
+
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
18
|
+
Version #{Kaya::VERSION}
|
|
19
|
+
"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Kaya
|
|
2
|
+
module Support
|
|
3
|
+
module Logs
|
|
4
|
+
|
|
5
|
+
def self.path
|
|
6
|
+
"#{Dir.pwd}/kaya/"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.all
|
|
10
|
+
logs = Hash.new
|
|
11
|
+
Dir.glob(path + '*_log') do |log_file|
|
|
12
|
+
name = log_file.split("/").last.gsub('.log','')
|
|
13
|
+
text = File.read(log_file)
|
|
14
|
+
logs[name] = text
|
|
15
|
+
end
|
|
16
|
+
logs
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.read_log_file_content_for log=nil
|
|
20
|
+
path = "#{Dir.pwd}/kaya/#{log}"
|
|
21
|
+
if File.exist?("#{path}")
|
|
22
|
+
FileUtils.cp(path, "#{path}~")
|
|
23
|
+
all_content = IO.read("#{path}~")
|
|
24
|
+
content = if all_content.split("\n").size > 500
|
|
25
|
+
all_content.split("\n")[-500..-1].join("<br>")
|
|
26
|
+
else
|
|
27
|
+
all_content.gsub("\n","<br>")
|
|
28
|
+
end
|
|
29
|
+
File.delete("#{path}~")
|
|
30
|
+
else
|
|
31
|
+
content = ""
|
|
32
|
+
end
|
|
33
|
+
content
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'gmail'
|
|
2
|
+
|
|
3
|
+
module Kaya
|
|
4
|
+
module Support
|
|
5
|
+
class Notification
|
|
6
|
+
|
|
7
|
+
include Gmail
|
|
8
|
+
|
|
9
|
+
def initialize project_name, base_url=nil
|
|
10
|
+
@project_name = project_name
|
|
11
|
+
@base_url = base_url
|
|
12
|
+
@subject_prefix = "[Kaya] [#{@project_name}] "
|
|
13
|
+
if Kaya::Support::Configuration.notification?
|
|
14
|
+
begin
|
|
15
|
+
@email = Gmail.connect!(Kaya::Support::Configuration.notification_username,Kaya::Support::Configuration.notification_password)
|
|
16
|
+
$K_LOG.debug "Notification: Login to Gmail Succesfully"
|
|
17
|
+
$K_LOG.debug "Notification: USING NOTIFICATION TO #{Kaya::Support::Configuration.recipients}"
|
|
18
|
+
rescue => e
|
|
19
|
+
$K_LOG.error "Notification: ERROR TO CONNECT TO GMAIL #{e}".red
|
|
20
|
+
$K_LOG.error "Notification: Connecting to GMail error => #{e}"
|
|
21
|
+
@email = NoEmail.new
|
|
22
|
+
end
|
|
23
|
+
else
|
|
24
|
+
@email = NoEmail.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def notificate subject, body
|
|
30
|
+
send_email subject, body, Kaya::Support::Configuration.notifications_to
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def send_email message_subject, message_body, path_to_file=nil
|
|
34
|
+
message_subject = "#{@subject_prefix} #{message_subject}"
|
|
35
|
+
begin
|
|
36
|
+
email = @email.compose do
|
|
37
|
+
to Kaya::Support::Configuration.recipients
|
|
38
|
+
subject message_subject
|
|
39
|
+
text_part do
|
|
40
|
+
body message_body
|
|
41
|
+
end
|
|
42
|
+
html_part do
|
|
43
|
+
$K_LOG.debug "Notification: Attaching report file (#{path_to_file})"
|
|
44
|
+
content_type 'text/html; charset=UTF-8'
|
|
45
|
+
body "<p>#{message_body}</p>"
|
|
46
|
+
end
|
|
47
|
+
add_file path_to_file
|
|
48
|
+
end
|
|
49
|
+
email.deliver!
|
|
50
|
+
$K_LOG.debug "Notification: Email sent to (#{Kaya::Support::Configuration.recipients}) | Subject: '#{message_subject}' | Message: #{message_body}" if $K_LOG
|
|
51
|
+
rescue => e
|
|
52
|
+
$K_LOG.error "Notification: Could not sent email to (#{Kaya::Support::Configuration.recipients}) | Subject: '#{message_subject}' | Message: #{message_body} | #{e}\n #{e.backtrace}" if $K_LOG
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if path_to_file
|
|
56
|
+
begin
|
|
57
|
+
File.delete path_to_file
|
|
58
|
+
$K_LOG.debug "Notification: File #{path_to_file} deleted"
|
|
59
|
+
rescue
|
|
60
|
+
$K_LOG.error "Notification: Could not delete file #{path_to_file}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def execution_finished result
|
|
68
|
+
body = "
|
|
69
|
+
Result Summary: #{result.summary}
|
|
70
|
+
|
|
71
|
+
Command: #{result.command}
|
|
72
|
+
|
|
73
|
+
Execution name: #{result.execution_name}
|
|
74
|
+
|
|
75
|
+
Started at: #{result.started_at_formatted}
|
|
76
|
+
|
|
77
|
+
Finished at: #{result.finished_at_formatted}
|
|
78
|
+
|
|
79
|
+
Elapsed Time: #{result.elapsed_time} seconds
|
|
80
|
+
|
|
81
|
+
Custom Params: #{result.custom_params}
|
|
82
|
+
|
|
83
|
+
See log at http://#{@base_url}/kaya/results/#{result.id}/log"
|
|
84
|
+
|
|
85
|
+
if Kaya::Support::Configuration.attach_report?
|
|
86
|
+
path_to_file = "#{Dir.pwd}/kaya/temp/#{result.id}.html"
|
|
87
|
+
$K_LOG.debug "Notification: Creating file report to attach to mail (#{path_to_file})"
|
|
88
|
+
File.open("#{path_to_file}","a+"){|f| f.write result.html_report}
|
|
89
|
+
$K_LOG.debug "Notification: File created (#{path_to_file})"
|
|
90
|
+
end
|
|
91
|
+
message_subject = "Execution Finished (#{result.id}) "
|
|
92
|
+
send_email message_subject, body, path_to_file
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def execution_stopped result, additional_text=nil
|
|
100
|
+
body = "Execution stopped \n#{additional_text}"
|
|
101
|
+
message_subject = "Execution stopped (#{result.id})"
|
|
102
|
+
send_email message_subject, body
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class NoEmail
|
|
113
|
+
|
|
114
|
+
def initialize
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def method_missing meth, *args
|
|
119
|
+
begin
|
|
120
|
+
rescue
|
|
121
|
+
$K_LOG.error "Notification: #{meth} invoked but email is not configured"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
module Kaya
|
|
2
|
+
module Support
|
|
3
|
+
class Processes
|
|
4
|
+
def self.kill_by_result_id(result_id)
|
|
5
|
+
|
|
6
|
+
pid = pid_for(result_id)
|
|
7
|
+
|
|
8
|
+
return false if pid.nil?
|
|
9
|
+
|
|
10
|
+
childs = process_childs(pid)
|
|
11
|
+
|
|
12
|
+
unless pid.zero?
|
|
13
|
+
begin
|
|
14
|
+
childs.each{|ch_pid| kill_p(ch_pid)} unless childs.empty?
|
|
15
|
+
kill_p(pid)
|
|
16
|
+
true # Process killed
|
|
17
|
+
rescue Errno::EPERM # Denied permission to kill process
|
|
18
|
+
begin
|
|
19
|
+
kill_dash_nine(pid) and true # Process killed
|
|
20
|
+
rescue
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
rescue Errno::ESRCH # Process did not exist
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
puts "Cannot find process id"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.kill_p(pid)
|
|
32
|
+
pid = pid.to_i if pid.respond_to? :to_i
|
|
33
|
+
Process.kill('INT', pid)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.kill_dash_nine(pid)
|
|
37
|
+
pid = pid.to_i if pid.respond_to? :to_i
|
|
38
|
+
puts "kill -9 #{pid}" if $DEBUG
|
|
39
|
+
Kaya::Support::Console.execute "kill -9 #{pid}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.pid_for(result_id)
|
|
43
|
+
result = Kaya::Results::Result.get(result_id)
|
|
44
|
+
result.pid.to_i
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.process_running? pid
|
|
48
|
+
unless pid.nil?
|
|
49
|
+
res = Kaya::Support::Console.execute("ps -p #{pid}").split("\n").last
|
|
50
|
+
unless res.nil?
|
|
51
|
+
res.include? "#{pid}" and !res.include? "<defunct>"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#Recibe un PID y devuelve un array con los PID de sus hijos
|
|
58
|
+
def self.process_childs(pid)
|
|
59
|
+
Kaya::Support::Console.execute("ps -fea | grep #{pid} | grep -v grep | awk '$2!=#{pid} && $8!~/awk/ && $3==#{pid}{print $2}'").split("\n")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.kaya_pids
|
|
63
|
+
res = Kaya::Support::Console.execute "ps -fea | grep 'unicorn.rb -p #{Kaya::Support::Configuration.port}'"
|
|
64
|
+
|
|
65
|
+
res.split("\n").select{|lines| !lines.include? "grep"}.map{|line| line.split[1]}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.sidekiq_pids
|
|
69
|
+
res = Kaya::Support::Console.execute "ps -fea | grep 'sidekiq'"
|
|
70
|
+
|
|
71
|
+
res.split("\n").select{|lines| !lines.include? "grep"}.map{|line| line.split[1]}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.kill_all_these pids=nil
|
|
75
|
+
if pids
|
|
76
|
+
until pids.empty?
|
|
77
|
+
pid = pids.pop
|
|
78
|
+
if process_running? pid
|
|
79
|
+
begin
|
|
80
|
+
kill_dash_nine(pid)
|
|
81
|
+
rescue Errno::ESRCH
|
|
82
|
+
puts "Could not find process id #{pid} to kill"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def self.fork_this command
|
|
91
|
+
fork{exec("#{command}")}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Kaya
|
|
2
|
+
module Support
|
|
3
|
+
class QueryString
|
|
4
|
+
|
|
5
|
+
attr_reader :values, :req
|
|
6
|
+
|
|
7
|
+
# req = Request
|
|
8
|
+
def initialize req
|
|
9
|
+
@req = req
|
|
10
|
+
@values = Rack::Utils.parse_nested_query(req.query_string.split("/").last)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def value_for key
|
|
14
|
+
@values[key]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def method_missing(key, *args, &block)
|
|
18
|
+
@values[key.to_s]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Kaya
|
|
2
|
+
module Support
|
|
3
|
+
class Request
|
|
4
|
+
|
|
5
|
+
def initialize req
|
|
6
|
+
@req = req
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def path
|
|
10
|
+
self.path_info
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def path_info
|
|
14
|
+
@req.env["PATH_INFO"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def ip
|
|
18
|
+
@req.env["REMOTE_ADDR"]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def method_missing(method_name, *args, &block)
|
|
22
|
+
begin
|
|
23
|
+
send("@req.#{method_name}", *args)
|
|
24
|
+
rescue
|
|
25
|
+
$K_LOG.error "#{method_name} not found for req in #{self.class}. Returning nil"
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module Kaya
|
|
2
|
+
module Support
|
|
3
|
+
class Risk
|
|
4
|
+
def self.secure? value
|
|
5
|
+
value.scan(/&&|kill.*|rm -rf|rm -r \.\[\^\.\]\*|mkfs.*|.*\> \/dev\/sda|\:\(\)\{\:\|\:\&\}\;\:|wget .*|sh \.\/.*|\||grep|python \-c \'import os.*|mv .+|\> .+|\^foo\^bar|dd if=\/dev\/random of=\/dev\/sda|mkdir .*/).empty?
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|