filecluster 0.5.14 → 0.5.15
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 +4 -4
- data/.gitignore +3 -0
- data/.ssh/.keep +0 -0
- data/Dockerfile +40 -0
- data/Gemfile +1 -0
- data/README_RU.md +32 -0
- data/bin/fc-daemon +4 -1
- data/bin/fc-manage +8 -0
- data/bin/fc-setup-db +2 -2
- data/docker-compose-mysql56.yaml +35 -0
- data/docker-compose.yaml +35 -0
- data/docker/Dockerfile.sshd +17 -0
- data/docker/development.env +7 -0
- data/entrypoint.sh +19 -0
- data/filecluster.gemspec +2 -0
- data/lib/autosync.rb +149 -0
- data/lib/daemon.rb +17 -1
- data/lib/daemon/autosync_thread.rb +16 -0
- data/lib/daemon/global_daemon_thread.rb +1 -1
- data/lib/daemon/update_tasks_thread.rb +1 -1
- data/lib/fc/db.rb +5 -1
- data/lib/fc/storage.rb +3 -3
- data/lib/fc/var.rb +20 -1
- data/lib/fc/version.rb +1 -1
- data/lib/iostat.rb +48 -0
- data/lib/manage.rb +3 -1
- data/lib/manage/autosync.rb +53 -0
- data/lib/manage/copy_speed.rb +1 -1
- data/lib/manage/storages.rb +57 -1
- data/test/autosync_test.rb +186 -0
- data/test/daemon_test.rb +44 -31
- data/test/db_test.rb +28 -21
- data/test/error_test.rb +3 -3
- data/test/functional_test.rb +21 -20
- data/test/helper.rb +8 -2
- data/test/storage_sync_test.rb +7 -7
- metadata +44 -2
data/test/daemon_test.rb
CHANGED
@@ -6,24 +6,24 @@ class DaemonTest < Test::Unit::TestCase
|
|
6
6
|
class << self
|
7
7
|
def startup
|
8
8
|
@@debug = false # show stdout and sterr of fc-daemon
|
9
|
-
|
9
|
+
|
10
10
|
dir = File.expand_path(File.dirname(__FILE__))
|
11
11
|
db_config_file = "#{dir}/db_test.yml"
|
12
12
|
daemon_bin = File.expand_path("#{dir}/../bin/fc-daemon")
|
13
|
-
|
13
|
+
|
14
14
|
File.open(db_config_file, 'w') do |f|
|
15
15
|
f.write(FC::DB.options.to_yaml)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
@@errors_count = FC::Error.where.count
|
19
|
-
|
20
|
-
FC::Var.set('daemon_cycle_time',
|
21
|
-
FC::Var.set('daemon_global_wait_time',
|
19
|
+
|
20
|
+
FC::Var.set('daemon_cycle_time', 0)
|
21
|
+
FC::Var.set('daemon_global_wait_time', 0)
|
22
22
|
FC::Var.set('daemon_global_error_items_storages_ttl', 2)
|
23
23
|
FC::Var.set('daemon_global_error_items_ttl', 2)
|
24
24
|
@stotage_checks = 0
|
25
25
|
Thread.new do
|
26
|
-
Open3.popen2e("#{daemon_bin} -c #{db_config_file} -l debug -h
|
26
|
+
Open3.popen2e("#{daemon_bin} -c #{db_config_file} -l debug -h #{ ssh_hostname} ") do |stdin, stdout, t|
|
27
27
|
@@pid = t.pid
|
28
28
|
while line = stdout.readline
|
29
29
|
@stotage_checks += 1 if line =~ /Finish stotage check/i
|
@@ -31,11 +31,11 @@ class DaemonTest < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# tmp fake storages dirs
|
36
36
|
`rm -rf /tmp/host*-sd*`
|
37
37
|
`mkdir -p /tmp/host1-sda/ /tmp/host1-sdb/ /tmp/host1-sdc/`
|
38
|
-
|
38
|
+
|
39
39
|
# test files to copy
|
40
40
|
@@test_file_path = '/tmp/fc_test_file'
|
41
41
|
`dd if=/dev/urandom of=#{@@test_file_path} bs=1M count=1 2>&1`
|
@@ -43,48 +43,48 @@ class DaemonTest < Test::Unit::TestCase
|
|
43
43
|
`mkdir -p #{@@test_dir_path}/aaa #{@@test_dir_path}/bbb`
|
44
44
|
`cp #{@@test_file_path} #{@@test_dir_path}/aaa/test1`
|
45
45
|
`cp #{@@test_file_path} #{@@test_dir_path}/bbb/test2`
|
46
|
-
|
46
|
+
|
47
47
|
@@storages = []
|
48
48
|
@@storages << FC::Storage.new(
|
49
49
|
:name => 'host1-sda',
|
50
|
-
:host =>
|
50
|
+
:host => ssh_hostname,
|
51
51
|
:path => '/tmp/host1-sda/',
|
52
|
-
:copy_storages => 'host1-sdb,host1-sdc',
|
52
|
+
:copy_storages => 'host1-sdb,host1-sdc',
|
53
53
|
:size_limit => 1_000_000_000
|
54
54
|
)
|
55
55
|
@@storages << FC::Storage.new(
|
56
56
|
:name => 'host1-sdb',
|
57
|
-
:host =>
|
57
|
+
:host => ssh_hostname,
|
58
58
|
:path => '/tmp/host1-sdb/',
|
59
|
-
:copy_storages => 'host1-sda,host1-sdc',
|
59
|
+
:copy_storages => 'host1-sda,host1-sdc',
|
60
60
|
:size_limit => 1_000_000_000
|
61
61
|
)
|
62
62
|
@@storages << FC::Storage.new(
|
63
63
|
:name => 'host1-sdc',
|
64
|
-
:host =>
|
64
|
+
:host => ssh_hostname,
|
65
65
|
:path => '/tmp/host1-sdc/',
|
66
66
|
:copy_storages => 'host1-sda,host1-sdb',
|
67
67
|
:size_limit => 1_000_000_000
|
68
68
|
)
|
69
69
|
@@storages.each(&:save)
|
70
|
-
|
70
|
+
|
71
71
|
@@policy = FC::Policy.new(
|
72
|
-
:create_storages => 'host1-sda,host1-sdb,host1-sdc',
|
73
|
-
:copies => 2,
|
72
|
+
:create_storages => 'host1-sda,host1-sdb,host1-sdc',
|
73
|
+
:copies => 2,
|
74
74
|
:name => 'policy 1',
|
75
|
-
:delete_deferred_time =>
|
75
|
+
:delete_deferred_time => 5
|
76
76
|
)
|
77
77
|
@@policy.save
|
78
|
-
|
78
|
+
|
79
79
|
@@rule = FC::CopyRule.new(:copy_storages => 'host1-sdc', :rule => 'name == "bla/bla/test3"')
|
80
80
|
@@rule.save
|
81
|
-
|
81
|
+
|
82
82
|
# wait for running fc-daemon
|
83
83
|
Timeout.timeout(5) do
|
84
84
|
sleep 0.1 while @stotage_checks < @@storages.size
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def shutdown
|
89
89
|
Process.kill('KILL', @@pid)
|
90
90
|
FC::DB.query('DELETE FROM items_storages')
|
@@ -100,15 +100,15 @@ class DaemonTest < Test::Unit::TestCase
|
|
100
100
|
should 'daemon_all' do
|
101
101
|
puts 'Start' if @@debug
|
102
102
|
@@storages.each(&:reload)
|
103
|
-
assert @@storages[0].up?, "Storage #{@@storages[0].name} down"
|
103
|
+
assert @@storages[0].up?, "Storage #{@@storages[0].name} down"
|
104
104
|
assert @@storages[1].up?, "Storage #{@@storages[1].name} down"
|
105
105
|
assert @@storages[2].up?, "Storage #{@@storages[2].name} down"
|
106
|
-
|
106
|
+
|
107
107
|
assert_nothing_raised { @item1 = make_file_item('bla/bla/test1', 'test1') }
|
108
108
|
assert_nothing_raised { @item2 = make_file_item('bla/bla/test2', 'test2') }
|
109
109
|
assert_nothing_raised { @item3 = make_dir_item('bla/bla/test3', 'test3') }
|
110
110
|
assert_nothing_raised { @item4 = make_file_item('bla/bla/test4', 'test4') }
|
111
|
-
|
111
|
+
|
112
112
|
@@policy.copies = 3
|
113
113
|
@@policy.save
|
114
114
|
|
@@ -123,18 +123,31 @@ class DaemonTest < Test::Unit::TestCase
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
assert_equal @@errors_count, FC::Error.where.count, 'new errors in errors table'
|
126
|
-
|
126
|
+
|
127
127
|
@@policy.copies = 2
|
128
128
|
@@policy.save
|
129
|
+
|
130
|
+
item_size = `du -sb #{@@test_file_path} 2>&1`.to_i
|
131
|
+
storage = FC::Storage.where('name = ?', 'host1-sdc').first
|
132
|
+
storage.write_weight = -1
|
133
|
+
storage.save
|
129
134
|
item_storage = FC::ItemStorage.where('item_id = ? AND storage_name = ?', @item1.id, 'host1-sdc').first
|
130
135
|
item_storage.status = 'delete'
|
131
136
|
item_storage.save
|
132
|
-
|
137
|
+
|
138
|
+
sleep 2
|
139
|
+
puts 'Check no delete' if @@debug
|
140
|
+
assert_equal item_size, `du -sb /tmp/host1-sdc/bla/bla/test1 2>&1`.to_i
|
141
|
+
|
142
|
+
storage = FC::Storage.where('name = ?', 'host1-sdc').first
|
143
|
+
storage.write_weight = 0
|
144
|
+
storage.save
|
145
|
+
|
133
146
|
sleep 2
|
134
147
|
puts 'Check delete' if @@debug
|
135
148
|
assert_equal 0, `du -sb /tmp/host1-sdc/bla/bla/test1 2>&1`.to_i
|
136
149
|
assert_equal @@errors_count, FC::Error.where.count, 'new errors in errors table'
|
137
|
-
|
150
|
+
|
138
151
|
@item1.immediate_delete
|
139
152
|
@item4.mark_deleted
|
140
153
|
@item2.get_item_storages.each do |ist|
|
@@ -143,8 +156,8 @@ class DaemonTest < Test::Unit::TestCase
|
|
143
156
|
end
|
144
157
|
@item3.status = 'error'
|
145
158
|
@item3.save
|
146
|
-
|
147
|
-
sleep
|
159
|
+
|
160
|
+
sleep 4
|
148
161
|
puts 'Check immediate_delete' if @@debug
|
149
162
|
assert_raise(RuntimeError, 'Item not deleted after mark_deleted') { @item1.reload }
|
150
163
|
assert_equal 0, @item2.get_item_storages.count, "ItemStorages not deleted after status='error'"
|
@@ -154,7 +167,7 @@ class DaemonTest < Test::Unit::TestCase
|
|
154
167
|
assert_equal 'deferred_delete', @item4.status, 'Item not deferred_delete after mark_deleted'
|
155
168
|
assert_same_elements %w(ready ready ready), @item4.get_item_storages.map(&:status)
|
156
169
|
|
157
|
-
sleep
|
170
|
+
sleep 4
|
158
171
|
puts 'Check mark_deleted' if @@debug
|
159
172
|
assert_raise(RuntimeError, 'Item not deleted after mark_deleted') { @item4.reload }
|
160
173
|
end
|
data/test/db_test.rb
CHANGED
@@ -13,19 +13,19 @@ class DbTest < Test::Unit::TestCase
|
|
13
13
|
storages << FC::Storage.new(:name => 'rec2-sdc', :host => 'rec2')
|
14
14
|
storages << FC::Storage.new(:name => 'rec2-sdd', :host => 'rec2')
|
15
15
|
@@storages_ids = storages.map{|storage| storage.save; storage.id }
|
16
|
-
|
16
|
+
|
17
17
|
policies = []
|
18
18
|
policies << FC::Policy.new(:create_storages => 'rec1-sda,rec1-sdd', :copies => 2, :name => 'policy 1')
|
19
19
|
policies << FC::Policy.new(:create_storages => 'rec1-sda,bla,rec2-sdd', :copies => 3, :name => 'policy 2')
|
20
20
|
policies << FC::Policy.new(:create_storages => 'bla,rec1-sda,test', :copies => 4, :name => 'policy 3')
|
21
21
|
@@policies_ids = policies.map{|policy| policy.save; policy.id }
|
22
|
-
|
22
|
+
|
23
23
|
items = []
|
24
24
|
items << FC::Item.new(:name => 'test1', :policy_id => policies.first.id, :size => 150)
|
25
25
|
items << FC::Item.new(:name => 'test2', :policy_id => policies.first.id, :size => 200)
|
26
26
|
items << FC::Item.new(:name => 'test3', :policy_id => policies.first.id, :size => 400)
|
27
27
|
@@items_ids = items.map{|item| item.save; item.id }
|
28
|
-
|
28
|
+
|
29
29
|
item_storages = []
|
30
30
|
items.each do |item|
|
31
31
|
item_storages << FC::ItemStorage.new(:item_id => item.id, :storage_name => 'rec1-sda')
|
@@ -54,7 +54,7 @@ class DbTest < Test::Unit::TestCase
|
|
54
54
|
|
55
55
|
should 'sql logger' do
|
56
56
|
FC::DB.logger = mock
|
57
|
-
FC::DB.logger.expects(:debug).at_least_once
|
57
|
+
FC::DB.logger.expects(:debug).at_least_once
|
58
58
|
FC::DB.query 'SELECT 1'
|
59
59
|
FC::DB.logger = nil
|
60
60
|
end
|
@@ -64,7 +64,7 @@ class DbTest < Test::Unit::TestCase
|
|
64
64
|
File.open(db_config_file, 'w') do |f|
|
65
65
|
f.write(FC::DB.options.to_yaml)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
connect = FC::DB.connect
|
69
69
|
FC::DB.close
|
70
70
|
assert_false connect.ping, 'Mysql2 connect not closed after close call'
|
@@ -88,7 +88,7 @@ class DbTest < Test::Unit::TestCase
|
|
88
88
|
FC::DB.connect!(:multi_threads => true)
|
89
89
|
assert_true FC::DB.connect.ping, 'Not connected after lazy_connect with Mysql2'
|
90
90
|
assert_true FC::DB.options[:multi_threads], 'Options from connect!(options) was not setted'
|
91
|
-
|
91
|
+
|
92
92
|
FC::DB.close
|
93
93
|
FC::DB.lazy_connect do
|
94
94
|
FC::DB.connect_by_config(FC::DB.options)
|
@@ -111,13 +111,20 @@ class DbTest < Test::Unit::TestCase
|
|
111
111
|
should 'mysql errors' do
|
112
112
|
FC::DB.connect!(:reconnect => true)
|
113
113
|
FC::DB.logger = mock
|
114
|
-
FC::DB.logger.expects(:info).at_least_once
|
114
|
+
FC::DB.logger.expects(:info).at_least_once
|
115
115
|
assert_raise(Mysql2::Error) { FC::DB.query('retertert') }
|
116
116
|
assert_raise(RuntimeError) { FC::DB.query('select ewrwerwerwer()') }
|
117
117
|
FC::DB.connect!(:reconnect => false)
|
118
118
|
FC::DB.logger = nil
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
|
+
should "item time update" do
|
122
|
+
item = FC::Item.new(:name => 'bla bla bla', :policy_id => @item.policy_id)
|
123
|
+
item.save
|
124
|
+
item.reload
|
125
|
+
assert((item.time - Time.new.to_i).abs <= 1)
|
126
|
+
end
|
127
|
+
|
121
128
|
should "items" do
|
122
129
|
assert @items.count > 0, 'Items not loaded'
|
123
130
|
@items.each{|item| assert item.time > 0, "Item (id=#{item.id}) time = 0"}
|
@@ -131,25 +138,25 @@ class DbTest < Test::Unit::TestCase
|
|
131
138
|
item2.save
|
132
139
|
assert_equal 0, item2.id, "Item (id=#{item2.id}) successfull insert on uniq key"
|
133
140
|
end
|
134
|
-
|
141
|
+
|
135
142
|
should "storages" do
|
136
143
|
assert @storages.count > 0, 'Storages not loaded'
|
137
144
|
storage = FC::Storage.new(:name => 'rec1-sda', :host => 'rec1')
|
138
145
|
storage.save
|
139
146
|
assert_equal storage.id, 0, "Storage duplicate name"
|
140
147
|
end
|
141
|
-
|
148
|
+
|
142
149
|
should "policies and storages" do
|
143
150
|
assert @policies.count > 0, 'Policies not loaded'
|
144
151
|
assert_equal 'rec1-sda,rec1-sdd', @policies[0].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages"
|
145
152
|
assert_equal 'rec1-sda,rec2-sdd', @policies[1].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages"
|
146
153
|
assert_equal 'rec1-sda', @policies[2].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages"
|
147
|
-
|
154
|
+
|
148
155
|
FC::Policy.new(:create_storages => 'rec2-sda,rec2-sdd', :name => 'policy 1').save
|
149
156
|
assert_equal 'rec1-sda,rec1-sdd', FC::Policy.where('name = ?', 'policy 1').first.create_storages, "Create policy with uniq name"
|
150
|
-
FC::Policy.new(:create_storages => 'bla,test', :name => 'new policy').save
|
157
|
+
FC::Policy.new(:create_storages => 'bla,test', :name => 'new policy').save rescue nil # nil from mysql 5.6
|
151
158
|
assert_nil FC::Policy.where('name = ?', 'new policy').first, "Create policy with incorrect create_storages"
|
152
|
-
|
159
|
+
|
153
160
|
assert_raise(Mysql2::Error, 'Change storage name with linked polices') { @storages[0].name = 'blabla'; @storages[0].save }
|
154
161
|
assert_raise(Mysql2::Error, 'Delete storage name with linked polices') { @storages[0].delete }
|
155
162
|
assert_nothing_raised { @storages[6].name = 'rec2-sdc-new'; @storages[6].save }
|
@@ -169,13 +176,13 @@ class DbTest < Test::Unit::TestCase
|
|
169
176
|
assert_equal 'rec2-sda,rec1-sda', @policies[0].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages after change"
|
170
177
|
assert_raise(Mysql2::Error, 'Save empty policy storage') { @policies[0].create_storages = 'blabla'; @policies[0].save }
|
171
178
|
end
|
172
|
-
|
179
|
+
|
173
180
|
should "item_storages doubles" do
|
174
181
|
is = FC::ItemStorage.new(:item_id => @item_storage.item_id, :storage_name => @item_storage.storage_name)
|
175
182
|
is.save
|
176
183
|
assert_equal 0, is.id, 'Item_storages successfull insert on uniq key'
|
177
184
|
end
|
178
|
-
|
185
|
+
|
179
186
|
should "item_storages times" do
|
180
187
|
assert @item_storages.count > 0, 'Item_storages not loaded'
|
181
188
|
@item_storages.each{|is| assert is.time > 0, "Item_storage (id=#{is.id}) time = 0"}
|
@@ -189,17 +196,17 @@ class DbTest < Test::Unit::TestCase
|
|
189
196
|
@item_storage.storage_name = storage_name
|
190
197
|
@item_storage.save
|
191
198
|
end
|
192
|
-
|
199
|
+
|
193
200
|
should "item_storages references" do
|
194
201
|
assert_raise(Mysql2::Error, "Delete item (id=#{@items[2].id} with references to item_storages") { @items[2].delete }
|
195
202
|
assert_raise(Mysql2::Error, "Delete storage (id=#{@storages[4].id} with references to item_storages") { @storages[4].delete }
|
196
203
|
end
|
197
|
-
|
204
|
+
|
198
205
|
should "item_storages copies, statuses, size" do
|
199
206
|
@items.each{|item| assert_equal 2, item.copies, "Item (id=#{item.id}) copies not inc after add item_storage"}
|
200
207
|
size_sum = @items.inject(0){|sum, item| sum+item.size}
|
201
208
|
assert_equal size_sum, @storage.size, "storage (id=#{@storage.id}) size <> ready not inc after item_storage.status='ready'"
|
202
|
-
|
209
|
+
|
203
210
|
assert_equal 'new', @item.status, "Item (id=#{@item.id}) status <> 'new'"
|
204
211
|
@item_storage.status = 'ready'
|
205
212
|
@item_storage.save
|
@@ -216,7 +223,7 @@ class DbTest < Test::Unit::TestCase
|
|
216
223
|
@item.reload
|
217
224
|
assert_equal 'error', @item.status, "Item (id=#{@item.id}) status <> 'error' not changed after item_storage.status='error'"
|
218
225
|
assert_equal 2, @item.copies, "Item (id=#{@item.id}) copies changed after item_storage.status='error'"
|
219
|
-
|
226
|
+
|
220
227
|
@item_storage.status = 'ready'
|
221
228
|
@item_storage.save
|
222
229
|
@item.reload
|
@@ -226,7 +233,7 @@ class DbTest < Test::Unit::TestCase
|
|
226
233
|
@item.reload
|
227
234
|
assert_equal 'error', @item.status, "Item (id=#{@item.id}) status <> 'error' not changed after item_storage.status='delete'"
|
228
235
|
assert_equal 1, @item.copies, "Item (id=#{@item.id}) copies not decreased after item_storage.status='delete'"
|
229
|
-
|
236
|
+
|
230
237
|
@item_storage.status = 'ready'
|
231
238
|
@item_storage.save
|
232
239
|
@item_storage2.status = 'ready'
|
@@ -245,7 +252,7 @@ class DbTest < Test::Unit::TestCase
|
|
245
252
|
@item.reload
|
246
253
|
assert_equal 'error', @item.status, "Item (id=#{@item.id}) status <> 'error' not changed after delete all item_storage"
|
247
254
|
end
|
248
|
-
|
255
|
+
|
249
256
|
should "errors time" do
|
250
257
|
error = FC::Error.new(:message => 'test error')
|
251
258
|
error.save
|
data/test/error_test.rb
CHANGED
@@ -2,14 +2,14 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class ErrorTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
FC::Storage.stubs(:curr_host).returns(
|
5
|
+
FC::Storage.stubs(:curr_host).returns(ssh_hostname)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
should "get_storages" do
|
9
9
|
assert_raise(RuntimeError) { FC::Error.raise 'error message', :item_id => 111 }
|
10
10
|
assert error = FC::Error.where('1 ORDER BY id desc LIMIT 1').first
|
11
11
|
assert_equal 'error message', error.message
|
12
|
-
assert_equal
|
12
|
+
assert_equal ssh_hostname, error.host
|
13
13
|
assert_equal 111, error.item_id
|
14
14
|
end
|
15
15
|
end
|
data/test/functional_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class FunctionalTest < Test::Unit::TestCase
|
3
|
+
class FunctionalTest < Test::Unit::TestCase
|
4
4
|
class << self
|
5
5
|
def startup
|
6
6
|
# tmp fake storages dirs
|
7
7
|
`rm -rf /tmp/host*-sd*`
|
8
8
|
`mkdir -p /tmp/host1-sda/ /tmp/host2-sda/`
|
9
|
-
|
9
|
+
|
10
10
|
# test file to copy
|
11
11
|
@@test_file_path = '/tmp/fc test_file "~!@#$%^&*()_+|\';'
|
12
12
|
`dd if=/dev/urandom of=#{@@test_file_path.shellescape} bs=100K count=1 2>&1`
|
@@ -14,7 +14,7 @@ class FunctionalTest < Test::Unit::TestCase
|
|
14
14
|
`mkdir -p #{@@test_dir_path.shellescape}/aaa #{@@test_dir_path.shellescape}/bbb`
|
15
15
|
`cp #{@@test_file_path.shellescape} #{@@test_dir_path.shellescape}/aaa/test1`
|
16
16
|
`cp #{@@test_file_path.shellescape} #{@@test_dir_path.shellescape}/bbb/test2`
|
17
|
-
|
17
|
+
|
18
18
|
@@storages = []
|
19
19
|
@@storages << FC::Storage.new(:name => 'host1-sda', :host => 'host1', :path => '/tmp/host1-sda/', :size => 0, :size_limit => 1000000, :check_time => Time.new.to_i)
|
20
20
|
@@storages << FC::Storage.new(:name => 'host1-sdb', :host => 'host1', :path => '/tmp/host1-sdb/', :size => 0, :size_limit => 1000000, :check_time => Time.new.to_i)
|
@@ -22,7 +22,7 @@ class FunctionalTest < Test::Unit::TestCase
|
|
22
22
|
@@storages << FC::Storage.new(:name => 'host2-sdb', :host => 'host2', :path => '/tmp/host2-sdb/', :size => 10, :size_limit => 1000000, :check_time => Time.new.to_i)
|
23
23
|
@@storages << FC::Storage.new(:name => 'host3-sda', :host => 'host3', :path => '/tmp/host3-sda/', :size => 100, :size_limit => 1000000)
|
24
24
|
@@storages.each { |storage| storage.save}
|
25
|
-
|
25
|
+
|
26
26
|
@@policies = []
|
27
27
|
@@policies << FC::Policy.new(:create_storages => 'host1-sda,host2-sda', :copy_storages => 'host1-sdb', :copies => 2, :name => 'policy 1')
|
28
28
|
@@policies << FC::Policy.new(:create_storages => 'host1-sdb,host2-sdb', :copy_storages => 'host1-sdb', :copies => 2, :name => 'policy 2')
|
@@ -40,10 +40,10 @@ class FunctionalTest < Test::Unit::TestCase
|
|
40
40
|
#`rm -rf #{@@test_dir_path.shellescape}`
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def setup
|
45
|
-
FC::Storage.any_instance.stubs(:host).returns('localhost')
|
46
|
-
FC::Storage.stubs(:curr_host).returns('localhost')
|
45
|
+
FC::Storage.any_instance.stubs(:host).returns(ENV['SSH_HOST'] || 'localhost')
|
46
|
+
FC::Storage.stubs(:curr_host).returns(ENV['SSH_HOST'] || 'localhost')
|
47
47
|
end
|
48
48
|
|
49
49
|
def stub_method(obj, method, method_impl)
|
@@ -65,7 +65,7 @@ class FunctionalTest < Test::Unit::TestCase
|
|
65
65
|
assert_equal 'ready', item_storage.status
|
66
66
|
assert_equal 'host1-sda', item_storage.storage_name
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
should "item create_from_local dir successful" do
|
70
70
|
assert_nothing_raised { @item = FC::Item.create_from_local(@@test_dir_path, '/bla/bla/test_dir', @@policies[0], {:tag => 'test_dir'}) }
|
71
71
|
assert_kind_of FC::Item, @item
|
@@ -79,7 +79,7 @@ class FunctionalTest < Test::Unit::TestCase
|
|
79
79
|
assert_equal 'ready', item_storage.status
|
80
80
|
assert_equal 'host1-sda', item_storage.storage_name
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
should "item create_from_local replace" do
|
84
84
|
@item = FC::Item.new(:name => 'test2', :policy_id => @@policies[3].id)
|
85
85
|
@item.save
|
@@ -97,13 +97,13 @@ class FunctionalTest < Test::Unit::TestCase
|
|
97
97
|
assert_equal 'delete', item_storages['host1-sdb'].status
|
98
98
|
assert_equal 'ready', item_storages['host2-sda'].status
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
should "item create_from_local available storage" do
|
102
102
|
errors_count = FC::Error.where.count
|
103
103
|
assert_raise(RuntimeError, "available storage") { FC::Item.create_from_local(@@test_file_path, 'test3', @@policies[2], {:tag => 'test'}) }
|
104
104
|
assert_equal errors_count+1, FC::Error.where.count, "Error not saved on available storage"
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
should "item create_from_local delete item_storage" do
|
108
108
|
@item = FC::Item.new(:name => 'test4', :policy_id => @@policies[3].id)
|
109
109
|
@item.save
|
@@ -115,7 +115,7 @@ class FunctionalTest < Test::Unit::TestCase
|
|
115
115
|
assert_not_equal item_storage.id, item_storages.first.id
|
116
116
|
assert_raise(RuntimeError) { item_storage.reload }
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
should "item create_from_local check md5" do
|
120
120
|
errors_count = FC::Error.where.count
|
121
121
|
@item = FC::Item.create_from_local(@@test_file_path, 'test5', @@policies[0], {:tag => 'test'})
|
@@ -197,14 +197,14 @@ class FunctionalTest < Test::Unit::TestCase
|
|
197
197
|
`cp #{@@test_file_path.shellescape} #{tmp_file_path.shellescape}`
|
198
198
|
assert_nothing_raised { FC::Item.create_from_local(tmp_file_path, 'inplace test', @@policies[0]) }
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
should "item create_from_local inplace for dir" do
|
202
202
|
tmp_dir_path = "/tmp/host2-sda/inplace test dir/"
|
203
203
|
`mkdir #{tmp_dir_path.shellescape}`
|
204
204
|
`cp #{@@test_file_path.shellescape} #{tmp_dir_path.shellescape}`
|
205
205
|
assert_nothing_raised { FC::Item.create_from_local(tmp_dir_path, '/inplace test dir/', @@policies[0]) }
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
should "item create_from_local with move and delete" do
|
209
209
|
tmp_file_path = "/tmp/fc test file for delete"
|
210
210
|
`cp #{@@test_file_path.shellescape} #{tmp_file_path.shellescape}`
|
@@ -218,22 +218,23 @@ class FunctionalTest < Test::Unit::TestCase
|
|
218
218
|
end
|
219
219
|
|
220
220
|
should 'item create_from_local with block for choose storage' do
|
221
|
-
item = FC::Item.create_from_local(@@test_file_path,
|
222
|
-
'/bla/bla/test7',
|
223
|
-
@@policies[0],
|
221
|
+
item = FC::Item.create_from_local(@@test_file_path,
|
222
|
+
'/bla/bla/test7',
|
223
|
+
@@policies[0],
|
224
224
|
:tag => 'test') do |storages|
|
225
225
|
storages.select { |s| s.name == 'host2-sda' }
|
226
226
|
end
|
227
227
|
assert_kind_of FC::Item, item
|
228
|
+
|
228
229
|
assert_equal `du -sb /tmp/host2-sda/bla/bla/test7 2>&1`.to_i, item.size
|
229
230
|
assert_equal 'ready', item.status
|
230
231
|
item_storages = item.get_item_storages
|
231
232
|
assert_equal 1, item_storages.count
|
232
233
|
assert_equal 'ready', item_storages.first.status
|
233
234
|
assert_equal 'host2-sda', item_storages.first.storage_name
|
234
|
-
item = FC::Item.create_from_local(@@test_file_path,
|
235
|
-
'/bla/bla/test8',
|
236
|
-
@@policies[0],
|
235
|
+
item = FC::Item.create_from_local(@@test_file_path,
|
236
|
+
'/bla/bla/test8',
|
237
|
+
@@policies[0],
|
237
238
|
:tag => 'test') { [@@storages[4]] }
|
238
239
|
assert_equal 'host3-sda', item.get_item_storages.first.storage_name
|
239
240
|
end
|