drbqs 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/.document +3 -0
  2. data/README.md +137 -128
  3. data/VERSION +1 -1
  4. data/docs/FormatExecute.md +119 -0
  5. data/docs/GettingStarted.md +242 -0
  6. data/drbqs.gemspec +36 -13
  7. data/example/command/server_def.rb +4 -5
  8. data/example/execute/execute.rb +41 -0
  9. data/example/execute/server.rb +14 -0
  10. data/example/execute/task.rb +0 -0
  11. data/example/mandelbrot/README.md +15 -0
  12. data/example/mandelbrot/execute.rb +10 -0
  13. data/example/mandelbrot/mandelbrot.rb +56 -0
  14. data/example/mandelbrot/server.rb +49 -0
  15. data/example/server/server.rb +3 -6
  16. data/example/simple/README.md +18 -0
  17. data/example/simple/execute.rb +11 -0
  18. data/example/simple/server.rb +8 -0
  19. data/example/simple/task.rb +11 -0
  20. data/example/sum/server_def.rb +1 -1
  21. data/example/sum2/execute_def.rb +21 -8
  22. data/example/sum2/server_def.rb +8 -7
  23. data/example/transfer/file.rb +42 -8
  24. data/example/transfer/server_def.rb +43 -9
  25. data/lib/drbqs.rb +1 -1
  26. data/lib/drbqs/command_line/command_execute.rb +3 -3
  27. data/lib/drbqs/command_line/command_line.rb +1 -1
  28. data/lib/drbqs/execute/execute_node.rb +50 -0
  29. data/lib/drbqs/execute/process_define.rb +102 -54
  30. data/lib/drbqs/execute/register.rb +241 -87
  31. data/lib/drbqs/execute/server_define.rb +69 -58
  32. data/lib/drbqs/ext/task.rb +2 -0
  33. data/lib/drbqs/ext/task/command_task.rb +43 -0
  34. data/lib/drbqs/manage/manage.rb +5 -4
  35. data/lib/drbqs/manage/ssh_shell.rb +2 -8
  36. data/lib/drbqs/node/connection.rb +1 -1
  37. data/lib/drbqs/node/node.rb +8 -14
  38. data/lib/drbqs/node/task_client.rb +1 -1
  39. data/lib/drbqs/server/history.rb +5 -1
  40. data/lib/drbqs/server/message.rb +7 -34
  41. data/lib/drbqs/server/queue.rb +14 -2
  42. data/lib/drbqs/server/server.rb +86 -43
  43. data/lib/drbqs/server/server_hook.rb +3 -0
  44. data/lib/drbqs/server/test/node.rb +1 -1
  45. data/lib/drbqs/server/test/prof.rb +50 -0
  46. data/lib/drbqs/server/test/server.rb +2 -2
  47. data/lib/drbqs/server/transfer_setting.rb +23 -11
  48. data/lib/drbqs/setting/base.rb +15 -0
  49. data/lib/drbqs/setting/data_container.rb +1 -1
  50. data/lib/drbqs/setting/execute.rb +3 -3
  51. data/lib/drbqs/setting/node.rb +1 -1
  52. data/lib/drbqs/setting/server.rb +2 -2
  53. data/lib/drbqs/task/registrar.rb +39 -0
  54. data/lib/drbqs/task/task.rb +139 -59
  55. data/lib/drbqs/task/task_generator.rb +93 -116
  56. data/lib/drbqs/utility/misc.rb +15 -10
  57. data/lib/drbqs/utility/temporary.rb +7 -2
  58. data/lib/drbqs/utility/transfer/transfer.rb +81 -0
  59. data/lib/drbqs/utility/transfer/transfer_client.rb +68 -69
  60. data/lib/drbqs/utility/transfer/transfer_client_connect.rb +83 -0
  61. data/lib/drbqs/utility/transfer/transfer_file_list.rb +40 -0
  62. data/spec/execute/def/execute1.rb +4 -4
  63. data/spec/execute/def/execute2.rb +24 -0
  64. data/spec/execute/process_define_spec.rb +43 -6
  65. data/spec/execute/register_spec.rb +403 -9
  66. data/spec/execute/server_define_spec.rb +1 -1
  67. data/spec/ext/task/command_task_spec.rb +16 -0
  68. data/spec/integration_test/01_basic_usage_spec.rb +1 -1
  69. data/spec/integration_test/02_use_generator_spec.rb +2 -2
  70. data/spec/integration_test/04_use_unix_domain_spec.rb +1 -1
  71. data/spec/integration_test/05_server_exit_signal_spec.rb +1 -1
  72. data/spec/integration_test/06_node_exit_after_task_spec.rb +4 -4
  73. data/spec/integration_test/08_shutdown_unused_nodes_spec.rb +2 -2
  74. data/spec/integration_test/09_server_process_data_spec.rb +1 -1
  75. data/spec/integration_test/definition/server01.rb +4 -5
  76. data/spec/integration_test/definition/server02.rb +2 -4
  77. data/spec/node/node_spec.rb +34 -0
  78. data/spec/server/message_spec.rb +1 -1
  79. data/spec/server/queue_spec.rb +34 -7
  80. data/spec/server/server_spec.rb +21 -9
  81. data/spec/server/transfer_setting_spec.rb +59 -24
  82. data/spec/setting/base_spec.rb +11 -0
  83. data/spec/setting/data_container_spec.rb +8 -0
  84. data/spec/spec_helper.rb +1 -7
  85. data/spec/task/registrar_spec.rb +34 -0
  86. data/spec/task/task_generator_spec.rb +15 -15
  87. data/spec/task/task_spec.rb +132 -23
  88. data/spec/utility/misc_spec.rb +2 -2
  89. data/spec/utility/transfer/transfer_client_connect_spec.rb +90 -0
  90. data/spec/utility/transfer/transfer_file_list_spec.rb +27 -0
  91. data/spec/{task/file_transfer_spec.rb → utility/transfer/transfer_spec.rb} +24 -24
  92. metadata +66 -45
  93. data/lib/drbqs/manage/execute_node.rb +0 -50
  94. data/lib/drbqs/server/prof.rb +0 -48
  95. data/lib/drbqs/task/command_task.rb +0 -43
  96. data/lib/drbqs/utility/transfer/file_transfer.rb +0 -73
