Skip to content

Commit

Permalink
Drop multiple database support
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl authored and mmoll committed Dec 19, 2019
1 parent 6420624 commit 10229dd
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 116 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ to configure Foreman's Smart Proxy and related services.

## Database support

This module supports configuration of either SQLite, PostgreSQL or MySQL as the
database for Foreman. The database type can be changed using the `db_type`
parameter, or management disabled with `db_manage`.

The default database is PostgreSQL, which will be fully installed and managed
on the host this module is applied to. Databases will be created with using the
`en_US.utf8` locale, which means a respective OS locale must be available on
the database host. If using MySQL, the puppetlabs-mysql module must be added to
the modulepath, otherwise it's not required.
the database host. The database management can be disabled with `db_manage`.

## Support policy

Expand Down
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ensure => directory,
}

if $::foreman::db_root_cert and $::foreman::db_type == 'postgresql' {
if $::foreman::db_root_cert {
$pg_cert_dir = "${::foreman::app_root}/.postgresql"

file { $pg_cert_dir:
Expand Down
6 changes: 2 additions & 4 deletions manifests/database.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Set up the foreman database
class foreman::database {
if $::foreman::db_manage {
$db_class = "foreman::database::${::foreman::db_type}"

contain $db_class
contain foreman::database::postgresql

if $::foreman::db_manage_rake {
Class[$db_class] ~> Foreman::Rake['db:migrate']
Class['foreman::database::postgresql'] ~> Foreman::Rake['db:migrate']
}
}

Expand Down
13 changes: 0 additions & 13 deletions manifests/database/mysql.pp

This file was deleted.

7 changes: 0 additions & 7 deletions manifests/database/sqlite.pp

This file was deleted.

18 changes: 1 addition & 17 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#
# $db_manage:: If enabled, will install and configure the database server on this host
#
# $db_type:: Database 'production' type
#
# $email_delivery_method:: Email delivery method
#
# $email_smtp_address:: SMTP server hostname, when delivery method is SMTP
Expand Down Expand Up @@ -79,8 +77,6 @@
# $plugin_version:: Foreman plugins package version, it's passed to ensure parameter of package resource
# can be set to 'installed', 'latest', 'present' only
#
# $db_adapter:: Database 'production' adapter
#
# $db_host:: Database 'production' host
#
# $db_port:: Database 'production' port
Expand Down Expand Up @@ -228,8 +224,6 @@
String $version = $::foreman::params::version,
Enum['installed', 'present', 'latest'] $plugin_version = $::foreman::params::plugin_version,
Boolean $db_manage = $::foreman::params::db_manage,
Enum['mysql', 'postgresql', 'sqlite'] $db_type = $::foreman::params::db_type,
Optional[Enum['mysql2', 'postgresql', 'sqlite3', 'UNSET']] $db_adapter = 'UNSET',
Optional[Stdlib::Host] $db_host = 'UNSET',
Variant[Undef, Enum['UNSET'], Stdlib::Port] $db_port = 'UNSET',
Optional[String] $db_database = 'UNSET',
Expand Down Expand Up @@ -308,17 +302,7 @@
Boolean $hsts_enabled = $::foreman::params::hsts_enabled,
Array[Stdlib::HTTPUrl] $cors_domains = $::foreman::params::cors_domains,
) inherits foreman::params {
if $db_adapter == 'UNSET' {
$db_adapter_real = $::foreman::db_type ? {
'sqlite' => 'sqlite3',
'mysql' => 'mysql2',
default => $::foreman::db_type,
}
} else {
$db_adapter_real = $db_adapter
}

if $db_sslmode == 'UNSET' and $db_root_cert and $db_type == 'postgresql' {
if $db_sslmode == 'UNSET' and $db_root_cert {
$db_sslmode_real = 'verify-full'
} else {
$db_sslmode_real = $db_sslmode
Expand Down
22 changes: 2 additions & 20 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
# Install the needed packages for foreman
class foreman::install {

case $::foreman::db_type {
'sqlite': {
case $::osfamily {
'Debian': { $package = 'foreman-sqlite3' }
default: { $package = 'foreman-sqlite' }
}
}
'postgresql': {
$package = 'foreman-postgresql'
}
'mysql': {
$package = 'foreman-mysql2'
}
default: {
fail("${::hostname}: unknown database type ${::foreman::db_type}")
}
}

package { $package:
ensure => $::foreman::version,
package { 'foreman-postgresql':
ensure => $::foreman::version,
}

if $::foreman::selinux or (str2bool($::selinux) and $::foreman::selinux != false) {
Expand Down
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
# if enabled, will install and configure the database server on this host
$db_manage = true
# Database 'production' settings
$db_type = 'postgresql'
$db_username = 'foreman'
# Generate and cache the password on the master once
# In multi-puppetmaster setups, the user should specify their own
Expand Down
35 changes: 0 additions & 35 deletions spec/classes/foreman_database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,6 @@
)
end
end

describe 'with db_type => mysql' do
let(:params) { super().merge(db_type: 'mysql') }
# install
it { should contain_package('foreman-mysql2') }

# config
it { should contain_file('/etc/foreman/database.yml').with_content(/adapter: mysql2/) }

# database
it { should_not contain_class('foreman::database::postgresql') }
it { should_not contain_class('foreman::database::sqlite') }
it { should contain_class('foreman::database::mysql') }
it { should contain_class('mysql::server') }
it { should contain_class('mysql::server::account_security') }
it { should contain_mysql__db('foreman').with_user('foreman') }
end

describe 'with db_type => sqlite' do
let(:params) { super().merge(db_type: 'sqlite') }
# install
case facts[:osfamily]
when 'RedHat'
it { should contain_package('foreman-sqlite') }
when 'Debian'
it { should contain_package('foreman-sqlite3') }
end

# config
it { should contain_file('/etc/foreman/database.yml').with_content(/adapter: sqlite/) }

# database
it { should_not contain_class('foreman::database::postgresql') }
it { should_not contain_class('foreman::database::mysql') }
end
end
end
end
3 changes: 0 additions & 3 deletions spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@

# database
it { should contain_class('foreman::database') }
it { should_not contain_class('foreman::database::mysql') }
it {
should contain_class('foreman::database::postgresql')
.that_notifies('Foreman::Rake[db:migrate]')
Expand Down Expand Up @@ -206,8 +205,6 @@ class {'apache':
version: '1.12',
plugin_version: 'installed',
db_manage: true,
db_type: 'postgresql',
db_adapter: 'UNSET',
db_host: 'UNSET',
db_port: 'UNSET',
db_database: 'UNSET',
Expand Down
12 changes: 3 additions & 9 deletions templates/database.yml.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%>

<%
type = scope.lookupvar("::foreman::db_type")
adapter = scope.lookupvar("::foreman::db_adapter_real")
host = scope.lookupvar("::foreman::db_host")
host = scope.lookupvar("::fqdn") if type == 'mysql' && adapter == 'UNSET'
database = scope.lookupvar("::foreman::db_database")
database = (type == 'sqlite') ? 'db/production.sqlite3' : 'foreman' if database == 'UNSET'
database = 'foreman' if database == 'UNSET'
rails_env = scope.lookupvar("::foreman::rails_env")
-%>
<% unless scope.lookupvar("::foreman::db_manage") == 'UNSET' -%>
# Database is managed by foreman::database::<%= type %>
# Database is managed by foreman::database::postgresql
<% end -%>
<%= rails_env %>:
adapter: <%= adapter %>
adapter: postgresql
<% unless host == 'UNSET' -%>
host: <%= host %>
<% end -%>
Expand All @@ -33,6 +30,3 @@
<% unless (pool = scope.lookupvar("::foreman::db_pool")) == 'UNSET' -%>
pool: <%= pool %>
<% end -%>
<% if type == 'sqlite' -%>
timeout: 5000
<% end -%>

0 comments on commit 10229dd

Please sign in to comment.