filecluster 0.5.13 → 0.5.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55c62eefa42ab98952d048ba96e7467a4a88fd80
4
- data.tar.gz: 6f9464f3d84c270a9ed46f84790dc605be33f72d
3
+ metadata.gz: df71ee0cd0c4068b96655ad85da5a84de2aa2044
4
+ data.tar.gz: f7787796c064db4b2e7f373d94422cb0af708eca
5
5
  SHA512:
6
- metadata.gz: ff5af3f5f2c994df7bf18c191e7d4ad38c6c2f7bf79e43ac2f3ff2011ef49717d26b174d83a01d115f932c396f59a392e0dd98ca2a870d1b10ff873c2220a8a2
7
- data.tar.gz: a4934117b805502c5f5b7ca0cf6d496455326f90c57e1587bf03a7bd913bea45b72a172e4f078182d97a7e16158c00d62f65d12b98831b539cfa5d4e08c29dee
6
+ metadata.gz: 053ef243b2f1c07f955207af615764909245cdcf5d7b35d76c34f267e3f80a9572f1465208cd2d2bfd34e2095103988609cbba66fb3f8c9d1ad29b27443b5f96
7
+ data.tar.gz: 52e8e8ee2cf22ede6b1f31448d3b7233ea3a883938c8a4ec4d27922b08dc124a76b2f74668e146c4cc6d51e45060dd0b563071375e5afc6fc32b0077374855da
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'rake/testtask'
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
7
  t.test_files = FileList["test/*_test.rb"]
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  desc "Run tests"
@@ -108,8 +108,7 @@ module FC
108
108
  end
109
109
  md5_on_storage = storage.md5_sum(name) if md5
110
110
  rescue Exception => e
111
- item_storage.status = 'error'
112
- item_storage.save
111
+ item_storage_status_set(item_storage, 'error')
113
112
  FC::Error.raise "Copy error: #{e.message}", :item_id => id, :item_storage_id => item_storage.id
114
113
  else
115
114
  begin
@@ -118,13 +117,10 @@ module FC
118
117
  FC::Error.raise "After copy error: #{e.message}", :item_id => id, :item_storage_id => item_storage.id
119
118
  else
120
119
  if md5 && md5_on_storage != md5
121
- item_storage.status = 'error'
122
- item_storage.save
120
+ item_storage_status_set(item_storage, 'error')
123
121
  FC::Error.raise "Check md5 after copy error", :item_id => id, :item_storage_id => item_storage.id
124
122
  else
125
- item_storage.status = 'ready'
126
- item_storage.save
127
- reload
123
+ item_storage_status_set(item_storage, 'ready')
128
124
  if remove_local && !src.instance_of?(FC::Storage) && File.exists?(src)
129
125
  if File.directory?(src)
130
126
  FileUtils.rm_r(src)
@@ -136,7 +132,16 @@ module FC
136
132
  end
137
133
  end
138
134
  end
139
-
135
+
136
+ def item_storage_status_set(item_storage, status)
137
+ reload
138
+ marked_for_delete = self.status == 'deferred_delete'
139
+ item_storage.status = status
140
+ item_storage.save
141
+ reload
142
+ mark_deleted if marked_for_delete
143
+ end
144
+
140
145
  # mark item and his items_storages for deferred delete
141
146
  # real delete after policy.delete_deferred_time
142
147
  def mark_deleted
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = '0.5.13'.freeze
2
+ VERSION = '0.5.14'.freeze
3
3
  end
@@ -145,8 +145,10 @@ class DbTest < Test::Unit::TestCase
145
145
  assert_equal 'rec1-sda,rec2-sdd', @policies[1].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages"
146
146
  assert_equal 'rec1-sda', @policies[2].create_storages, "Policy (id=#{@policies[0].id}) incorrect create_storages"
147
147
 
148
- assert_raise(Mysql2::Error, 'Create policy with uniq name') { FC::Policy.new(:create_storages => 'bla,test', :name => 'policy 1').save }
149
- assert_raise(Mysql2::Error, 'Create policy with incorrect create_storages') { FC::Policy.new(:create_storages => 'bla,test', :name => 'new policy').save }
148
+ FC::Policy.new(:create_storages => 'rec2-sda,rec2-sdd', :name => 'policy 1').save
149
+ 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
151
+ assert_nil FC::Policy.where('name = ?', 'new policy').first, "Create policy with incorrect create_storages"
150
152
 
151
153
  assert_raise(Mysql2::Error, 'Change storage name with linked polices') { @storages[0].name = 'blabla'; @storages[0].save }
