Skip to content

Commit

Permalink
add check that /var/lib/pgsql and /var/lib/pgsql/data is on the same dev
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Dec 18, 2024
1 parent be2304c commit da5e16e
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
35 changes: 35 additions & 0 deletions definitions/checks/disk/postgresql_mountpoint.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions definitions/scenarios/foreman_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions definitions/scenarios/satellite_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions test/definitions/checks/disk/postgresql_mountpoint_test.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/definitions/scenarios/capsule_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::Repositories::Validate,
Checks::Pulpcore::NoRunningTasks,
Expand All @@ -53,6 +54,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::Repositories::Validate,
Checks::Pulpcore::NoRunningTasks,
Expand Down
2 changes: 2 additions & 0 deletions test/definitions/scenarios/foreman_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Checks::Foreman::CheckDuplicatePermissions,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::Repositories::Validate,
Checks::Pulpcore::NoRunningTasks,
)
Expand All @@ -45,6 +46,7 @@
Checks::Foreman::CheckDuplicatePermissions,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::Repositories::Validate,
Checks::Pulpcore::NoRunningTasks,
)
Expand Down
2 changes: 2 additions & 0 deletions test/definitions/scenarios/katello_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
Expand Down Expand Up @@ -72,6 +73,7 @@
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
Expand Down
2 changes: 2 additions & 0 deletions test/definitions/scenarios/satellite_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
Expand Down Expand Up @@ -122,6 +123,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::Disk::PostgresqlMountpoint,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
Expand Down

0 comments on commit da5e16e

Please sign in to comment.