From 46302a0af8d73ae6cabcf5fd52400b13d89ec94a Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 18 Dec 2024 13:19:36 +0100 Subject: [PATCH] add check that /var/lib/pgsql and /var/lib/pgsql/data is on the same dev --- .../checks/disk/postgresql_mountpoint.rb | 35 +++++++++++++++++ definitions/scenarios/foreman_upgrade.rb | 1 + definitions/scenarios/satellite_upgrade.rb | 1 + .../checks/disk/postgresql_mountpoint_test.rb | 38 +++++++++++++++++++ .../scenarios/capsule_upgrade_test.rb | 2 + .../scenarios/foreman_upgrade_test.rb | 2 + .../scenarios/katello_upgrade_test.rb | 2 + .../scenarios/satellite_upgrade_test.rb | 2 + 8 files changed, 83 insertions(+) create mode 100644 definitions/checks/disk/postgresql_mountpoint.rb create mode 100644 test/definitions/checks/disk/postgresql_mountpoint_test.rb diff --git a/definitions/checks/disk/postgresql_mountpoint.rb b/definitions/checks/disk/postgresql_mountpoint.rb new file mode 100644 index 000000000..bf91f1432 --- /dev/null +++ b/definitions/checks/disk/postgresql_mountpoint.rb @@ -0,0 +1,35 @@ +module Checks + module Disk + class PostgresqlMountpoint < ForemanMaintain::Check + metadata do + label :postgresql_mountpoint + description 'Check to make sure PostgreSQL data is not on an own mountpoint' + confine do + feature(:instance).postgresql_local? && ForemanMaintain.el? + end + end + + def run + assert(psql_dir_device == psql_data_dir_device, warning_message) + end + + def psql_dir_device + device = ForemanMaintain::Utils::Disk::Device.new('/var/lib/pgsql') + device.name + end + + def psql_data_dir_device + device = ForemanMaintain::Utils::Disk::Device.new('/var/lib/pgsql/data') + device.name + end + + def warning_message + <<~MSG + PostgreSQL data (/var/lib/pgsql/data) is on a different device than /var/lib/pgsql. + This is not supported and breaks PostgreSQL upgrades. + Please ensure PostgreSQL data is on the same mountpoint as the /var/lib/pgsql. + MSG + end + end + end +end diff --git a/definitions/scenarios/foreman_upgrade.rb b/definitions/scenarios/foreman_upgrade.rb index c0638505f..d8abef9e0 100644 --- a/definitions/scenarios/foreman_upgrade.rb +++ b/definitions/scenarios/foreman_upgrade.rb @@ -39,6 +39,7 @@ def compose Checks::Disk::AvailableSpace, Checks::Disk::AvailableSpaceCandlepin, # if candlepin Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::Foreman::ValidateExternalDbVersion, # if external database Checks::Foreman::CheckExternalDbEvrPermissions, # if external database Checks::Foreman::CheckCorruptedRoles, diff --git a/definitions/scenarios/satellite_upgrade.rb b/definitions/scenarios/satellite_upgrade.rb index 0735762b6..5fbe5523b 100644 --- a/definitions/scenarios/satellite_upgrade.rb +++ b/definitions/scenarios/satellite_upgrade.rb @@ -38,6 +38,7 @@ def compose Checks::CheckUpstreamRepository, Checks::Disk::AvailableSpace, Checks::Disk::AvailableSpaceCandlepin, # if candlepin + Checks::Disk::PostgresqlMountpoint, Checks::Foreman::ValidateExternalDbVersion, # if external database Checks::Foreman::CheckExternalDbEvrPermissions, # if external database Checks::Foreman::CheckCorruptedRoles, diff --git a/test/definitions/checks/disk/postgresql_mountpoint_test.rb b/test/definitions/checks/disk/postgresql_mountpoint_test.rb new file mode 100644 index 000000000..1ea75e5b6 --- /dev/null +++ b/test/definitions/checks/disk/postgresql_mountpoint_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' +describe Checks::Disk::PostgresqlMountpoint do + include DefinitionsTestHelper + include UnitTestHelper + + let(:check) { described_class.new } + + before do + assume_feature_present(:instance) do |feature| + feature.any_instance.stubs(:postgresql_local?).returns(true) + end + ForemanMaintain.stubs(:el?).returns(true) + end + + it 'executes successfully for data on same disks' do + check.stubs(:psql_dir_device).returns('/dev/mapper/foreman-postgresql') + check.stubs(:psql_data_dir_device).returns('/dev/mapper/foreman-postgresql') + + step = run_step(check) + assert_empty(step.output) + assert_equal(:success, step.status) + end + + it 'prints warnings for data on separate disk' do + check.stubs(:psql_dir_device).returns('/dev/mapper/foreman-root') + check.stubs(:psql_data_dir_device).returns('/dev/mapper/foreman-postgresql') + + step = run_step(check) + + warning = <<~MSG + PostgreSQL data (/var/lib/pgsql/data) is on a different device than /var/lib/pgsql. + This is not supported and breaks PostgreSQL upgrades. + Please ensure PostgreSQL data is on the same mountpoint as the /var/lib/pgsql. + MSG + assert_equal(warning, step.output) + assert_equal(:fail, step.status) + end +end diff --git a/test/definitions/scenarios/capsule_upgrade_test.rb b/test/definitions/scenarios/capsule_upgrade_test.rb index b1854caf0..e28a2370b 100644 --- a/test/definitions/scenarios/capsule_upgrade_test.rb +++ b/test/definitions/scenarios/capsule_upgrade_test.rb @@ -30,6 +30,7 @@ Checks::Repositories::CheckNonRhRepository, Checks::CheckIpv6Disable, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::Repositories::Validate, Checks::Pulpcore::NoRunningTasks, @@ -53,6 +54,7 @@ Checks::Repositories::CheckNonRhRepository, Checks::CheckIpv6Disable, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::Repositories::Validate, Checks::Pulpcore::NoRunningTasks, diff --git a/test/definitions/scenarios/foreman_upgrade_test.rb b/test/definitions/scenarios/foreman_upgrade_test.rb index 9cc0f33d8..c02e38151 100644 --- a/test/definitions/scenarios/foreman_upgrade_test.rb +++ b/test/definitions/scenarios/foreman_upgrade_test.rb @@ -26,6 +26,7 @@ Checks::Foreman::CheckDuplicatePermissions, Checks::PackageManager::Dnf::ValidateDnfConfig, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::Repositories::Validate, Checks::Pulpcore::NoRunningTasks, ) @@ -45,6 +46,7 @@ Checks::Foreman::CheckDuplicatePermissions, Checks::PackageManager::Dnf::ValidateDnfConfig, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::Repositories::Validate, Checks::Pulpcore::NoRunningTasks, ) diff --git a/test/definitions/scenarios/katello_upgrade_test.rb b/test/definitions/scenarios/katello_upgrade_test.rb index 0cb1a38e6..163e5005d 100644 --- a/test/definitions/scenarios/katello_upgrade_test.rb +++ b/test/definitions/scenarios/katello_upgrade_test.rb @@ -39,6 +39,7 @@ Checks::PackageManager::Dnf::ValidateDnfConfig, Checks::Repositories::CheckNonRhRepository, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::CheckSha1CertificateAuthority, Checks::Repositories::Validate, @@ -72,6 +73,7 @@ Checks::PackageManager::Dnf::ValidateDnfConfig, Checks::Repositories::CheckNonRhRepository, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::CheckSha1CertificateAuthority, Checks::Repositories::Validate, diff --git a/test/definitions/scenarios/satellite_upgrade_test.rb b/test/definitions/scenarios/satellite_upgrade_test.rb index bca956826..4b24e7fe2 100644 --- a/test/definitions/scenarios/satellite_upgrade_test.rb +++ b/test/definitions/scenarios/satellite_upgrade_test.rb @@ -88,6 +88,7 @@ Checks::Repositories::CheckNonRhRepository, Checks::CheckIpv6Disable, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::CheckSha1CertificateAuthority, Checks::Repositories::Validate, @@ -122,6 +123,7 @@ Checks::Repositories::CheckNonRhRepository, Checks::CheckIpv6Disable, Checks::Disk::AvailableSpacePostgresql13, + Checks::Disk::PostgresqlMountpoint, Checks::CheckOrganizationContentAccessMode, Checks::CheckSha1CertificateAuthority, Checks::Repositories::Validate,