152
154
  assert_raise(Mysql2::Error, 'Delete storage name with linked polices') { @storages[0].delete }
@@ -45,7 +45,14 @@ class FunctionalTest < Test::Unit::TestCase
45
45
  FC::Storage.any_instance.stubs(:host).returns('localhost')
46
46
  FC::Storage.stubs(:curr_host).returns('localhost')
47
47
  end
48
-
48
+
49
+ def stub_method(obj, method, method_impl)
50
+ obj.singleton_class.send(:alias_method, "#{method}_mock_backup", method)
51
+ obj.define_singleton_method(method, method_impl)
52
+ yield if block_given?
53
+ obj.singleton_class.send(:alias_method, method, "#{method}_mock_backup")
54
+ end
55
+
49
56
  should "item create_from_local successful" do
50
57
  assert_nothing_raised { @item = FC::Item.create_from_local(@@test_file_path, '/bla/bla/test1', @@policies[0], {:tag => 'test'}) }
51
58
  assert_kind_of FC::Item, @item
@@ -130,7 +137,61 @@ class FunctionalTest < Test::Unit::TestCase
130
137
  # no md5 check on copy - success
131
138
  assert_nothing_raised { @item.copy_item_storage(@@storages[0], @@storages[1], item_storage) }
132
139
  end
133
-
140
+
141
+ should 'item keep deferred_delete after copy' do
142
+ @item = FC::Item.create_from_local(@@test_file_path, 'test9', @@policies[0], {:tag => 'test', :no_md5 => true})
143
+ item_storage = @item.make_item_storage(@@storages[1], 'copy')
144
+ @item.mark_deleted
145
+ # rewrite item file
146
+ `dd if=/dev/urandom of=#{@@storages[0].path}#{@item.name} bs=100K count=1 2>&1`
147
+ @item.copy_item_storage(@@storages[0], @@storages[1], item_storage)
148
+ @item.reload
149
+ assert_equal 2, @item.get_item_storages.size
150
+ @item.get_item_storages.each do |is|
151
+ assert_equal 'ready', is.status
152
+ end
153
+ assert_equal 'deferred_delete', @item.status
154
+ end
155
+
156
+ should 'item keep deferred_delete status if changed during copy' do
157
+ @item = FC::Item.create_from_local(@@test_file_path, 'test10', @@policies[0], {:tag => 'test', :no_md5 => true})
158
+ item_storage = @item.make_item_storage(@@storages[1], 'copy')
159
+ # rewrite item file
160
+ `dd if=/dev/urandom of=#{@@storages[0].path}#{@item.name} bs=100K count=1 2>&1`
161
+ # no md5 check on copy - success
162
+ item = @item
163
+ stubbed_method_impl = proc { |*args|
164
+ copy_to_local_mock_backup(*args)
165
+ item.mark_deleted
166
+ }
167
+ stub_method(@@storages[0], :copy_to_local, stubbed_method_impl) do
168
+ @item.copy_item_storage(@@storages[0], @@storages[1], item_storage)
169
+ end
170
+ @item.reload
171
+ assert_equal 'ready', item_storage.status
172
+ assert_equal 'deferred_delete', @item.status
173
+ end
174
+
175
+ should 'item keep deferred_delete status if changed during copy and error was raised' do
176
+ @item = FC::Item.create_from_local(@@test_file_path, 'test11', @@policies[0], {:tag => 'test'})
177
+ item_storage = @item.make_item_storage(@@storages[1], 'copy')
178
+ # rewrite item file
179
+ `dd if=/dev/urandom of=#{@@storages[0].path}#{@item.name} bs=100K count=1 2>&1`
180
+
181
+ # simulate mark_delete during copy process and raise exception
182
+ item = @item
183
+ stubbed_method_impl = proc { |*_|
184
+ item.mark_deleted
185
+ raise 'oops'
186
+ }
187
+ stub_method(@@storages[0], :copy_to_local, stubbed_method_impl) do
188
+ assert_raise(RuntimeError) { @item.copy_item_storage(@@storages[0], @@storages[1], item_storage) }
189
+ end
190
+ @item.reload
191
+ assert_equal 'error', item_storage.status
192
+ assert_equal 'deferred_delete', @item.status
193
+ end
194
+
134
195
  should "item create_from_local inplace" do
135
196
  tmp_file_path = "/tmp/host2-sda/inplace test"
136
197
  `cp #{@@test_file_path.shellescape} #{tmp_file_path.shellescape}`
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - sh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2