From 992c0a0b23121a70f82af8b26ffebdd7cb797ac2 Mon Sep 17 00:00:00 2001 From: "parag.jain" Date: Wed, 11 Dec 2024 13:02:53 +0530 Subject: [PATCH 1/4] Refactor SUSE repo cleanup and local path generation logic supporting akamai url --- app/models/repository.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 6a7719aa2..6fedd7945 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,14 +23,16 @@ class Repository < ApplicationRecord class << self def remove_suse_repos_without_tokens! - where(auth_token: nil).where('external_url LIKE ?', 'https://updates.suse.com%').delete_all + where(auth_token: nil) + .where("external_url LIKE 'https://updates.suse.com%' OR external_url LIKE 'https://dl.suse.com%'") + .delete_all end # Mangles remote repo URL to make a nicer local path, see specs for examples def make_local_path(url) uri = URI(url) path = uri.path.to_s - path.gsub!(%r{^/repo}, '') if (uri.hostname == 'updates.suse.com') + path.gsub!(%r{^/repo}, '') if (uri.hostname == 'updates.suse.com' || uri.hostname == 'dl.suse.com') (path == '') ? '/' : path end From caa983103853f35b895d95dd7290c8b0bbc41834 Mon Sep 17 00:00:00 2001 From: "parag.jain" Date: Thu, 12 Dec 2024 17:50:37 +0530 Subject: [PATCH 2/4] remove function remove_suse_repos_without_tokens!; --- app/models/repository.rb | 10 ++-------- lib/rmt/scc.rb | 6 ------ spec/lib/rmt/scc_spec.rb | 4 ---- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 6fedd7945..ff09674e0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -21,18 +21,12 @@ class Repository < ApplicationRecord before_destroy :ensure_destroy_possible class << self - - def remove_suse_repos_without_tokens! - where(auth_token: nil) - .where("external_url LIKE 'https://updates.suse.com%' OR external_url LIKE 'https://dl.suse.com%'") - .delete_all - end - # Mangles remote repo URL to make a nicer local path, see specs for examples def make_local_path(url) uri = URI(url) path = uri.path.to_s - path.gsub!(%r{^/repo}, '') if (uri.hostname == 'updates.suse.com' || uri.hostname == 'dl.suse.com') + # drop '/repo' from SLE11 paths, to avoid double /repo/repo in local storage path. + path.gsub!(%r{^/repo/\$RCE/}, '/$RCE/') (path == '') ? '/' : path end diff --git a/lib/rmt/scc.rb b/lib/rmt/scc.rb index 59fccdf2a..63cbe5106 100644 --- a/lib/rmt/scc.rb +++ b/lib/rmt/scc.rb @@ -24,9 +24,6 @@ def sync data.each { |item| migration_paths(item) } update_repositories(scc_api_client.list_repositories) - - Repository.remove_suse_repos_without_tokens! - update_subscriptions(scc_api_client.list_subscriptions) end @@ -68,9 +65,6 @@ def import(path) data.each { |item| migration_paths(item) } update_repositories(JSON.parse(File.read(File.join(path, 'organizations_repositories.json')), symbolize_names: true)) - - Repository.remove_suse_repos_without_tokens! - update_subscriptions(JSON.parse(File.read(File.join(path, 'organizations_subscriptions.json')), symbolize_names: true)) end diff --git a/spec/lib/rmt/scc_spec.rb b/spec/lib/rmt/scc_spec.rb index 802cf1c8a..4b62370fb 100644 --- a/spec/lib/rmt/scc_spec.rb +++ b/spec/lib/rmt/scc_spec.rb @@ -290,10 +290,6 @@ def scc expect { suse_repo_with_token.reload }.not_to raise_error end - it 'SUSE repos without auth_tokens are removed' do - expect { suse_repo_without_token.reload }.to raise_error(ActiveRecord::RecordNotFound) - end - it 'other repos without auth_tokens persist' do expect { other_repo_without_token.reload }.not_to raise_error end From d81ee4b82a8591e2f56203236418116524a6fb74 Mon Sep 17 00:00:00 2001 From: "parag.jain" Date: Mon, 16 Dec 2024 14:08:21 +0530 Subject: [PATCH 3/4] Refactor SUSE repo cleanup and local path generation logic supporting akamai url --- app/models/repository.rb | 5 +++++ lib/rmt/scc.rb | 6 ++++++ spec/lib/rmt/scc_spec.rb | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index ff09674e0..347ec5548 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -21,6 +21,11 @@ class Repository < ApplicationRecord before_destroy :ensure_destroy_possible class << self + + def remove_suse_repos_without_tokens! + where(auth_token: nil).where("external_url LIKE '%.suse.com%'").where(installer_updates: 0).delete_all + end + # Mangles remote repo URL to make a nicer local path, see specs for examples def make_local_path(url) uri = URI(url) diff --git a/lib/rmt/scc.rb b/lib/rmt/scc.rb index 63cbe5106..59fccdf2a 100644 --- a/lib/rmt/scc.rb +++ b/lib/rmt/scc.rb @@ -24,6 +24,9 @@ def sync data.each { |item| migration_paths(item) } update_repositories(scc_api_client.list_repositories) + + Repository.remove_suse_repos_without_tokens! + update_subscriptions(scc_api_client.list_subscriptions) end @@ -65,6 +68,9 @@ def import(path) data.each { |item| migration_paths(item) } update_repositories(JSON.parse(File.read(File.join(path, 'organizations_repositories.json')), symbolize_names: true)) + + Repository.remove_suse_repos_without_tokens! + update_subscriptions(JSON.parse(File.read(File.join(path, 'organizations_subscriptions.json')), symbolize_names: true)) end diff --git a/spec/lib/rmt/scc_spec.rb b/spec/lib/rmt/scc_spec.rb index 496730e56..a62077d00 100644 --- a/spec/lib/rmt/scc_spec.rb +++ b/spec/lib/rmt/scc_spec.rb @@ -261,7 +261,8 @@ :repository, :with_products, auth_token: nil, - external_url: 'https://example.com/repos/not/updates.suse.com/' + external_url: 'https://installer-updates.suse.com/repos/not/updates', + installer_updates: true ) end @@ -290,6 +291,10 @@ def scc expect { suse_repo_with_token.reload }.not_to raise_error end + it 'SUSE repos without auth_tokens are removed' do + expect { suse_repo_without_token.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + it 'other repos without auth_tokens persist' do expect { other_repo_without_token.reload }.not_to raise_error end From 3503590a1b8e7128b707fd32e15dc1eba985d687 Mon Sep 17 00:00:00 2001 From: "parag.jain" Date: Mon, 16 Dec 2024 16:41:35 +0530 Subject: [PATCH 4/4] add check for custom repos --- app/models/repository.rb | 2 +- spec/lib/rmt/scc_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 347ec5548..c65c602cd 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,7 +23,7 @@ class Repository < ApplicationRecord class << self def remove_suse_repos_without_tokens! - where(auth_token: nil).where("external_url LIKE '%.suse.com%'").where(installer_updates: 0).delete_all + where(auth_token: nil).where("external_url LIKE '%.suse.com%'").where(installer_updates: 0).where.not(scc_id: nil).delete_all end # Mangles remote repo URL to make a nicer local path, see specs for examples diff --git a/spec/lib/rmt/scc_spec.rb b/spec/lib/rmt/scc_spec.rb index a62077d00..f1e3b9d61 100644 --- a/spec/lib/rmt/scc_spec.rb +++ b/spec/lib/rmt/scc_spec.rb @@ -265,6 +265,16 @@ installer_updates: true ) end + let!(:custom_repo) do + FactoryBot.create( + :repository, + :with_products, + auth_token: nil, + external_url: 'http://customer.com/stuff.suse.com/x86', + installer_updates: false, + scc_id: nil + ) + end before do # to prevent 'does not implement' verifying doubles error @@ -298,6 +308,10 @@ def scc it 'other repos without auth_tokens persist' do expect { other_repo_without_token.reload }.not_to raise_error end + + it 'custom repos without auth_tokens persist' do + expect { custom_repo.reload }.not_to raise_error + end end describe '#export' do