Commit 2df57e51 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch...

Merge branch '334004-rake-task-gitlab-rake-gitlab-pages-deployments-migrate_to_object_storage-fails-with-error' into 'master'

Fix pages deployment storage migration

See merge request gitlab-org/gitlab!64697
parents 7a4e8196 55f8b012
......@@ -8,7 +8,7 @@ module Gitlab
end
def migrate_to_remote_storage
logger.info('Starting transfer to remote storage')
logger.info('Starting transfer to object storage')
migrate(items_with_files_stored_locally, ObjectStorage::Store::REMOTE)
end
......@@ -38,11 +38,11 @@ module Gitlab
end
def log_success(item, store)
logger.info("Transferred #{item.class.name} ID #{item.id} of type #{item.file_type} with size #{item.size} to #{storage_label(store)} storage")
logger.info("Transferred #{item.class.name} ID #{item.id} with size #{item.size} to #{storage_label(store)} storage")
end
def log_error(err, item)
logger.warn("Failed to transfer #{item.class.name} of type #{item.file_type} and ID #{item.id} with error: #{err.message}")
logger.warn("Failed to transfer #{item.class.name} ID #{item.id} with error: #{err.message}")
end
def storage_label(store)
......
# frozen_string_literal: true
require 'spec_helper'
require 'support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples'
RSpec.describe Gitlab::LocalAndRemoteStorageMigration::ArtifactMigrater do
before do
stub_artifacts_object_storage(enabled: true)
end
let!(:item) { create(:ci_job_artifact, :archive, file_store: start_store) }
it_behaves_like 'local and remote storage migration'
end
# frozen_string_literal: true
require 'spec_helper'
require 'support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples'
RSpec.describe Gitlab::LocalAndRemoteStorageMigration::PagesDeploymentMigrater do
before do
stub_pages_object_storage(::Pages::DeploymentUploader, enabled: true)
end
let!(:item) { create(:pages_deployment, file_store: start_store) }
it_behaves_like 'local and remote storage migration'
end
# frozen_string_literal: true
RSpec.shared_examples 'local and remote storage migration' do
let(:logger) { Logger.new("/dev/null") }
let(:migrater) { described_class.new(logger) }
using RSpec::Parameterized::TableSyntax
where(:start_store, :end_store, :method) do
ObjectStorage::Store::LOCAL | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage
ObjectStorage::Store::REMOTE | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
ObjectStorage::Store::REMOTE | ObjectStorage::Store::LOCAL | :migrate_to_local_storage
ObjectStorage::Store::LOCAL | ObjectStorage::Store::LOCAL | :migrate_to_local_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
end
with_them do
let(:storage_name) { end_store == ObjectStorage::Store::REMOTE ? 'object' : 'local' }
it 'successfully migrates' do
expect(logger).to receive(:info).with("Starting transfer to #{storage_name} storage")
if start_store != end_store
expect(logger).to receive(:info).with("Transferred #{item.class.name} ID #{item.id} with size #{item.size} to #{storage_name} storage")
end
expect(item.file_store).to eq(start_store)
migrater.send(method)
expect(item.reload.file_store).to eq(end_store)
end
end
context 'when migration fails' do
let(:start_store) { ObjectStorage::Store::LOCAL }
it 'prints error' do
expect_next_instance_of(item.file.class) do |file|
expect(file).to receive(:migrate!).and_raise("error message")
end
expect(logger).to receive(:info).with("Starting transfer to object storage")
expect(logger).to receive(:warn).with("Failed to transfer #{item.class.name} ID #{item.id} with error: error message")
expect(item.file_store).to eq(start_store)
migrater.migrate_to_remote_storage
expect(item.reload.file_store).to eq(start_store)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment