summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2018-06-06 12:51:03 -0700
committerMichael Kozono <mkozono@gmail.com>2018-06-12 13:58:01 -0700
commitd4ad92cd06fd0367f93bcb908cf50261d013fe43 (patch)
tree9913bb878ac9e00543803a9aa7f7d023cd842df2
parent8eea1a92b51c0d2a7ca1fae20d9d6e70a45bb87a (diff)
downloadgitlab-ce-d4ad92cd06fd0367f93bcb908cf50261d013fe43.tar.gz
Support verifying remote store uploads
-rw-r--r--lib/gitlab/verify/batch_verifier.rb24
-rw-r--r--lib/gitlab/verify/job_artifacts.rb4
-rw-r--r--lib/gitlab/verify/lfs_objects.rb4
-rw-r--r--lib/gitlab/verify/uploads.rb6
-rw-r--r--spec/lib/gitlab/verify/uploads_spec.rb16
5 files changed, 44 insertions, 10 deletions
diff --git a/lib/gitlab/verify/batch_verifier.rb b/lib/gitlab/verify/batch_verifier.rb
index 1ef369a4b67..fd01602c256 100644
--- a/lib/gitlab/verify/batch_verifier.rb
+++ b/lib/gitlab/verify/batch_verifier.rb
@@ -34,15 +34,28 @@ module Gitlab
end
def verify(object)
+ if local?(object)
+ verify_local(object)
+ else
+ verify_remote(object)
+ end
+
+ nil
+ rescue => err
+ [object, err]
+ end
+
+ def verify_local(object)
expected = expected_checksum(object)
actual = actual_checksum(object)
raise 'Checksum missing' unless expected.present?
raise 'Checksum mismatch' unless expected == actual
+ end
- nil
- rescue => err
- [object, err]
+ # We don't calculate checksum for remote objects, so just check existence
+ def verify_remote(object)
+ raise 'Remote object does not exist' unless object.build_uploader.exists?
end
# This should return an ActiveRecord::Relation suitable for calling #in_batches on
@@ -50,6 +63,11 @@ module Gitlab
raise NotImplementedError.new
end
+ # Should return true if the object is stored locally
+ def local?(_object)
+ raise NotImplementedError.new
+ end
+
# The checksum we expect the object to have
def expected_checksum(_object)
raise NotImplementedError.new
diff --git a/lib/gitlab/verify/job_artifacts.rb b/lib/gitlab/verify/job_artifacts.rb
index 03500a61074..afee3b84268 100644
--- a/lib/gitlab/verify/job_artifacts.rb
+++ b/lib/gitlab/verify/job_artifacts.rb
@@ -15,6 +15,10 @@ module Gitlab
::Ci::JobArtifact.all
end
+ def local?(artifact)
+ artifact.local_store?
+ end
+
def expected_checksum(artifact)
artifact.file_sha256
end
diff --git a/lib/gitlab/verify/lfs_objects.rb b/lib/gitlab/verify/lfs_objects.rb
index 970e2a7b718..bfda339f129 100644
--- a/lib/gitlab/verify/lfs_objects.rb
+++ b/lib/gitlab/verify/lfs_objects.rb
@@ -15,6 +15,10 @@ module Gitlab
LfsObject.with_files_stored_locally
end
+ def local?(lfs_object)
+ lfs_object.local_store?
+ end
+
def expected_checksum(lfs_object)
lfs_object.oid
end
diff --git a/lib/gitlab/verify/uploads.rb b/lib/gitlab/verify/uploads.rb
index 0ffa71a6d72..70916aeed4f 100644
--- a/lib/gitlab/verify/uploads.rb
+++ b/lib/gitlab/verify/uploads.rb
@@ -12,7 +12,11 @@ module Gitlab
private
def relation
- Upload.with_files_stored_locally
+ Upload.all
+ end
+
+ def local?(upload)
+ upload.local?
end
def expected_checksum(upload)
diff --git a/spec/lib/gitlab/verify/uploads_spec.rb b/spec/lib/gitlab/verify/uploads_spec.rb
index 85768308edc..1a4e5c626a4 100644
--- a/spec/lib/gitlab/verify/uploads_spec.rb
+++ b/spec/lib/gitlab/verify/uploads_spec.rb
@@ -44,16 +44,20 @@ describe Gitlab::Verify::Uploads do
context 'with remote files' do
before do
stub_uploads_object_storage(AvatarUploader)
+ upload.update!(store: ObjectStorage::Store::REMOTE)
end
- it 'skips uploads in object storage' do
- local_failure = create(:upload)
- create(:upload, :object_storage)
+ it 'passes uploads in object storage that exist' do
+ expect_any_instance_of(AvatarUploader).to receive(:exists?).and_return(true)
- failures = {}
- described_class.new(batch_size: 10).run_batches { |_, failed| failures.merge!(failed) }
+ expect(failures).to eq({})
+ end
+
+ it 'fails uploads in object storage that do not exist' do
+ expect_any_instance_of(AvatarUploader).to receive(:exists?).and_return(false)
- expect(failures.keys).to contain_exactly(local_failure)
+ expect(failures.keys).to contain_exactly(upload)
+ expect(failure.to_s).to include('Remote object does not exist')
end
end
end