@@ -0,0 +1,83 @@
1
+ require 'net/sftp'
2
+
3
+ module DRbQS
4
+ class Transfer
5
+ class Client
6
+ class Base
7
+ def initialize(server_directory)
8
+ @directory = server_directory
9
+ end
10
+
11
+ def upload_name(path)
12
+ File.join(@directory, File.basename(path))
13
+ end
14
+ private :upload_name
15
+
16
+ def directory_for_download(path)
17
+ dir = DRbQS::Temporary.directory
18
+ [dir, File.join(dir, File.basename(path))]
19
+ end
20
+ private :directory_for_download
21
+ end
22
+
23
+ # Transfer files to directory on DRbQS server over sftp.
24
+ # Note that after we transfer files we delete the original files.
25
+ class SFTP < DRbQS::Transfer::Client::Base
26
+ attr_reader :user, :host, :directory
27
+
28
+ def initialize(user, host, directory)
29
+ super(directory)
30
+ @user = user
31
+ @host = host
32
+ end
33
+
34
+ def start_sftp(&block)
35
+ Net::SFTP.start(@host, @user, &block)
36
+ end
37
+ private :start_sftp
38
+
39
+ # Transfer and delete +files+.
40
+ def transfer(files)
41
+ start_sftp do |sftp|
42
+ files.each do |path|
43
+ sftp.upload(path, upload_name(path))
44
+ FileUtils.rm_r(path)
45
+ end
46
+ end
47
+ rescue => err
48
+ raise err.class, "user=#{@user}, host=#{@host}, directory=#{@directory}; #{err.to_s}", err.backtrace
49
+ end
50
+
51
+ def download(files)
52
+ moved = []
53
+ start_sftp do |sftp|
54
+ files.each do |path|
55
+ dir, downloaded_path = directory_for_download(path)
56
+ sftp.download(path, dir, :recursive => true)
57
+ moved << downloaded_path
58
+ end
59
+ end
60
+ moved
61
+ rescue => err
62
+ raise err.class, "user=#{@user}, host=#{@host}, directory=#{@directory}; #{err.to_s}", err.backtrace
63
+ end
64
+ end
65
+
66
+ class Local < DRbQS::Transfer::Client::Base
67
+ def transfer(files)
68
+ files.each do |path|
69
+ FileUtils.mv(path, upload_name(path))
70
+ end
71
+ end
72
+
73
+ def download(files)
74
+ files.map do |path|
75
+ dir, downloaded_path = directory_for_download(path)
76
+ FileUtils.cp_r(path, dir)
77
+ downloaded_path
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,40 @@
1
+ module DRbQS
2
+ # Class for path of files to send from server to a node.
3
+ class Transfer
4
+ class FileList
5
+ # Initialization is executed on server.
6
+ # If :readonly option is true, nodes on same computer as server
7
+ # does not copy files.
8
+ # Therefore, if we edit the files then the change remains.
9
+ # If :readonly option is not true then the files is copied,
10
+ # so the original files are not changed.
11
+ def initialize(*files)
12
+ opts = (Hash === files[-1] ? files.pop : {})
13
+ @readonly = opts[:readonly]
14
+ @files = files.map do |path|
15
+ epath = File.expand_path(path)
16
+ unless File.exist?(epath)
17
+ raise ArgumentError, "#{epath} does not exist."
18
+ end
19
+ epath
20
+ end
21
+ @downloaded = nil
22
+ @path = nil
23
+ end
24
+
25
+ # This method is executed on a node.
26
+ def download
27
+ @downloaded = true
28
+ @path = DRbQS::Transfer::Client.get.download(@files, @readonly)
29
+ end
30
+ private :download
31
+
32
+ # Return an array of paths of downloaded files.
33
+ # Note that this method is executed on a node.
34
+ def path
35
+ download unless @downloaded
36
+ @path
37
+ end
38
+ end
39
+ end
40
+ end
@@ -5,20 +5,20 @@ usage message: "Usage of this definition.", server: server_file
5
5
 
