Commit 6a63d330 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch '336511-feature-flag-cleanup' into 'master'

Remove the feature flag packages_nuget_new_package_file_updater

See merge request gitlab-org/gitlab!69755
parents 7a9c2762 1630d748
...@@ -21,11 +21,7 @@ module Packages ...@@ -21,11 +21,7 @@ module Packages
try_obtain_lease do try_obtain_lease do
@package_file.transaction do @package_file.transaction do
if use_new_package_file_updater? process_package_update
new_execute
else
legacy_execute
end
end end
end end
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
...@@ -34,7 +30,7 @@ module Packages ...@@ -34,7 +30,7 @@ module Packages
private private
def new_execute def process_package_update
package_to_destroy = nil package_to_destroy = nil
target_package = @package_file.package target_package = @package_file.package
...@@ -50,36 +46,11 @@ module Packages ...@@ -50,36 +46,11 @@ module Packages
end end
update_package(target_package) update_package(target_package)
::Packages::UpdatePackageFileService.new(@package_file, package_id: target_package.id, file_name: package_filename) ::Packages::UpdatePackageFileService.new(@package_file, package_id: target_package.id, file_name: package_filename)
.execute .execute
package_to_destroy&.destroy! package_to_destroy&.destroy!
end end
def legacy_execute
if existing_package
package = link_to_existing_package
elsif symbol_package?
raise InvalidMetadataError, 'symbol package is invalid, matching package does not exist'
else
package = update_linked_package
end
update_package(package)
# Updating file_name updates the path where the file is stored.
# We must pass the file again so that CarrierWave can handle the update
@package_file.update!(
file_name: package_filename,
file: @package_file.file
)
end
def use_new_package_file_updater?
::Feature.enabled?(:packages_nuget_new_package_file_updater, @package_file.project, default_enabled: :yaml)
end
def update_package(package) def update_package(package)
return if symbol_package? return if symbol_package?
......
---
name: packages_nuget_new_package_file_updater
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/336511
milestone: '14.2'
type: development
group: group::package
default_enabled: true
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_redis_shared_state do RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_redis_shared_state do
include ExclusiveLeaseHelpers include ExclusiveLeaseHelpers
let(:package) { create(:nuget_package, :processing, :with_symbol_package) } let!(:package) { create(:nuget_package, :processing, :with_symbol_package) }
let(:package_file) { package.package_files.first } let(:package_file) { package.package_files.first }
let(:service) { described_class.new(package_file) } let(:service) { described_class.new(package_file) }
let(:package_name) { 'DummyProject.DummyPackage' } let(:package_name) { 'DummyProject.DummyPackage' }
...@@ -63,234 +63,213 @@ RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_ ...@@ -63,234 +63,213 @@ RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_
end end
end end
shared_examples 'handling all conditions' do context 'with no existing package' do
context 'with no existing package' do let(:package_id) { package.id }
let(:package_id) { package.id }
it 'updates package and package file', :aggregate_failures do
expect { subject }
.to not_change { ::Packages::Package.count }
.and change { Packages::Dependency.count }.by(1)
.and change { Packages::DependencyLink.count }.by(1)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package.reload.name).to eq(package_name)
expect(package.version).to eq(package_version)
expect(package).to be_default
expect(package_file.reload.file_name).to eq(package_file_name)
# hard reset needed to properly reload package_file.file
expect(Packages::PackageFile.find(package_file.id).file.size).not_to eq 0
end
it 'updates package and package file', :aggregate_failures do it_behaves_like 'taking the lease'
expect { subject }
.to not_change { ::Packages::Package.count }
.and change { Packages::Dependency.count }.by(1)
.and change { Packages::DependencyLink.count }.by(1)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package.reload.name).to eq(package_name) it_behaves_like 'not updating the package if the lease is taken'
expect(package.version).to eq(package_version) end
expect(package).to be_default
expect(package_file.reload.file_name).to eq(package_file_name)
# hard reset needed to properly reload package_file.file
expect(Packages::PackageFile.find(package_file.id).file.size).not_to eq 0
end
it_behaves_like 'taking the lease' context 'with existing package' do
let!(:existing_package) { create(:nuget_package, project: package.project, name: package_name, version: package_version) }
let(:package_id) { existing_package.id }
it_behaves_like 'not updating the package if the lease is taken' it 'link existing package and updates package file', :aggregate_failures do
end expect(service).to receive(:try_obtain_lease).and_call_original
context 'with existing package' do expect { subject }
let!(:existing_package) { create(:nuget_package, project: package.project, name: package_name, version: package_version) } .to change { ::Packages::Package.count }.by(-1)
let(:package_id) { existing_package.id } .and change { Packages::Dependency.count }.by(0)
.and change { Packages::DependencyLink.count }.by(0)
.and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(0)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package_file.reload.file_name).to eq(package_file_name)
expect(package_file.package).to eq(existing_package)
end
it 'link existing package and updates package file', :aggregate_failures do it_behaves_like 'taking the lease'
expect(service).to receive(:try_obtain_lease).and_call_original
expect { subject } it_behaves_like 'not updating the package if the lease is taken'
.to change { ::Packages::Package.count }.by(-1) end
.and change { Packages::Dependency.count }.by(0)
.and change { Packages::DependencyLink.count }.by(0)
.and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(0)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package_file.reload.file_name).to eq(package_file_name)
expect(package_file.package).to eq(existing_package)
end
it_behaves_like 'taking the lease' context 'with a nuspec file with metadata' do
let(:nuspec_filepath) { 'packages/nuget/with_metadata.nuspec' }
let(:expected_tags) { %w(foo bar test tag1 tag2 tag3 tag4 tag5) }
it_behaves_like 'not updating the package if the lease is taken' before do
allow_next_instance_of(Packages::Nuget::MetadataExtractionService) do |service|
allow(service)
.to receive(:nuspec_file_content).and_return(fixture_file(nuspec_filepath))
end
end end
context 'with a nuspec file with metadata' do it 'creates tags' do
let(:nuspec_filepath) { 'packages/nuget/with_metadata.nuspec' } expect(service).to receive(:try_obtain_lease).and_call_original
let(:expected_tags) { %w(foo bar test tag1 tag2 tag3 tag4 tag5) } expect { subject }.to change { ::Packages::Tag.count }.by(8)
expect(package.reload.tags.map(&:name)).to contain_exactly(*expected_tags)
end
before do context 'with existing package and tags' do
allow_next_instance_of(Packages::Nuget::MetadataExtractionService) do |service| let!(:existing_package) { create(:nuget_package, project: package.project, name: 'DummyProject.WithMetadata', version: '1.2.3') }
allow(service) let!(:tag1) { create(:packages_tag, package: existing_package, name: 'tag1') }
.to receive(:nuspec_file_content).and_return(fixture_file(nuspec_filepath)) let!(:tag2) { create(:packages_tag, package: existing_package, name: 'tag2') }
end let!(:tag3) { create(:packages_tag, package: existing_package, name: 'tag_not_in_metadata') }
end
it 'creates tags' do it 'creates tags and deletes those not in metadata' do
expect(service).to receive(:try_obtain_lease).and_call_original expect(service).to receive(:try_obtain_lease).and_call_original
expect { subject }.to change { ::Packages::Tag.count }.by(8) expect { subject }.to change { ::Packages::Tag.count }.by(5)
expect(package.reload.tags.map(&:name)).to contain_exactly(*expected_tags) expect(existing_package.tags.map(&:name)).to contain_exactly(*expected_tags)
end end
end
context 'with existing package and tags' do it 'creates nuget metadatum', :aggregate_failures do
let!(:existing_package) { create(:nuget_package, project: package.project, name: 'DummyProject.WithMetadata', version: '1.2.3') } expect { subject }
let!(:tag1) { create(:packages_tag, package: existing_package, name: 'tag1') } .to not_change { ::Packages::Package.count }
let!(:tag2) { create(:packages_tag, package: existing_package, name: 'tag2') } .and change { ::Packages::Nuget::Metadatum.count }.by(1)
let!(:tag3) { create(:packages_tag, package: existing_package, name: 'tag_not_in_metadata') }
it 'creates tags and deletes those not in metadata' do
expect(service).to receive(:try_obtain_lease).and_call_original
expect { subject }.to change { ::Packages::Tag.count }.by(5)
expect(existing_package.tags.map(&:name)).to contain_exactly(*expected_tags)
end
end
it 'creates nuget metadatum', :aggregate_failures do
expect { subject }
.to not_change { ::Packages::Package.count }
.and change { ::Packages::Nuget::Metadatum.count }.by(1)
metadatum = package_file.reload.package.nuget_metadatum
expect(metadatum.license_url).to eq('https://opensource.org/licenses/MIT')
expect(metadatum.project_url).to eq('https://gitlab.com/gitlab-org/gitlab')
expect(metadatum.icon_url).to eq('https://opensource.org/files/osi_keyhole_300X300_90ppi_0.png')
end
context 'with too long url' do metadatum = package_file.reload.package.nuget_metadatum
let_it_be(:too_long_url) { "http://localhost/#{'bananas' * 50}" } expect(metadatum.license_url).to eq('https://opensource.org/licenses/MIT')
expect(metadatum.project_url).to eq('https://gitlab.com/gitlab-org/gitlab')
expect(metadatum.icon_url).to eq('https://opensource.org/files/osi_keyhole_300X300_90ppi_0.png')
end
let(:metadata) { { package_name: package_name, package_version: package_version, license_url: too_long_url } } context 'with too long url' do
let_it_be(:too_long_url) { "http://localhost/#{'bananas' * 50}" }
before do let(:metadata) { { package_name: package_name, package_version: package_version, license_url: too_long_url } }
allow(service).to receive(:metadata).and_return(metadata)
end
it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError before do
allow(service).to receive(:metadata).and_return(metadata)
end end
it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError
end end
end
context 'with nuspec file with dependencies' do context 'with nuspec file with dependencies' do
let(:nuspec_filepath) { 'packages/nuget/with_dependencies.nuspec' } let(:nuspec_filepath) { 'packages/nuget/with_dependencies.nuspec' }
let(:package_name) { 'Test.Package' } let(:package_name) { 'Test.Package' }
let(:package_version) { '3.5.2' } let(:package_version) { '3.5.2' }
let(:package_file_name) { 'test.package.3.5.2.nupkg' } let(:package_file_name) { 'test.package.3.5.2.nupkg' }
before do before do
allow_next_instance_of(Packages::Nuget::MetadataExtractionService) do |service| allow_next_instance_of(Packages::Nuget::MetadataExtractionService) do |service|
allow(service) allow(service)
.to receive(:nuspec_file_content).and_return(fixture_file(nuspec_filepath)) .to receive(:nuspec_file_content).and_return(fixture_file(nuspec_filepath))
end
end end
end
it 'updates package and package file', :aggregate_failures do it 'updates package and package file', :aggregate_failures do
expect { subject } expect { subject }
.to not_change { ::Packages::Package.count } .to not_change { ::Packages::Package.count }
.and change { Packages::Dependency.count }.by(4) .and change { Packages::Dependency.count }.by(4)
.and change { Packages::DependencyLink.count }.by(4) .and change { Packages::DependencyLink.count }.by(4)
.and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(2) .and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(2)
expect(package.reload.name).to eq(package_name) expect(package.reload.name).to eq(package_name)
expect(package.version).to eq(package_version) expect(package.version).to eq(package_version)
expect(package).to be_default expect(package).to be_default
expect(package_file.reload.file_name).to eq(package_file_name) expect(package_file.reload.file_name).to eq(package_file_name)
# hard reset needed to properly reload package_file.file # hard reset needed to properly reload package_file.file
expect(Packages::PackageFile.find(package_file.id).file.size).not_to eq 0 expect(Packages::PackageFile.find(package_file.id).file.size).not_to eq 0
end
end end
end
context 'with package file not containing a nuspec file' do context 'with package file not containing a nuspec file' do
before do before do
allow_next_instance_of(Zip::File) do |file| allow_next_instance_of(Zip::File) do |file|
allow(file).to receive(:glob).and_return([]) allow(file).to receive(:glob).and_return([])
end
end end
it_behaves_like 'raising an', ::Packages::Nuget::MetadataExtractionService::ExtractionError
end end
context 'with a symbol package' do it_behaves_like 'raising an', ::Packages::Nuget::MetadataExtractionService::ExtractionError
let(:package_file) { package.package_files.last } end
let(:package_file_name) { 'dummyproject.dummypackage.1.0.0.snupkg' }
context 'with no existing package' do context 'with a symbol package' do
let(:package_id) { package.id } let(:package_file) { package.package_files.last }
let(:package_file_name) { 'dummyproject.dummypackage.1.0.0.snupkg' }
it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError context 'with no existing package' do
end let(:package_id) { package.id }
context 'with existing package' do
let!(:existing_package) { create(:nuget_package, project: package.project, name: package_name, version: package_version) }
let(:package_id) { existing_package.id }
it 'link existing package and updates package file', :aggregate_failures do it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError
expect(service).to receive(:try_obtain_lease).and_call_original end
expect(::Packages::Nuget::SyncMetadatumService).not_to receive(:new)
expect(::Packages::UpdateTagsService).not_to receive(:new)
expect { subject } context 'with existing package' do
.to change { ::Packages::Package.count }.by(-1) let!(:existing_package) { create(:nuget_package, project: package.project, name: package_name, version: package_version) }
.and change { Packages::Dependency.count }.by(0) let(:package_id) { existing_package.id }
.and change { Packages::DependencyLink.count }.by(0)
.and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(0)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package_file.reload.file_name).to eq(package_file_name)
expect(package_file.package).to eq(existing_package)
end
it_behaves_like 'taking the lease' it 'link existing package and updates package file', :aggregate_failures do
expect(service).to receive(:try_obtain_lease).and_call_original
expect(::Packages::Nuget::SyncMetadatumService).not_to receive(:new)
expect(::Packages::UpdateTagsService).not_to receive(:new)
it_behaves_like 'not updating the package if the lease is taken' expect { subject }
.to change { ::Packages::Package.count }.by(-1)
.and change { Packages::Dependency.count }.by(0)
.and change { Packages::DependencyLink.count }.by(0)
.and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(0)
.and change { ::Packages::Nuget::Metadatum.count }.by(0)
expect(package_file.reload.file_name).to eq(package_file_name)
expect(package_file.package).to eq(existing_package)
end end
end
context 'with an invalid package name' do
invalid_names = [
'',
'My/package',
'../../../my_package',
'%2e%2e%2fmy_package'
]
invalid_names.each do |invalid_name| it_behaves_like 'taking the lease'
before do
allow(service).to receive(:package_name).and_return(invalid_name)
end
it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError it_behaves_like 'not updating the package if the lease is taken'
end
end end
end
context 'with an invalid package version' do context 'with an invalid package name' do
invalid_versions = [ invalid_names = [
'', '',
'555', 'My/package',
'1.2', '../../../my_package',
'1./2.3', '%2e%2e%2fmy_package'
'../../../../../1.2.3', ]
'%2e%2e%2f1.2.3'
] invalid_names.each do |invalid_name|
before do
invalid_versions.each do |invalid_version| allow(service).to receive(:package_name).and_return(invalid_name)
before do
allow(service).to receive(:package_version).and_return(invalid_version)
end
it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError
end end
end
end
context 'with packages_nuget_new_package_file_updater enabled' do it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError
before do
expect(service).not_to receive(:legacy_execute)
end end
it_behaves_like 'handling all conditions'
end end
context 'with packages_nuget_new_package_file_updater disabled' do context 'with an invalid package version' do
before do invalid_versions = [
stub_feature_flags(packages_nuget_new_package_file_updater: false) '',
expect(::Packages::UpdatePackageFileService) '555',
.not_to receive(:new).with(package_file, instance_of(Hash)).and_call_original '1.2',
expect(service).not_to receive(:new_execute) '1./2.3',
end '../../../../../1.2.3',
'%2e%2e%2f1.2.3'
]
invalid_versions.each do |invalid_version|
before do
allow(service).to receive(:package_version).and_return(invalid_version)
end
it_behaves_like 'handling all conditions' it_behaves_like 'raising an', ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError
end
end end
end 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