From 4b7fea60a5990357d4e857437f11a401484bdddf Mon Sep 17 00:00:00 2001 From: Adnilson Date: Thu, 20 Jun 2024 12:15:59 +0100 Subject: [PATCH 01/18] Create migration to remove ltss7 from products --- db/migrate/20240620111456_remove_ltss_7_from_products.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20240620111456_remove_ltss_7_from_products.rb diff --git a/db/migrate/20240620111456_remove_ltss_7_from_products.rb b/db/migrate/20240620111456_remove_ltss_7_from_products.rb new file mode 100644 index 000000000..fe7358ca6 --- /dev/null +++ b/db/migrate/20240620111456_remove_ltss_7_from_products.rb @@ -0,0 +1,5 @@ +class RemoveLtss7FromProducts < ActiveRecord::Migration[6.1] + def change + Product.where(cpe: "cpe:/o:suse:res-ha-ltss:7").destroy! + end +end From f7c2ef58648d308397b16c0478d52840e08dca9f Mon Sep 17 00:00:00 2001 From: Adnilson Date: Thu, 20 Jun 2024 12:21:16 +0100 Subject: [PATCH 02/18] Run lint --- db/migrate/20240620111456_remove_ltss_7_from_products.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20240620111456_remove_ltss_7_from_products.rb b/db/migrate/20240620111456_remove_ltss_7_from_products.rb index fe7358ca6..a089b28bb 100644 --- a/db/migrate/20240620111456_remove_ltss_7_from_products.rb +++ b/db/migrate/20240620111456_remove_ltss_7_from_products.rb @@ -1,5 +1,5 @@ class RemoveLtss7FromProducts < ActiveRecord::Migration[6.1] def change - Product.where(cpe: "cpe:/o:suse:res-ha-ltss:7").destroy! + Product.where(cpe: 'cpe:/o:suse:res-ha-ltss:7').destroy! end end From 02757341bfc9e5c152b9266bad8c726fda7b0ae5 Mon Sep 17 00:00:00 2001 From: Adnilson Date: Thu, 20 Jun 2024 12:47:31 +0100 Subject: [PATCH 03/18] Destroy products as a list --- db/migrate/20240620111456_remove_ltss_7_from_products.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/migrate/20240620111456_remove_ltss_7_from_products.rb b/db/migrate/20240620111456_remove_ltss_7_from_products.rb index a089b28bb..16d73b123 100644 --- a/db/migrate/20240620111456_remove_ltss_7_from_products.rb +++ b/db/migrate/20240620111456_remove_ltss_7_from_products.rb @@ -1,5 +1,7 @@ class RemoveLtss7FromProducts < ActiveRecord::Migration[6.1] def change - Product.where(cpe: 'cpe:/o:suse:res-ha-ltss:7').destroy! + products = Product.where(cpe: 'cpe:/o:suse:res-ha-ltss:7') + + products.each(&:destroy) end end From ae306041b1ba0f0a2304ed09a9ca12733d5f4cb8 Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Tue, 25 Jun 2024 17:04:54 +0100 Subject: [PATCH 04/18] Fix wrongly named variable for the registry cache path --- engines/registry/lib/registry/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/registry/lib/registry/engine.rb b/engines/registry/lib/registry/engine.rb index 6fbcdc4a6..aa5481f12 100644 --- a/engines/registry/lib/registry/engine.rb +++ b/engines/registry/lib/registry/engine.rb @@ -2,7 +2,7 @@ module Registry class << self def remove_auth_cache(registry_cache_key) cache_path = File.join(Rails.application.config.registry_cache_dir, registry_cache_key) - File.unlink(registry_cache_path) if File.exist?(cache_path) + File.unlink(cache_path) if File.exist?(cache_path) end end From 395ef65af4d9ad49cdd7897b8dbf32227d6860a6 Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Thu, 27 Jun 2024 09:08:27 +0100 Subject: [PATCH 05/18] Set the agreed path for the repos and registry cache Set the cache paths inside the Instance Verification engine --- config/environments/production.rb | 11 ----------- .../config/environments/production.rb | 7 +++++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 1589ece0f..a0be67e85 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -19,17 +19,6 @@ # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? - config.cache_config_file = '/var/lib/rmt/rmt-cache-trim.sh' - config.repo_cache_dir = Rails.root.join('tmp/cache/repository') - config.registry_cache_dir = Rails.root.join('tmp/cache/registry') - cache_config_content = [ - "REPOSITORY_CLIENT_CACHE_DIRECTORY=#{config.repo_cache_dir}", - 'REPOSITORY_CACHE_EXPIRY_MINUTES=20', - "REGISTRY_CLIENT_CACHE_DIRECTORY=#{config.registry_cache_dir}", - "REGISTRY_CACHE_EXPIRY_MINUTES=#{Settings[:registry].try(:token_expiration) || 480}" # 480: 8 hours in minutes - ].join("\n") - File.write(config.cache_config_file, cache_config_content) - # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' diff --git a/engines/instance_verification/config/environments/production.rb b/engines/instance_verification/config/environments/production.rb index aaf300b86..f71e6354f 100644 --- a/engines/instance_verification/config/environments/production.rb +++ b/engines/instance_verification/config/environments/production.rb @@ -2,10 +2,13 @@ module InstanceVerification class Application < Rails::Application config.cache_config_file = '/var/lib/rmt/rmt-cache-trim.sh' - config.repo_cache_dir = '/run/rmt/cache/repository' + config.repo_cache_dir = Rails.root.join('tmp/cache/repository') + config.registry_cache_dir = Rails.root.join('tmp/cache/registry') cache_config_content = [ "REPOSITORY_CLIENT_CACHE_DIRECTORY=#{config.repo_cache_dir}", - 'REPOSITORY_CACHE_EXPIRY_MINUTES=20' + 'REPOSITORY_CACHE_EXPIRY_MINUTES=20', + "REGISTRY_CLIENT_CACHE_DIRECTORY=#{config.registry_cache_dir}", + "REGISTRY_CACHE_EXPIRY_MINUTES=#{Settings[:registry].try(:token_expiration) || 480}" # 480: 8 hours in minutes ].join("\n") File.write(config.cache_config_file, cache_config_content) end From 2e442a99bd94a00645ed01100988d56d8097cb64 Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Thu, 27 Jun 2024 09:12:20 +0100 Subject: [PATCH 06/18] Use that value for tests --- engines/registry/spec/data/rmt-cache-trim.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/registry/spec/data/rmt-cache-trim.sh b/engines/registry/spec/data/rmt-cache-trim.sh index 108a042a4..84e86e8cd 100644 --- a/engines/registry/spec/data/rmt-cache-trim.sh +++ b/engines/registry/spec/data/rmt-cache-trim.sh @@ -1,4 +1,4 @@ -REPOSITORY_CLIENT_CACHE_DIRECTORY="/run/rmt/cache/repository" +REPOSITORY_CLIENT_CACHE_DIRECTORY="/usr/share/rmt/tmp/cache/repository" REPOSITORY_CACHE_EXPIRY_MINUTES=20 -REGISTRY_CLIENT_CACHE_DIRECTORY="/run/rmt/cache/registry" +REGISTRY_CLIENT_CACHE_DIRECTORY="/usr/share/rmt/tmp/cache/registry" REGISTRY_CACHE_EXPIRY_MINUTES=480 From f4caebbe8c6a5b3897f8302f33c78d808ec797a2 Mon Sep 17 00:00:00 2001 From: Adnilson Date: Mon, 1 Jul 2024 13:38:59 +0100 Subject: [PATCH 07/18] =?UTF-8?q?Test=20mess=20from=20Jos=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/lockfile_spec.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 9aaefd36d..c4fa911d1 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -1,13 +1,17 @@ -require File.expand_path('../support/command_rspec_helper', __FILE__) - describe 'rmt-cli' do - before do + around do |example| + parent_pidfile = "/tmp/rmt-parent-#{Process.pid}.pid" + `echo long_text_but_not_the_process_id > /tmp/rmt.lock` `chown _rmt /tmp/rmt.lock` - `/usr/bin/rmt-cli sync > /dev/null &` + + fork { + File.write(parent_pidfile, Process.pid) + exec "/usr/bin/rmt-cli sync >/dev/null" + } + example.run + Process.kill('TERM', File.read(parent_pidfile).to_i) end - # kill running process to let further specs pass - after { `pkill -9 -f rmt-cli` } describe 'lockfile' do command '/usr/bin/rmt-cli sync', allow_error: true From 60d353739f0085d43f3a12a0ef7aa5781634da71 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 15:10:57 +0200 Subject: [PATCH 08/18] Update features/lockfile_spec.rb Co-authored-by: Jose D. Gomez R. --- features/lockfile_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index c4fa911d1..872626d74 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -11,6 +11,7 @@ } example.run Process.kill('TERM', File.read(parent_pidfile).to_i) + File.delete('/tmp/rmt.lock') end describe 'lockfile' do From de7d60fb707838ed600965cdcfad3a4925917960 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 15:11:03 +0200 Subject: [PATCH 09/18] Update features/lockfile_spec.rb Co-authored-by: Jose D. Gomez R. --- features/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 872626d74..b9654dc36 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -2,7 +2,7 @@ around do |example| parent_pidfile = "/tmp/rmt-parent-#{Process.pid}.pid" - `echo long_text_but_not_the_process_id > /tmp/rmt.lock` + File.write('long_text_but_not_the_process_id', '/tmp/rmt.lock') `chown _rmt /tmp/rmt.lock` fork { From e754431e68ef96ae6512934bb87ab75a00d74d49 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 15:37:32 +0200 Subject: [PATCH 10/18] Update features/lockfile_spec.rb --- features/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index b9654dc36..82ab9bd62 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -2,7 +2,7 @@ around do |example| parent_pidfile = "/tmp/rmt-parent-#{Process.pid}.pid" - File.write('long_text_but_not_the_process_id', '/tmp/rmt.lock') + File.write('/tmp/rmt.lock', 'long_text_but_not_the_process_id') `chown _rmt /tmp/rmt.lock` fork { From c90143e51672c2e57c8d6f6c3ec658d3ea78e8df Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 15:37:41 +0200 Subject: [PATCH 11/18] Update features/lockfile_spec.rb --- features/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 82ab9bd62..4fa265244 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -11,7 +11,7 @@ } example.run Process.kill('TERM', File.read(parent_pidfile).to_i) - File.delete('/tmp/rmt.lock') + FileUtils.rm('/tmp/rmt.lock', force: true) end describe 'lockfile' do From cb8a7379724b06d5466b2e2d5020262be96a8886 Mon Sep 17 00:00:00 2001 From: Adnilson Date: Tue, 2 Jul 2024 15:30:20 +0100 Subject: [PATCH 12/18] Add space on the command --- features/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 4fa265244..defd18c0a 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -7,7 +7,7 @@ fork { File.write(parent_pidfile, Process.pid) - exec "/usr/bin/rmt-cli sync >/dev/null" + exec "/usr/bin/rmt-cli sync > /dev/null" } example.run Process.kill('TERM', File.read(parent_pidfile).to_i) From 3cb0b0ef4793c85ee7f380f6ac8ef4eb9e86bf1b Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 16:33:45 +0200 Subject: [PATCH 13/18] drop lockfile, use SIGKILL --- features/lockfile_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index defd18c0a..56cd385e4 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -2,16 +2,12 @@ around do |example| parent_pidfile = "/tmp/rmt-parent-#{Process.pid}.pid" - File.write('/tmp/rmt.lock', 'long_text_but_not_the_process_id') - `chown _rmt /tmp/rmt.lock` - fork { File.write(parent_pidfile, Process.pid) exec "/usr/bin/rmt-cli sync > /dev/null" } example.run - Process.kill('TERM', File.read(parent_pidfile).to_i) - FileUtils.rm('/tmp/rmt.lock', force: true) + Process.kill('KILL', File.read(parent_pidfile).to_i) end describe 'lockfile' do From 950822969b94ce1d0ee6f50ddbba806710dece1d Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 17:22:35 +0200 Subject: [PATCH 14/18] no pid file, no duplicate describe block names --- features/lockfile_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 56cd385e4..76ca1ed97 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -1,13 +1,10 @@ -describe 'rmt-cli' do +describe 'rmt-cli lock' do around do |example| - parent_pidfile = "/tmp/rmt-parent-#{Process.pid}.pid" - - fork { - File.write(parent_pidfile, Process.pid) + parent_pid = fork do exec "/usr/bin/rmt-cli sync > /dev/null" - } + end example.run - Process.kill('KILL', File.read(parent_pidfile).to_i) + Process.kill('KILL', parent_pid) end describe 'lockfile' do From 8425d5ca194c97d814b6525ffa8a294c55f69f8c Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 17:44:06 +0200 Subject: [PATCH 15/18] try with sigint --- features/lockfile_spec.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 76ca1ed97..148bb4d7a 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -1,13 +1,16 @@ -describe 'rmt-cli lock' do - around do |example| - parent_pid = fork do - exec "/usr/bin/rmt-cli sync > /dev/null" - end - example.run - Process.kill('KILL', parent_pid) - end +require File.expand_path('../support/command_rspec_helper', __FILE__) +describe 'rmt-cli' do describe 'lockfile' do + + around do |example| + parent_pid = fork do + exec "/usr/bin/rmt-cli sync > /dev/null" + end + example.run + Process.kill('INT', parent_pid) + end + command '/usr/bin/rmt-cli sync', allow_error: true its(:stderr) do is_expected.to eq( From 7cd3e0710c7c5b1f6c4c5ab614c5e97833854d36 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 17:58:43 +0200 Subject: [PATCH 16/18] release db lock --- features/lockfile_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 148bb4d7a..b4e76542e 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -8,7 +8,8 @@ exec "/usr/bin/rmt-cli sync > /dev/null" end example.run - Process.kill('INT', parent_pid) + Process.kill('KILL', parent_pid) + ActiveRecord::Base.connection.execute("SELECT RELEASE_LOCK('rmt-cli')") end command '/usr/bin/rmt-cli sync', allow_error: true From 3733124519cdda0b3af6096d99403b681c32c49a Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 20:51:38 +0200 Subject: [PATCH 17/18] call release_lock method --- features/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index b4e76542e..51dcc4883 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -9,7 +9,7 @@ end example.run Process.kill('KILL', parent_pid) - ActiveRecord::Base.connection.execute("SELECT RELEASE_LOCK('rmt-cli')") + RMT::Lockfile.send(:release_lock, 'rmt-cli') end command '/usr/bin/rmt-cli sync', allow_error: true From ca8e3845132b3b696b0b4ea0d178947ae3b8752f Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Tue, 2 Jul 2024 21:21:40 +0200 Subject: [PATCH 18/18] wait for the process to finish --- features/lockfile_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/lockfile_spec.rb b/features/lockfile_spec.rb index 51dcc4883..e33009680 100644 --- a/features/lockfile_spec.rb +++ b/features/lockfile_spec.rb @@ -8,8 +8,8 @@ exec "/usr/bin/rmt-cli sync > /dev/null" end example.run - Process.kill('KILL', parent_pid) - RMT::Lockfile.send(:release_lock, 'rmt-cli') + # wait for the parent process to finish, so the lock is released + Process.waitpid(parent_pid) end command '/usr/bin/rmt-cli sync', allow_error: true