Skip to content

Commit fb56093

Browse files
committed
Refactor DBUps into subclasses
1 parent c8fe3c2 commit fb56093

6 files changed

Lines changed: 71 additions & 69 deletions

File tree

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1+
require_relative '../db_up_check'
2+
13
module Checks
24
module Candlepin
3-
class DBUp < ForemanMaintain::Check
5+
class DBUp < DBUpCheck
46
metadata do
57
description 'Make sure Candlepin DB is up'
68
label :candlepin_db_up
79
for_feature :candlepin_database
810
end
911

10-
def run
11-
status = false
12-
if feature(:candlepin_database).psql_cmd_available?
13-
with_spinner('Checking connection to the Candlepin DB') do
14-
status = feature(:candlepin_database).ping
15-
end
16-
assert(status, 'Candlepin DB is not responding. ' \
17-
'It needs to be up and running to perform the following steps',
18-
:next_steps => start_pgsql)
19-
else
20-
feature(:candlepin_database).raise_psql_missing_error
21-
end
12+
def database_feature
13+
:candlepin_database
2214
end
2315

24-
def start_pgsql
25-
if feature(:candlepin_database).local?
26-
[Procedures::Service::Start.new(:only => 'postgresql')]
27-
else
28-
[] # there is nothing we can do for remote db
29-
end
16+
def database_name
17+
'Candlepin'
3018
end
3119
end
3220
end
3321
end
22+

definitions/checks/container_gateway/db_up.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1+
require_relative '../db_up_check'
2+
13
module Checks
24
module ContainerGateway
3-
class DBUp < ForemanMaintain::Check
5+
class DBUp < DBUpCheck
46
metadata do
57
description 'Make sure ContainerGateway DB is up'
68
label :container_gateway_db_up
79
for_feature :container_gateway_database
810
end
911

10-
def run
11-
status = false
12-
with_spinner('Checking connection to the Container Gateway DB') do
13-
status = feature(:container_gateway_database).ping
14-
end
15-
assert(status, 'Container Gateway DB is not responding. ' \
16-
'It needs to be up and running to perform the following steps',
17-
:next_steps => next_steps)
12+
def database_feature
13+
:container_gateway_database
1814
end
1915

20-
def next_steps
21-
if feature(:container_gateway_database).local?
22-
[Procedures::Service::Start.new(:only => 'postgresql')]
23-
else
24-
[] # there is nothing we can do for remote db
25-
end
16+
def database_name
17+
'Container Gateway'
2618
end
2719
end
2820
end

definitions/checks/db_up_check.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Checks
2+
class DBUpCheck < ForemanMaintain::Check
3+
def run
4+
status = false
5+
if feature(database_feature).psql_cmd_available?
6+
with_spinner("Checking connection to the #{database_name} DB") do
7+
status = feature(database_feature).ping
8+
end
9+
assert(status, "#{database_name} DB is not responding. " \
10+
"It needs to be up and running to perform the following steps",
11+
:next_steps => start_pgsql)
12+
else
13+
feature(database_feature).raise_psql_missing_error
14+
end
15+
end
16+
17+
def start_pgsql
18+
if feature(database_feature).local?
19+
[Procedures::Service::Start.new(:only => 'postgresql')]
20+
else
21+
[] # there is nothing we can do for remote db
22+
end
23+
end
24+
25+
def database_feature
26+
raise NotImplementedError, 'Subclasses must define `database_feature`'
27+
end
28+
29+
def database_name
30+
raise NotImplementedError, 'Subclasses must define `database_name`'
31+
end
32+
end
33+
end
34+
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1+
require_relative '../db_up_check'
2+
13
module Checks
24
module Foreman
3-
class DBUp < ForemanMaintain::Check
5+
class DBUp < DBUpCheck
46
metadata do
57
description 'Make sure Foreman DB is up'
68
label :foreman_db_up
79
for_feature :foreman_database
810
end
911

10-
def run
11-
status = false
12-
if feature(:foreman_database).psql_cmd_available?
13-
with_spinner('Checking connection to the Foreman DB') do
14-
status = feature(:foreman_database).ping
15-
end
16-
assert(status, 'Foreman DB is not responding. ' \
17-
'It needs to be up and running to perform the following steps',
18-
:next_steps => start_pgsql)
19-
else
20-
feature(:foreman_database).raise_psql_missing_error
21-
end
12+
def database_feature
13+
:foreman_database
2214
end
2315

24-
def start_pgsql
25-
if feature(:foreman_database).local?
26-
[Procedures::Service::Start.new(:only => 'postgresql')]
27-
else
28-
[] # there is nothing we can do for remote db
29-
end
16+
def database_name
17+
'Foreman'
3018
end
3119
end
3220
end
3321
end
22+
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1+
require_relative '../db_up_check'
2+
13
module Checks
24
module Pulpcore
3-
class DBUp < ForemanMaintain::Check
5+
class DBUp < DBUpCheck
46
metadata do
57
description 'Make sure Pulpcore DB is up'
68
label :pulpcore_db_up
79
for_feature :pulpcore_database
810
end
911

10-
def run
11-
status = false
12-
with_spinner('Checking connection to the Pulpcore DB') do
13-
status = feature(:pulpcore_database).ping
14-
end
15-
assert(status, 'Pulpcore DB is not responding. ' \
16-
'It needs to be up and running to perform the following steps',
17-
:next_steps => next_steps)
12+
def database_feature
13+
:pulpcore_database
1814
end
1915

20-
def next_steps
21-
if feature(:pulpcore_database).local?
22-
[Procedures::Service::Start.new(:only => 'postgresql')]
23-
else
24-
[] # there is nothing we can do for remote db
25-
end
16+
def database_name
17+
'Pulpcore'
2618
end
2719
end
2820
end
2921
end
22+

definitions/procedures/restore/extract_files.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def extract_pulp_data(backup)
4949
end
5050

5151
def any_database
52-
feature(:foreman_database) || feature(:candlepin_database) || feature(:pulpcore_database) || feature(:container_gateway_database)
52+
%i[
53+
foreman_database
54+
candlepin_database
55+
pulpcore_database
56+
container_gateway_database
57+
].any? { |db| feature(db) }
5358
end
5459

5560
def extract_pgsql_data(backup)

0 commit comments

Comments
 (0)