6
6
  default log: '/tmp/drbqs_tmp_log'
7
7
 
8
- register_server 'server_local', 'localhost' do |server|
8
+ server 'server_local', 'localhost' do |server|
9
9
  server.load server_file
10
10
  end
11
11
 
12
- register_server 'server_ssh', 'example.com' do |server, ssh|
12
+ server 'server_ssh', 'example.com' do |server, ssh|
13
13
  ssh.connect "example.com"
14
14
  server.load 'server.rb'
15
15
  end
16
16
 
17
- register_node 'node_local' do |node|
17
+ node 'node_local' do |node|
18
18
  node.log_level = Logger::DEBUG
19
19
  end
20
20
 
21
- register_node 'node_ssh' do |node, ssh|
21
+ node 'node_ssh' do |node, ssh|
22
22
  ssh.connect "example.com"
23
23
  node.log_level = Logger::DEBUG
24
24
  end
@@ -0,0 +1,24 @@
1
+ # Use in process_define_spec.rb
2
+
3
+ server_file = File.join(File.dirname(__FILE__), '../../integration_test/definition/server02.rb')
4
+ usage message: "Usage of this definition.", server: server_file
5
+
6
+ default log: '/tmp/drbqs_tmp_log', node: [:node_ssh]
7
+
8
+ server 'server_local', 'localhost' do |server|
9
+ server.load server_file
10
+ end
11
+
12
+ server 'server_ssh', 'example.com' do |server, ssh|
13
+ ssh.connect "example.com"
14
+ server.load 'server.rb'
15
+ end
16
+
17
+ node 'node_local' do |node|
18
+ node.log_level = Logger::DEBUG
19
+ end
20
+
21
+ node 'node_ssh' do |node, ssh|
22
+ ssh.connect "example.com"
23
+ node.log_level = Logger::DEBUG
24
+ end
@@ -18,13 +18,27 @@ describe DRbQS::ProcessDefinition do
18
18
  end
19
19
 
20
20
  it "should get server list." do
21
- info = @info[:server].sort_by { |a| a [0] }
22
- info.should == [[:server_local, :server], [:server_ssh, :ssh]].sort_by { |a| a [0] }
21
+ data = @info[:server].assoc(:server_local)[1]
22
+ data[:type].should == :server
23
+ data[:ssh].should_not be_true
24
+ data[:args].should == ["localhost"]
25
+
26
+ data = @info[:server].assoc(:server_ssh)[1]
27
+ data[:type].should == :server
28
+ data[:ssh].should be_true
29
+ data[:args].should == ["example.com"]
23
30
  end
