From 4b7fea60a5990357d4e857437f11a401484bdddf Mon Sep 17 00:00:00 2001 From: Adnilson Date: Thu, 20 Jun 2024 12:15:59 +0100 Subject: [PATCH 01/15] 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/15] 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/15] 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 f4caebbe8c6a5b3897f8302f33c78d808ec797a2 Mon Sep 17 00:00:00 2001 From: Adnilson Date: Mon, 1 Jul 2024 13:38:59 +0100 Subject: [PATCH 04/15] =?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 05/15] 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 06/15] 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 07/15] 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 08/15] 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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 13/15] 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 14/15] 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 15/15] 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