gorgon 0.6.5 → 0.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +0 -1
- data/bin/gorgon +19 -0
- data/lib/gorgon/originator.rb +28 -18
- data/lib/gorgon/rsync_daemon.rb +19 -24
- data/lib/gorgon/settings/rails_project_files_content.rb +23 -25
- data/lib/gorgon/shutdown_manager.rb +0 -7
- data/lib/gorgon/source_tree_syncer.rb +19 -8
- data/lib/gorgon/version.rb +1 -1
- data/spec/originator_spec.rb +14 -21
- data/spec/rsync_daemon_spec.rb +12 -30
- data/spec/shutdown_manager_spec.rb +2 -11
- data/spec/source_tree_syncer_spec.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmUzM2U0MzQ5NjczNjczMjU4YjJjMWIxYmVkOTYxZDJjZTk0NjIzNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGRiOWM5ZTU0MjVmZGZlYmI5MDhhOGRmNTVkYTg0MzMxZGE0MGEwZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjFjMWFlMzFkYWM3OTBhYjA1ZDVmY2MwODViZTEzNWQzMjFlNmZlMWNmYTNm
|
10
|
+
OTZiNzc4ZWNjYWIxODYzMjczNzQ4NDcyOTM5MmEzYzIyMzY3YTVhYzUxYTA5
|
11
|
+
M2YwZjZjMGFiOGJlYjI0MTBiN2NkNTUxYmIwYTMyZDIyMTI5YTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTUyM2JhM2Q0YjlkNjJlZmRkZWI0MTE1M2NjNDBmNDI1ZDZjNzRkZDBkZTFk
|
14
|
+
ZjdiMzJjNWE0ODIzMDNjYzY2MGMxNDg5YzAzZjNiOGJiYzhmODQ0MWNkZmM3
|
15
|
+
ZjU0ZDQ0Y2VkZTYzOGNmYjAzMzg2NDM2MjIxYTA2NWExYWU0ODA=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,6 @@ Gorgon provides a method for distributing the workload of running ruby test suit
|
|
11
11
|
Installing Gorgon
|
12
12
|
-----------------
|
13
13
|
1. `sudo apt-get install rabbitmq-server`
|
14
|
-
1. When you run gorgon, every listener will use rsync to pull the directory tree from origin; therefore, you need passwordless ssh login from every listener to origin (even if origin and listener are on the same host). Follow [these steps](http://linuxconfig.org/Passwordless_ssh).
|
15
14
|
1. cd to your project
|
16
15
|
1. `gem install gorgon`
|
17
16
|
1. if using rails, `gorgon init rails` will create initial files for a typical rails project. Otherwise, you can use `gorgon init`
|
data/bin/gorgon
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require 'gorgon/originator'
|
3
3
|
require 'gorgon/listener'
|
4
|
+
require 'gorgon/rsync_daemon'
|
4
5
|
require 'gorgon/worker_manager'
|
5
6
|
require 'gorgon/ping_service'
|
6
7
|
require 'gorgon/gem_service'
|
@@ -20,6 +21,18 @@ def listen
|
|
20
21
|
l.listen
|
21
22
|
end
|
22
23
|
|
24
|
+
def start_rsync_daemon
|
25
|
+
puts "Starting rsync daemon..."
|
26
|
+
exit 1 unless RsyncDaemon.start ARGV[1]
|
27
|
+
puts "Rsync Daemon is running. Use 'gorgon stop_rsync' to kill it."
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop_rsync_daemon
|
31
|
+
puts "Stopping rsync daemon..."
|
32
|
+
exit 1 unless RsyncDaemon.stop
|
33
|
+
puts "Done"
|
34
|
+
end
|
35
|
+
|
23
36
|
def manage_workers
|
24
37
|
config_path = ENV["GORGON_CONFIG_PATH"]
|
25
38
|
|
@@ -53,6 +66,8 @@ def usage
|
|
53
66
|
puts "\tping - pings listeners and shows hosts and gorgon's version they are running"
|
54
67
|
puts "\tinit [rails] - create initial files for current project"
|
55
68
|
puts "\tinstall_listener - runs gorgon listener as a daemon process"
|
69
|
+
puts "\tstart_rsync <directory> - start rsync daemon. Run this command in File Server"
|
70
|
+
puts "\tstop_rsync - stop rsync daemon."
|
56
71
|
puts "\tgem command [options...] - execute the gem command on every listener and shutdown listener. e.g. 'gorgon gem install --version 1.0.0'"
|
57
72
|
end
|
58
73
|
|
@@ -65,6 +80,10 @@ when "start"
|
|
65
80
|
start
|
66
81
|
when "listen"
|
67
82
|
listen
|
83
|
+
when "start_rsync"
|
84
|
+
start_rsync_daemon
|
85
|
+
when "stop_rsync"
|
86
|
+
stop_rsync_daemon
|
68
87
|
when "manage_workers"
|
69
88
|
manage_workers
|
70
89
|
when "ping"
|
data/lib/gorgon/originator.rb
CHANGED
@@ -4,7 +4,7 @@ require 'gorgon/job_state'
|
|
4
4
|
require 'gorgon/progress_bar_view'
|
5
5
|
require 'gorgon/originator_logger'
|
6
6
|
require 'gorgon/failures_printer'
|
7
|
-
require 'gorgon/
|
7
|
+
require 'gorgon/source_tree_syncer'
|
8
8
|
require 'gorgon/shutdown_manager.rb'
|
9
9
|
|
10
10
|
require 'awesome_print'
|
@@ -16,7 +16,6 @@ class Originator
|
|
16
16
|
|
17
17
|
def initialize
|
18
18
|
@configuration = nil
|
19
|
-
@rsync_daemon = RsyncDaemon.new
|
20
19
|
end
|
21
20
|
|
22
21
|
def originate
|
@@ -39,8 +38,7 @@ class Originator
|
|
39
38
|
|
40
39
|
def cancel_job
|
41
40
|
ShutdownManager.new(protocol: @protocol,
|
42
|
-
job_state: @job_state
|
43
|
-
rsync_daemon: @rsync_daemon).cancel_job
|
41
|
+
job_state: @job_state).cancel_job
|
44
42
|
end
|
45
43
|
|
46
44
|
def ctrl_c
|
@@ -56,10 +54,7 @@ class Originator
|
|
56
54
|
exit 2
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
|
-
@logger.log_error "rsync daemon didn't start!"
|
61
|
-
exit 1
|
62
|
-
end
|
57
|
+
push_source_code
|
63
58
|
|
64
59
|
@protocol = OriginatorProtocol.new @logger
|
65
60
|
|
@@ -81,11 +76,24 @@ class Originator
|
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
79
|
+
def push_source_code
|
80
|
+
syncer = SourceTreeSyncer.new(source_tree_path)
|
81
|
+
syncer.exclude = configuration[:sync_exclude]
|
82
|
+
syncer.push
|
83
|
+
if syncer.success?
|
84
|
+
@logger.log "Command '#{syncer.sys_command}' completed successfully."
|
85
|
+
else
|
86
|
+
$stderr.puts "Command '#{syncer.sys_command}' failed!"
|
87
|
+
$stderr.puts "Stdout:\n#{syncer.output}"
|
88
|
+
$stderr.puts "Stderr:\n#{syncer.errors}"
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
84
93
|
def cleanup_if_job_complete
|
85
94
|
if @job_state.is_job_complete?
|
86
95
|
@logger.log "Job is done"
|
87
96
|
@protocol.disconnect
|
88
|
-
@rsync_daemon.stop
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
@@ -137,22 +145,24 @@ class Originator
|
|
137
145
|
def job_definition
|
138
146
|
job_config = configuration[:job]
|
139
147
|
if !job_config.has_key?(:source_tree_path)
|
140
|
-
job_config[:source_tree_path] =
|
148
|
+
job_config[:source_tree_path] = source_tree_path
|
141
149
|
end
|
142
150
|
JobDefinition.new(configuration[:job])
|
143
151
|
end
|
144
152
|
|
145
153
|
private
|
146
154
|
|
147
|
-
def
|
148
|
-
|
155
|
+
def source_tree_path
|
156
|
+
hostname = Socket.gethostname
|
157
|
+
source_code_root = File.basename(Dir.pwd)
|
149
158
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
159
|
+
"rsync://#{file_server_host}:43434/src/#{hostname}_#{source_code_root}"
|
160
|
+
end
|
161
|
+
|
162
|
+
def file_server_host
|
163
|
+
file_server = configuration[:file_server]
|
164
|
+
raise 'Please, provide file_server configuration.' if file_server.nil?
|
165
|
+
configuration[:file_server][:host]
|
156
166
|
end
|
157
167
|
|
158
168
|
def configuration
|
data/lib/gorgon/rsync_daemon.rb
CHANGED
@@ -6,37 +6,33 @@ class RsyncDaemon
|
|
6
6
|
RSYNC_PORT = 43434
|
7
7
|
PID_FILE = 'rsync.pid'
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def start
|
15
|
-
return if @started
|
9
|
+
def self.start(directory_bucket)
|
10
|
+
if directory_bucket.nil? || !File.directory?(directory_bucket)
|
11
|
+
$stderr.puts "Please, expecify a valid directory."
|
12
|
+
return false
|
13
|
+
end
|
16
14
|
|
17
15
|
if !port_available?
|
18
16
|
puts port_busy_msg
|
19
17
|
return false
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
Dir.mkdir(RSYNC_DIR_NAME)
|
23
|
-
success =
|
21
|
+
success = false
|
24
22
|
Dir.chdir(RSYNC_DIR_NAME) do
|
25
|
-
File.write("rsyncd.conf", rsyncd_config_string(
|
23
|
+
File.write("rsyncd.conf", rsyncd_config_string(directory_bucket))
|
26
24
|
|
27
25
|
success = Kernel.system("rsync --daemon --config rsyncd.conf")
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
@started = true
|
32
|
-
return true
|
33
|
-
else
|
34
|
-
return false
|
35
|
-
end
|
28
|
+
success
|
36
29
|
end
|
37
30
|
|
38
|
-
def stop
|
39
|
-
|
31
|
+
def self.stop
|
32
|
+
if !File.directory?(RSYNC_DIR_NAME)
|
33
|
+
puts "ERROR: Directory '#{RSYNC_DIR_NAME}' doesn't exists. Maybe rsync daemon is not running!"
|
34
|
+
return false
|
35
|
+
end
|
40
36
|
|
41
37
|
success = nil
|
42
38
|
Dir.chdir(RSYNC_DIR_NAME) do
|
@@ -45,7 +41,6 @@ class RsyncDaemon
|
|
45
41
|
end
|
46
42
|
|
47
43
|
if success
|
48
|
-
@started = false
|
49
44
|
FileUtils::remove_entry_secure(RSYNC_DIR_NAME)
|
50
45
|
return true
|
51
46
|
else
|
@@ -55,19 +50,19 @@ class RsyncDaemon
|
|
55
50
|
|
56
51
|
private
|
57
52
|
|
58
|
-
def rsyncd_config_string(
|
53
|
+
def self.rsyncd_config_string(directory_bucket)
|
59
54
|
return <<-EOF
|
60
55
|
port = #{RSYNC_PORT}
|
61
56
|
pid file = #{PID_FILE}
|
62
57
|
|
63
58
|
[src]
|
64
|
-
path = #{
|
65
|
-
read only =
|
59
|
+
path = #{directory_bucket}
|
60
|
+
read only = false
|
66
61
|
use chroot = false
|
67
62
|
EOF
|
68
63
|
end
|
69
64
|
|
70
|
-
def port_available?
|
65
|
+
def self.port_available?
|
71
66
|
begin
|
72
67
|
s = TCPServer.new('localhost', RSYNC_PORT)
|
73
68
|
s.close
|
@@ -77,7 +72,7 @@ EOF
|
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
80
|
-
def port_busy_msg
|
75
|
+
def self.port_busy_msg
|
81
76
|
<<-MSG
|
82
77
|
ERROR: port #{RSYNC_PORT} is being used. Maybe another rsync daemon is running.
|
83
78
|
Kill pid in #{RSYNC_DIR_NAME}/#{PID_FILE} or check no other process is using that port."
|
@@ -21,9 +21,7 @@ module Settings
|
|
21
21
|
{name: :after_creating_workers, file_name: "after_creating_workers.rb",
|
22
22
|
content: after_creating_workers_content},
|
23
23
|
{name: :before_start, file_name: "before_start.rb",
|
24
|
-
content: before_start_content}
|
25
|
-
{name: :after_complete, file_name: "after_complete.rb",
|
26
|
-
content: after_complete_content}]
|
24
|
+
content: before_start_content}]
|
27
25
|
end
|
28
26
|
|
29
27
|
def get_app_subdir
|
@@ -39,26 +37,26 @@ module Settings
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def after_sync_content
|
42
|
-
<<-CONTENT
|
40
|
+
<<-'CONTENT'
|
43
41
|
require 'bundler'
|
44
42
|
require 'open4'
|
45
43
|
|
46
44
|
Bundler.with_clean_env do
|
47
45
|
BUNDLE_LOG_FILE||="/tmp/gorgon-bundle-install.log "
|
48
46
|
|
49
|
-
pid, stdin, stdout, stderr = Open4::popen4 "bundle install >
|
47
|
+
pid, stdin, stdout, stderr = Open4::popen4 "bundle install > #{BUNDLE_LOG_FILE} 2>&1 "
|
50
48
|
|
51
49
|
ignore, status = Process.waitpid2 pid
|
52
50
|
|
53
51
|
if status.exitstatus != 0
|
54
|
-
raise "ERROR: 'bundle install' failed.\n
|
52
|
+
raise "ERROR: 'bundle install' failed.\n#{stderr.read}"
|
55
53
|
end
|
56
54
|
end
|
57
55
|
CONTENT
|
58
56
|
end
|
59
57
|
|
60
58
|
def before_creating_workers_content
|
61
|
-
<<-CONTENT
|
59
|
+
<<-'CONTENT'
|
62
60
|
ENV["TEST_ENV_NUMBER"] = Process.pid.to_s
|
63
61
|
ENV["RAILS_ENV"] = 'remote_test'
|
64
62
|
|
@@ -69,16 +67,31 @@ if status.exitstatus != 0
|
|
69
67
|
raise "ERROR: 'rake db:setup' failed.\n#{stderr.read}\n#{stdout.read}"
|
70
68
|
end
|
71
69
|
|
72
|
-
|
70
|
+
spec_helper_file = File.expand_path('../../spec_helper', __FILE__)
|
71
|
+
test_helper_file = File.expand_path('../../test_helper', __FILE__)
|
72
|
+
|
73
|
+
require spec_helper_file if File.exist?(spec_helper_file)
|
74
|
+
require test_helper_file if File.exist?(test_helper_file)
|
73
75
|
CONTENT
|
74
76
|
end
|
75
77
|
|
76
78
|
def after_creating_workers_content
|
77
|
-
|
79
|
+
<<-'CONTENT'
|
80
|
+
require 'rake'
|
81
|
+
load './Rakefile'
|
82
|
+
|
83
|
+
begin
|
84
|
+
if Rails.env = 'remote_test'
|
85
|
+
Rake::Task['db:drop'].execute
|
86
|
+
end
|
87
|
+
rescue Exception => ex
|
88
|
+
puts "Error dropping test database:\n #{ex}"
|
89
|
+
end
|
90
|
+
CONTENT
|
78
91
|
end
|
79
92
|
|
80
93
|
def before_start_content
|
81
|
-
<<-CONTENT
|
94
|
+
<<-'CONTENT'
|
82
95
|
require 'rake'
|
83
96
|
load './Rakefile'
|
84
97
|
|
@@ -89,21 +102,6 @@ begin
|
|
89
102
|
Rake::Task['db:reset'].invoke
|
90
103
|
end
|
91
104
|
|
92
|
-
CONTENT
|
93
|
-
end
|
94
|
-
|
95
|
-
def after_complete_content
|
96
|
-
<<-CONTENT
|
97
|
-
require 'rake'
|
98
|
-
load './Rakefile'
|
99
|
-
|
100
|
-
begin
|
101
|
-
if Rails.env = 'remote_test'
|
102
|
-
Rake::Task['db:drop'].execute
|
103
|
-
end
|
104
|
-
rescue Exception => ex
|
105
|
-
puts "Error dropping test database:\n \#\{ex\}"
|
106
|
-
end
|
107
105
|
CONTENT
|
108
106
|
end
|
109
107
|
end
|
@@ -3,7 +3,6 @@ class ShutdownManager
|
|
3
3
|
def initialize(args)
|
4
4
|
@protocol = args.fetch(:protocol)
|
5
5
|
@job_state = args.fetch(:job_state)
|
6
|
-
@rsync_daemon = args.fetch(:rsync_daemon)
|
7
6
|
end
|
8
7
|
|
9
8
|
def cancel_job
|
@@ -22,11 +21,5 @@ class ShutdownManager
|
|
22
21
|
|
23
22
|
def disconnect_protocol
|
24
23
|
@protocol.disconnect if @protocol
|
25
|
-
ensure
|
26
|
-
stop_rsync_daemon
|
27
|
-
end
|
28
|
-
|
29
|
-
def stop_rsync_daemon
|
30
|
-
@rsync_daemon.stop if @rsync_daemon
|
31
24
|
end
|
32
25
|
end
|
@@ -5,7 +5,7 @@ class SourceTreeSyncer
|
|
5
5
|
attr_reader :sys_command, :output, :errors
|
6
6
|
|
7
7
|
SYS_COMMAND = 'rsync'
|
8
|
-
OPTS = "-azr --timeout=5"
|
8
|
+
OPTS = "-azr --timeout=5 --delete"
|
9
9
|
EXCLUDE_OPT = "--exclude"
|
10
10
|
|
11
11
|
def initialize source_tree_path
|
@@ -19,17 +19,17 @@ class SourceTreeSyncer
|
|
19
19
|
@tempdir = Dir.mktmpdir("gorgon")
|
20
20
|
Dir.chdir(@tempdir)
|
21
21
|
|
22
|
-
|
23
|
-
@sys_command = "#{SYS_COMMAND} #{OPTS} #{exclude_opt} #{@source_tree_path}/ ."
|
22
|
+
@sys_command = "#{SYS_COMMAND} #{OPTS} #{build_exclude_opt} #{@source_tree_path}/ ."
|
24
23
|
|
25
|
-
|
26
|
-
|
24
|
+
execute_command
|
25
|
+
end
|
27
26
|
|
28
|
-
|
27
|
+
def push
|
28
|
+
return if blank_source_tree_path?
|
29
29
|
|
30
|
-
@
|
30
|
+
@sys_command = "#{SYS_COMMAND} #{OPTS} #{build_exclude_opt} . #{@source_tree_path}"
|
31
31
|
|
32
|
-
|
32
|
+
execute_command
|
33
33
|
end
|
34
34
|
|
35
35
|
def success?
|
@@ -42,6 +42,17 @@ class SourceTreeSyncer
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
+
def execute_command
|
46
|
+
pid, stdin, stdout, stderr = Open4::popen4 @sys_command
|
47
|
+
stdin.close
|
48
|
+
|
49
|
+
ignore, status = Process.waitpid2 pid
|
50
|
+
|
51
|
+
@output, @errors = [stdout, stderr].map { |p| begin p.read ensure p.close end }
|
52
|
+
|
53
|
+
@exitstatus = status.exitstatus
|
54
|
+
end
|
55
|
+
|
45
56
|
def blank_source_tree_path?
|
46
57
|
if @source_tree_path.nil?
|
47
58
|
@errors = "Source tree path cannot be nil. Check your gorgon.json file."
|
data/lib/gorgon/version.rb
CHANGED
data/spec/originator_spec.rb
CHANGED
@@ -5,16 +5,17 @@ describe Originator do
|
|
5
5
|
:publish_job => nil, :receive_payloads => nil, :cancel_job => nil,
|
6
6
|
:disconnect => nil)}
|
7
7
|
|
8
|
-
let(:configuration){ {:job => {}, :files => ["some/file"]}}
|
8
|
+
let(:configuration){ {:job => {}, :files => ["some/file"], :file_server => {:host => 'host-name'}}}
|
9
9
|
let(:job_state){ stub("JobState", :is_job_complete? => false, :file_finished => nil,
|
10
10
|
:add_observer => nil)}
|
11
11
|
let(:progress_bar_view){ stub("Progress Bar View", :show => nil)}
|
12
12
|
let(:originator_logger){ stub("Originator Logger", :log => nil, :log_message => nil)}
|
13
|
-
let(:
|
13
|
+
let(:source_tree_syncer) { stub("Source Tree Syncer", :push => nil, :exclude= => nil, :success? => true,
|
14
|
+
:sys_command => 'command')}
|
14
15
|
|
15
16
|
before do
|
16
17
|
OriginatorLogger.stub(:new).and_return originator_logger
|
17
|
-
|
18
|
+
SourceTreeSyncer.stub(:new).and_return source_tree_syncer
|
18
19
|
Dir.stub(:[]).and_return(["file"])
|
19
20
|
@originator = Originator.new
|
20
21
|
end
|
@@ -38,8 +39,9 @@ describe Originator do
|
|
38
39
|
@originator.publish
|
39
40
|
end
|
40
41
|
|
41
|
-
it "
|
42
|
-
|
42
|
+
it "pushes source code" do
|
43
|
+
source_tree_syncer.should_receive(:push)
|
44
|
+
source_tree_syncer.should_receive(:success?).and_return true
|
43
45
|
|
44
46
|
@originator.publish
|
45
47
|
end
|
@@ -49,7 +51,7 @@ describe Originator do
|
|
49
51
|
|
50
52
|
$stderr.should_receive(:puts)
|
51
53
|
OriginatorProtocol.should_not_receive(:new)
|
52
|
-
|
54
|
+
source_tree_syncer.should_not_receive(:push)
|
53
55
|
|
54
56
|
expect { @originator.publish }.to raise_error(SystemExit)
|
55
57
|
end
|
@@ -65,7 +67,7 @@ describe Originator do
|
|
65
67
|
JobState.stub!(:new).and_return job_state
|
66
68
|
|
67
69
|
ShutdownManager.should_receive(:new).
|
68
|
-
with(hash_including(protocol: protocol, job_state: job_state
|
70
|
+
with(hash_including(protocol: protocol, job_state: job_state)).
|
69
71
|
and_return(shutdown_manager)
|
70
72
|
shutdown_manager.should_receive(:cancel_job)
|
71
73
|
|
@@ -91,13 +93,6 @@ describe Originator do
|
|
91
93
|
protocol.should_receive(:disconnect)
|
92
94
|
@originator.cleanup_if_job_complete
|
93
95
|
end
|
94
|
-
|
95
|
-
it "stops the rsync daemon" do
|
96
|
-
job_state.stub!(:is_job_complete?).and_return true
|
97
|
-
rsync_daemon.should_receive(:stop)
|
98
|
-
|
99
|
-
@originator.cleanup_if_job_complete
|
100
|
-
end
|
101
96
|
end
|
102
97
|
|
103
98
|
describe "#handle_reply" do
|
@@ -134,10 +129,6 @@ describe Originator do
|
|
134
129
|
end
|
135
130
|
|
136
131
|
describe "#job_definition" do
|
137
|
-
before do
|
138
|
-
UDPSocket.any_instance.stub(:connect)
|
139
|
-
end
|
140
|
-
|
141
132
|
it "returns a JobDefinition object" do
|
142
133
|
@originator.stub!(:configuration).and_return configuration
|
143
134
|
job_definition = JobDefinition.new
|
@@ -146,9 +137,11 @@ describe Originator do
|
|
146
137
|
end
|
147
138
|
|
148
139
|
it "builds source_tree_path if it was not specified in the configuration" do
|
149
|
-
@originator.stub!(:configuration).and_return({:
|
150
|
-
|
151
|
-
|
140
|
+
@originator.stub!(:configuration).and_return(configuration.merge(:file_server => {:host => 'host-name'}))
|
141
|
+
Socket.stub(:gethostname => 'my-host')
|
142
|
+
Dir.stub(:pwd => 'dir')
|
143
|
+
|
144
|
+
@originator.job_definition.source_tree_path.should == "rsync://host-name:43434/src/my-host_dir"
|
152
145
|
end
|
153
146
|
|
154
147
|
it "returns source_tree_path specified in configuration if it is present" do
|
data/spec/rsync_daemon_spec.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
require 'gorgon/rsync_daemon'
|
2
2
|
|
3
3
|
describe RsyncDaemon do
|
4
|
+
let(:directory) {'/lol/hax'}
|
5
|
+
|
4
6
|
before(:each) do
|
5
7
|
Kernel.stub(:system => true)
|
6
|
-
Dir.stub(:mkdir => nil
|
8
|
+
Dir.stub(:mkdir => nil)
|
7
9
|
Dir.stub(:chdir).and_yield
|
8
|
-
File.stub(:write => 100, :read => "12345")
|
10
|
+
File.stub(:write => 100, :read => "12345", :directory? => true)
|
9
11
|
FileUtils.stub(:remove_entry_secure => nil)
|
10
|
-
|
12
|
+
TCPServer.stub(:new => double('TCPServer', :close => nil))
|
13
|
+
@r = RsyncDaemon
|
11
14
|
end
|
12
15
|
|
13
16
|
it "starts the rsync daemon" do
|
14
17
|
Kernel.should_receive(:system).with("rsync --daemon --config rsyncd.conf")
|
15
18
|
|
16
|
-
@r.start
|
19
|
+
@r.start(directory)
|
17
20
|
end
|
18
21
|
|
19
22
|
it "creates a directory in temporary dir for the configuration and pid files" do
|
20
23
|
Dir.should_receive(:mkdir).with(RsyncDaemon::RSYNC_DIR_NAME)
|
21
24
|
Dir.should_receive(:chdir).with(RsyncDaemon::RSYNC_DIR_NAME)
|
22
25
|
|
23
|
-
@r.start
|
26
|
+
@r.start(directory)
|
24
27
|
end
|
25
28
|
|
26
29
|
it "writes the config file" do
|
@@ -30,47 +33,26 @@ pid file = rsync.pid
|
|
30
33
|
|
31
34
|
[src]
|
32
35
|
path = /lol/hax
|
33
|
-
read only =
|
36
|
+
read only = false
|
34
37
|
use chroot = false
|
35
38
|
EOF
|
36
39
|
File.should_receive(:write).with("rsyncd.conf", valid_config)
|
37
40
|
|
38
|
-
@r.start
|
41
|
+
@r.start(directory)
|
39
42
|
end
|
40
43
|
|
41
44
|
it "reports when an error has prevented startup" do
|
42
45
|
Kernel.should_receive(:system).and_return(false)
|
43
46
|
|
44
|
-
@r.start.should == false
|
45
|
-
end
|
46
|
-
|
47
|
-
it "only starts once" do
|
48
|
-
Kernel.should_receive(:system).once
|
49
|
-
|
50
|
-
@r.start
|
51
|
-
@r.start
|
47
|
+
@r.start(directory).should == false
|
52
48
|
end
|
53
49
|
|
54
50
|
it "stops the rsync daemon" do
|
55
|
-
@r.start
|
51
|
+
@r.start(directory)
|
56
52
|
|
57
53
|
File.should_receive(:read).with("rsync.pid").and_return("12345")
|
58
54
|
Kernel.should_receive(:system).with("kill 12345")
|
59
55
|
|
60
56
|
@r.stop
|
61
57
|
end
|
62
|
-
|
63
|
-
it "only tries to stop if the daemon is started" do
|
64
|
-
Kernel.should_not_receive(:system)
|
65
|
-
|
66
|
-
@r.stop
|
67
|
-
end
|
68
|
-
|
69
|
-
it "can be restarted" do
|
70
|
-
Kernel.should_receive(:system).exactly(3).times
|
71
|
-
|
72
|
-
@r.start
|
73
|
-
@r.stop
|
74
|
-
@r.start
|
75
|
-
end
|
76
58
|
end
|
@@ -4,7 +4,6 @@ describe ShutdownManager do
|
|
4
4
|
let(:protocol){ stub("Originator Protocol", :cancel_job => nil, :disconnect => nil)}
|
5
5
|
|
6
6
|
let(:job_state){ stub("JobState", cancel: nil)}
|
7
|
-
let(:rsync_daemon) { stub("Rsync Daemon", :stop => true)}
|
8
7
|
|
9
8
|
describe '#cancel_job' do
|
10
9
|
it "call JobState#cancel" do
|
@@ -20,20 +19,13 @@ describe ShutdownManager do
|
|
20
19
|
shutdown_manager(protocol: protocol).cancel_job
|
21
20
|
end
|
22
21
|
|
23
|
-
it "stops the rsync daemon" do
|
24
|
-
rsync_daemon.should_receive(:stop)
|
25
|
-
|
26
|
-
shutdown_manager(rsync_daemon: rsync_daemon).cancel_job
|
27
|
-
end
|
28
|
-
|
29
22
|
it 'finishes cancelling job even when some cancelling steps fail' do
|
30
23
|
protocol.should_receive(:cancel_job).and_raise StandardError
|
31
24
|
job_state.should_receive(:cancel).and_raise StandardError
|
32
25
|
protocol.should_receive(:disconnect).and_raise StandardError
|
33
|
-
rsync_daemon.should_receive(:stop).and_raise StandardError
|
34
26
|
|
35
27
|
expect {
|
36
|
-
shutdown_manager(protocol: protocol, job_state: job_state
|
28
|
+
shutdown_manager(protocol: protocol, job_state: job_state).cancel_job
|
37
29
|
}.to raise_error StandardError
|
38
30
|
end
|
39
31
|
end
|
@@ -41,8 +33,7 @@ describe ShutdownManager do
|
|
41
33
|
def shutdown_manager(args)
|
42
34
|
defaults = {
|
43
35
|
protocol: protocol,
|
44
|
-
job_state: job_state
|
45
|
-
rsync_daemon: rsync_daemon
|
36
|
+
job_state: job_state
|
46
37
|
}
|
47
38
|
ShutdownManager.new(defaults.merge(args))
|
48
39
|
end
|
@@ -3,6 +3,7 @@ require 'gorgon/source_tree_syncer'
|
|
3
3
|
describe SourceTreeSyncer.new("") do
|
4
4
|
it { should respond_to :exclude= }
|
5
5
|
it { should respond_to :sync }
|
6
|
+
it { should respond_to :push }
|
6
7
|
it { should respond_to :sys_command }
|
7
8
|
it { should respond_to :remove_temp_dir }
|
8
9
|
it { should respond_to :success? }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorgon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Fitzsimmons
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-
|
15
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -360,9 +360,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
360
360
|
version: '0'
|
361
361
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
362
362
|
requirements:
|
363
|
-
- - ! '
|
363
|
+
- - ! '>'
|
364
364
|
- !ruby/object:Gem::Version
|
365
|
-
version:
|
365
|
+
version: 1.3.1
|
366
366
|
requirements: []
|
367
367
|
rubyforge_project: gorgon
|
368
368
|
rubygems_version: 2.1.11
|