24
31
 
25
32
  it "should get node list." do
26
- info = @info[:node].sort_by { |a| a[0] }
27
- info.should == [[:node_local, :node], [:node_ssh, :ssh]].sort_by { |a| a[0] }
33
+ data = @info[:node].assoc(:node_local)[1]
34
+ data[:type].should == :node
35
+ data[:ssh].should_not be_true
36
+ data[:args].should == []
37
+
38
+ data = @info[:node].assoc(:node_ssh)[1]
39
+ data[:type].should == :node
40
+ data[:ssh].should be_true
41
+ data[:args].should == []
28
42
  end
29
43
 
30
44
  it "should get default server." do
@@ -103,7 +117,7 @@ describe DRbQS::ProcessDefinition do
103
117
  @tmp = '/tmp/drbqs_tmp_log' # defined in execute1.rb
104
118
  @process_def = DRbQS::ProcessDefinition.new(nil, nil, @port)
105
119
  @process_def.load(definition_file('execute1.rb'))
106
- @server_setting = subject.__send__(:get_server_setting)[:setting]
120
+ @server_setting = subject.__send__(:get_server_setting)[1][:setting]
107
121
  @node_local_setting = subject.__send__(:get_node_data, :node_local)[:setting]
108
122
  @node_ssh_setting = subject.__send__(:get_node_data, :node_ssh)[:setting]
109
123
  end
@@ -139,7 +153,7 @@ describe DRbQS::ProcessDefinition do
139
153
  @tmp = '/tmp/drbqs_tmp_log' # defined in execute1.rb
140
154
  @process_def = DRbQS::ProcessDefinition.new(nil, [:node_local], nil)
141
155
  @process_def.load(definition_file('execute1.rb'))
142
- @server_setting = subject.__send__(:get_server_setting)[:setting]
156
+ @server_setting = subject.__send__(:get_server_setting)[1][:setting]
143
157
  @node_local_setting = subject.__send__(:get_node_data, :node_local)[:setting]
144
158
  end
145
159
 
@@ -164,4 +178,27 @@ describe DRbQS::ProcessDefinition do
164
178
  FileUtils.rm_r(@tmp)
165
179
  end
166
180
  end
181
+
182
+ context "when execute default nodes" do
183
+ before(:all) do
184
+ @port = DRbQS::ROOT_DEFAULT_PORT
185
+ @hostname = 'localhost' # defined in execute1.rb
186
+ @tmp = '/tmp/drbqs_tmp_log' # defined in execute1.rb
187
+ @process_def = DRbQS::ProcessDefinition.new(nil, nil, nil)
188
+ @process_def.load(definition_file('execute2.rb'))
189
+ @server_setting = subject.__send__(:get_server_setting)[1][:setting]
190
+ @node_local_setting = subject.__send__(:get_node_data, :node_local)[:setting]
191
+ @node_ssh_setting = subject.__send__(:get_node_data, :node_ssh)[:setting]
192
+ end
193
+
194
+ subject do
195
+ @process_def
196
+ end
197
+
198
+ it "should check port number set in node." do
199
+ @node_local_setting.should_not_receive(:exec)
200
+ @node_ssh_setting.should_receive(:exec)
201
+ subject.execute_node
202
+ end
203
+ end
167
204
  end
@@ -10,53 +10,424 @@ describe DRbQS::ProcessDefinition::Register do
10
10
  context "when registering a server" do
11
11
  it "should define a server on localhost." do
12
12
  load_file = 'file.rb'
13
- subject.register_server(:server1) do |server|
13
+ subject.server(:server1, "example.com") do |server|
14
14
  server.load load_file
15
15
  end
16
16
  name, data = subject.__server__.assoc(:server1)
17
17
  data[:type].should == :server
18
- data[:setting].get(:load).should == [load_file]
18
+ data[:ssh].should be_false
19
+ data[:template].should be_false
20
+ setting = data[:setting]
21
+ setting.get(:load).should == [load_file]
22
+ setting.should be_an_instance_of DRbQS::Setting::Server
19
23
  end
20
24
 
21
25
  it "should define a server over ssh." do
22
26
  dest = "user@example.com"
23
27
  load_file = 'file.rb'
24
- subject.register_server(:server1) do |server, ssh|
28
+ subject.server(:server2, "example.com") do |server, ssh|
25
29
  server.load load_file
26
30
  ssh.connect dest
27
31
  end
28
- name, data = subject.__server__.assoc(:server1)
29
- data[:type].should == :ssh
32
+ name, data = subject.__server__.assoc(:server2)
33
+ data[:type].should == :server
34
+ data[:ssh].should be_true
35
+ data[:template].should be_false
30
36
  setting = data[:setting]
37
+ setting.should be_an_instance_of DRbQS::Setting::SSH
31
38
  setting.get(:connect).should == [dest]
32
39
  setting.mode_setting.get(:load).should == [load_file]
33
40
  end
41
+
42
+ it "should raise error for arguments without hostname." do
43
+ load_file = 'file.rb'
44
+ lambda do
45
+ subject.server(:server3) do |server|
46
+ server.load load_file
47
+ end
48
+ end.should raise_error
49
+ end
50
+
51
+ it "should set template." do
52
+ load_file = 'file.rb'
53
+ subject.server(:server4, :template => true) do |server|
54
+ server.load load_file
55
+ end
56
+ name, data = subject.__server__.assoc(:server4)
57
+ data[:template].should be_true
58
+ data[:ssh].should be_false
59
+ data[:type].should == :server
60
+ setting = data[:setting]
61
+ setting.get(:load).should == [load_file]
62
+ setting.should be_an_instance_of DRbQS::Setting::Server
63
+ end
64
+
65
+ it "should define a server over ssh." do
66
+ load_file = 'file.rb'
67
+ bash = "bash"
68
+ subject.server(:server5, :template => true) do |server, ssh|
69
+ server.load load_file
70
+ ssh.shell bash
71
+ end
72
+ name, data = subject.__server__.assoc(:server5)
73
+ data[:type].should == :server
74
+ data[:ssh].should be_true
75
+ data[:template].should be_true
76
+ setting = data[:setting]
77
+ setting.should be_an_instance_of DRbQS::Setting::SSH
78
+ setting.get(:shell).should == [bash]
79
+ setting.mode_setting.get(:load).should == [load_file]
80
+ end
34
81
  end
35
82
 
36
83
  context "when registering a node" do
37
84
  it "should define a node on localhost." do
38
85
  uri = 'druby://:12345'
39
- subject.register_node(:node1) do |node|
86
+ subject.node(:node1) do |node|
40
87
  node.connect uri
41
88
  end
42
89
  name, data = subject.__node__.assoc(:node1)
43
90
  data[:type].should == :node
44
- data[:setting].get(:connect).should == [uri]
91
+ data[:ssh].should be_false
92
+ data[:template].should be_false
93
+ setting = data[:setting]
94
+ setting.should be_an_instance_of DRbQS::Setting::Node
95
+ setting.get(:connect).should == [uri]
45
96
  end
46
97
 
47
98
  it "should define a node over ssh." do
48
99
  dest = "user@example.com"
49
100
  uri = 'druby://:12345'
50
- subject.register_node(:node2) do |node, ssh|
101
+ subject.node(:node2) do |node, ssh|
51
102
  node.connect uri
52
103
  ssh.connect dest
53
104
  end
54
105
  name, data = subject.__node__.assoc(:node2)
55
- data[:type].should == :ssh
106
+ data[:type].should == :node
107
+ data[:ssh].should be_true
108
+ data[:template].should be_false
109
+ setting = data[:setting]
110
+ setting.should be_an_instance_of DRbQS::Setting::SSH
111
+ setting.get(:connect).should == [dest]
112
+ setting.mode_setting.get(:connect).should == [uri]
113
+ end
114
+
115
+ it "should define a node template." do
116
+ uri = 'druby://:12345'
117
+ subject.node(:node3, :template => true) do |node|
118
+ node.connect uri
119
+ end
120
+ name, data = subject.__node__.assoc(:node3)
121
+ data[:type].should == :node
122
+ data[:ssh].should be_false
123
+ data[:template].should be_true
124
+ setting = data[:setting]
125
+ setting.should be_an_instance_of DRbQS::Setting::Node
126
+ setting.get(:connect).should == [uri]
127
+ end
128
+
129
+ it "should define a node over ssh." do
130
+ dest = "user@example.com"
131
+ uri = 'druby://:12345'
132
+ subject.node(:node4, :template => true) do |node, ssh|
133
+ node.connect uri
134
+ ssh.connect dest
135
+ end
136
+ name, data = subject.__node__.assoc(:node4)
137
+ data[:type].should == :node
138
+ data[:ssh].should be_true
139
+ data[:template].should be_true
56
140
  setting = data[:setting]
141
+ setting.should be_an_instance_of DRbQS::Setting::SSH
57
142
  setting.get(:connect).should == [dest]
58
143
  setting.mode_setting.get(:connect).should == [uri]
59
144
  end
145
+
146
+ it "should set node group." do
147
+ nodes = [:node1, :node2]
148
+ subject.node(:node_group, :group => nodes)
149
+ name, data = subject.__node__.assoc(:node_group)
150
+ data[:type].should == :group
151
+ data[:template].should be_true
152
+ data[:ssh].should_not be_true
153
+ data[:args].should == nodes
154
+ end
155
+
156
+ it "should raise error for invalid node group." do
157
+ lambda do
158
+ subject.node(:node_group, :group => :node_error)
159
+ end.should raise_error
160
+ end
161
+ end
162
+
163
+ context "when loading other server difinition" do
164
+ it "should load server definition." do
165
+ subject.server :parent, template: true do |server|
166
+ server.log_level "debug"
167
+ end
168
+ subject.server :child, 'example.com', load: :parent do |server|
169
+ server.load "file.rb"
170
+ end
171
+
172
+ name, data = subject.__server__.assoc(:parent)
173
+ setting = data[:setting]
174
+ setting.value.load.should be_nil
175
+
176
+ name, data = subject.__server__.assoc(:child)
177
+ setting = data[:setting]
178
+ setting.value.log_level.should == ["debug"]
179
+ setting.value.load.should == ["file.rb"]
180
+ end
181
+
182
+ it "should load server definition that is over ssh." do
183
+ subject.server :parent, template: true do |server, ssh|
184
+ server.log_level "debug"
185
+ ssh.rvm "ruby-head"
186
+ end
187
+ subject.server :child, 'example.com', load: :parent do |server, ssh|
188
+ server.load "file.rb"
189
+ ssh.nice 20
190
+ end
191
+
192
+ name, data = subject.__server__.assoc(:parent)
193
+ setting = data[:setting]
194
+ setting.value.nice.should be_nil
195
+ setting.mode_setting.value.load.should be_nil
196
+
197
+ name, data = subject.__server__.assoc(:child)
198
+ setting = data[:setting]
199
+ setting.value.rvm.should == ["ruby-head"]
200
+ setting.value.nice.should == [20]
201
+ setting.mode_setting.value.log_level.should == ["debug"]
202
+ setting.mode_setting.value.load.should == ["file.rb"]
203
+ end
204
+
205
+ it "should load server definition on localhost for definition over ssh." do
206
+ subject.server :parent, template: true do |server|
207
+ server.log_level "debug"
208
+ end
209
+ subject.server :child, 'example.com', load: :parent do |server, ssh|
210
+ server.load "file.rb"
211
+ ssh.nice 20
212
+ end
213
+
214
+ name, data = subject.__server__.assoc(:parent)
215
+ setting = data[:setting]
216
+ setting.value.log.should be_nil
217
+
218
+ name, data = subject.__server__.assoc(:child)
219
+ setting = data[:setting]
220
+ setting.value.nice.should == [20]
221
+ setting.mode_setting.value.log_level.should == ["debug"]
222
+ setting.mode_setting.value.load.should == ["file.rb"]
223
+ end
224
+
225
+ it "should raise error because definition on localhost loads that over ssh." do
226
+ subject.server :parent, template: true do |server, ssh|
227
+ server.log_level "debug"
228
+ ssh.rvm "ruby-head"
229
+ end
230
+ lambda do
231
+ subject.server :child, 'example.com', load: :parent do |server|
232
+ end
233
+ end.should raise_error
234
+ end
235
+ end
236
+
237
+ context "when loading other node difinition" do
238
+ it "should load node definition." do
239
+ subject.node :parent, template: true do |node|
240
+ node.log_level "debug"
241
+ end
242
+ subject.node :child, load: :parent do |node|
243
+ node.load "file.rb"
244
+ end
245
+
246
+ name, data = subject.__node__.assoc(:parent)
247
+ setting = data[:setting]
248
+ setting.value.load.should be_nil
249
+
250
+ name, data = subject.__node__.assoc(:child)
251
+ setting = data[:setting]
252
+ setting.value.log_level.should == ["debug"]
253
+ setting.value.load.should == ["file.rb"]
254
+ end
255
+
256
+ it "should load node definition that is over ssh." do
257
+ subject.node :parent, template: true do |node, ssh|
258
+ node.log_level "debug"
259
+ ssh.rvm "ruby-head"
260
+ end
261
+ subject.node :child, load: :parent do |node, ssh|
262
+ node.load "file.rb"
263
+ ssh.nice 20
264
+ end
265
+
266
+ name, data = subject.__node__.assoc(:parent)
267
+ setting = data[:setting]
268
+ setting.value.nice.should be_nil
269
+ setting.mode_setting.value.load.should be_nil
270
+
271
+ name, data = subject.__node__.assoc(:child)
272
+ setting = data[:setting]
273
+ setting.value.rvm.should == ["ruby-head"]
274
+ setting.value.nice.should == [20]
275
+ setting.mode_setting.value.log_level.should == ["debug"]
276
+ setting.mode_setting.value.load.should == ["file.rb"]
277
+ end
278
+
279
+ it "should load node definition on localhost for definition over ssh." do
280
+ subject.node :parent, template: true do |node|
281
+ node.log_level "debug"
282
+ end
283
+ subject.node :child, load: :parent do |node, ssh|
284
+ node.load "file.rb"
285
+ ssh.nice 20
286
+ end
287
+
288
+ name, data = subject.__node__.assoc(:parent)
289
+ setting = data[:setting]
290
+ setting.value.log.should be_nil
291
+
292
+ name, data = subject.__node__.assoc(:child)
293
+ setting = data[:setting]
294
+ setting.value.nice.should == [20]
295
+ setting.mode_setting.value.log_level.should == ["debug"]
296
+ setting.mode_setting.value.load.should == ["file.rb"]
297
+ end
298
+
299
+ it "should raise error because definition on localhost loads that over ssh." do
300
+ subject.node :parent, template: true do |node, ssh|
301
+ node.log_level "debug"
302
+ ssh.rvm "ruby-head"
303
+ end
304
+ lambda do
305
+ subject.node :child, load: :parent do |node|
306
+ end
307
+ end.should raise_error
308
+ end
309
+
310
+ it "should raise error because group definition is loaded." do
311
+ subject.node :parent, group: [:node1, :node2, :node3]
312
+ lambda do
313
+ subject.node :child, load: :parent do |node|
314
+ end
315
+ end.should raise_error
316
+ end
317
+ end
318
+
319
+ context "when reconfiguring server" do
320
+ it "should reconfigure definition." do
321
+ load_file = 'file.rb'
322
+ subject.server(:server1, "example.com") do |server|
323
+ server.load load_file
324
+ end
325
+ subject.server(:server1, "example.com") do |server|
326
+ server.log_level 'info'
327
+ end
328
+
329
+ name, data = subject.__server__.assoc(:server1)
330
+ data[:type].should == :server
331
+ data[:ssh].should be_false
332
+ data[:template].should be_false
333
+ setting = data[:setting]
334
+ setting.get(:load).should == [load_file]
335
+ setting.get(:log_level).should == ['info']
336
+ end
337
+
338
+ it "should raise error for simultaneous reconfiguring and loading." do
339
+ subject.server(:server2, "example.com") do |server|
340
+ end
341
+ lambda do
342
+ subject.server(:server2, "example.com", load: :some_definition) do |server|
343
+ end
344
+ end.should raise_error
345
+ end
346
+ end
347
+
348
+ context "when reconfiguring node" do
349
+ it "should reconfigure definition." do
350
+ load_file = 'file.rb'
351
+ subject.node(:node1) do |node|
352
+ node.load load_file
353
+ end
354
+ subject.node(:node1) do |node|
355
+ node.log_level 'info'
356
+ end
357
+
358
+ name, data = subject.__node__.assoc(:node1)
359
+ data[:type].should == :node
360
+ data[:ssh].should be_false
361
+ data[:template].should be_false
362
+ setting = data[:setting]
363
+ setting.get(:load).should == [load_file]
364
+ setting.get(:log_level).should == ['info']
365
+ end
366
+
367
+ it "should raise error to change type of group." do
368
+ nodes = [:node1, :node2]
369
+ nodes2 = [:node3, :node4, :node5]
370
+ subject.node(:node_group, :group => nodes)
371
+ subject.node(:node_group, :group => nodes2)
372
+ name, data = subject.__node__.assoc(:node_group)
373
+ data[:type].should == :group
374
+ data[:template].should be_true
375
+ data[:ssh].should_not be_true
376
+ data[:args].should == nodes2
377
+ end
378
+
379
+ it "should raise error for simultaneous reconfiguring and loading." do
380
+ subject.node(:node2) do |node|
381
+ end
382
+ lambda do
383
+ subject.node(:node2, load: :some_definition) do |node|
384
+ end
385
+ end.should raise_error
386
+ end
387
+
388
+ it "should raise error to change type of group." do
389
+ subject.node(:node_group, group: [:node1, :node2])
390
+ lambda do
391
+ subject.node(:node_group) do |node|
392
+ end
393
+ end.should raise_error
394
+ end
395
+
396
+ it "should raise error to change type of process." do
397
+ subject.node(:node) do |node|
398
+ end
399
+ lambda do
400
+ subject.node(:node, group: [:node1, :node2])
401
+ end.should raise_error
402
+ end
403
+ end
404
+
405
+ context "when clearing" do
406
+ it "should clear servers" do
407
+ subject.server(:server1, "example.com") do |server|
408
+ end
409
+ subject.server(:server2, "example.com") do |server|
410
+ end
411
+ subject.server(:server3, "example.com") do |server|
412
+ end
413
+ subject.clear_server(:server1, :server3)
414
+ subject.__server__.assoc(:server1).should_not be_true
415
+ subject.__server__.assoc(:server2).should be_true
416
+ subject.__server__.assoc(:server3).should_not be_true
417
+ end
418
+
419
+ it "should clear nodes" do
420
+ subject.node(:node1) do |node|
421
+ end
422
+ subject.node(:node2) do |node|
423
+ end
424
+ subject.node(:node3) do |node|
425
+ end
426
+ subject.clear_node(:node1, :node3)
427
+ subject.__node__.assoc(:node1).should_not be_true
428
+ subject.__node__.assoc(:node2).should be_true
429
+ subject.__node__.assoc(:node3).should_not be_true
430
+ end
60
431
  end
61
432
 
62
433
  context "when setting default" do
@@ -73,5 +444,28 @@ describe DRbQS::ProcessDefinition::Register do
73
444
  h[:server].should == :server2
74
445
  h[:port].should == 12345
75
446
  end
447
+
448
+ it "should set default nodes." do
449
+ nodes = [:node1, :node2]
450
+ subject.default(:node => nodes)
451
+ h = subject.__default__
452
+ h[:node].should == nodes
453
+ end
454
+
455
+ it "should set default value for some keys." do
456
+ subject.default(:log => '/tmp/drbqs/log', :some_key => 'some_value')
457
+ h = subject.__default__
458
+ h[:log].should == '/tmp/drbqs/log'
459
+ h[:some_key].should == 'some_value'
460
+ end
461
+
462
+ it "should clear values." do
463
+ subject.default(key1: 'val1', key2: 'val2', key3: 'val3')
464
+ subject.default_clear(:key1, :key2)
465
+ h = subject.__default__
466
+ h[:key1].should be_nil
467
+ h[:key2].should be_nil
468
+ h[:key3].should == 'val3'
469
+ end
76
470
  end
77
471
  end