From ae7c3c728ad4b1a4a1c71715a43e1f0d44a5289b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 23 Feb 2020 22:12:00 +0000 Subject: [PATCH] Add tests for db cookbook --- .github/workflows/test-kitchen.yml | 4 ++++ .kitchen.yml | 12 ++++++++++++ cookbooks/db/attributes/default.rb | 3 +++ cookbooks/db/metadata.rb | 5 +++-- cookbooks/db/recipes/base.rb | 16 +++++++++------- roles/db-master.rb | 1 - roles/db-slave.rb | 1 - roles/db.rb | 1 - roles/eddie.rb | 3 --- roles/karm.rb | 3 --- roles/katla.rb | 3 --- test/data_bags/db/wal-secrets.json | 4 ++++ 12 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 cookbooks/db/attributes/default.rb create mode 100644 test/data_bags/db/wal-secrets.json diff --git a/.github/workflows/test-kitchen.yml b/.github/workflows/test-kitchen.yml index 6646f28d0..086850543 100644 --- a/.github/workflows/test-kitchen.yml +++ b/.github/workflows/test-kitchen.yml @@ -18,6 +18,10 @@ jobs: - blogs - civicrm - clamav + - db-backup + - db-base + - db-master + - db-slave - devices - dhcpd - dmca diff --git a/.kitchen.yml b/.kitchen.yml index babf14107..c136565f1 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -54,6 +54,18 @@ suites: - name: clamav run_list: - recipe[clamav::default] + - name: db-backup + run_list: + - recipe[db::backup] + - name: db-base + run_list: + - recipe[db::base] + - name: db-master + run_list: + - recipe[db::master] + - name: db-slave + run_list: + - recipe[db::slave] - name: devices run_list: - recipe[devices::default] diff --git a/cookbooks/db/attributes/default.rb b/cookbooks/db/attributes/default.rb new file mode 100644 index 000000000..1b674e3ad --- /dev/null +++ b/cookbooks/db/attributes/default.rb @@ -0,0 +1,3 @@ +default[:db][:cluster] = "9.5/main" + +default[:postgresql][:versions] |= ["9.5"] diff --git a/cookbooks/db/metadata.rb b/cookbooks/db/metadata.rb index 092949cb0..aadfe47db 100644 --- a/cookbooks/db/metadata.rb +++ b/cookbooks/db/metadata.rb @@ -6,7 +6,8 @@ description "Installs and configures database servers" version "1.0.0" supports "ubuntu" -depends "postgresql" -depends "web" +depends "accounts" depends "git" +depends "postgresql" depends "python" +depends "web" diff --git a/cookbooks/db/recipes/base.rb b/cookbooks/db/recipes/base.rb index ee9d0089f..f92a6ea0b 100644 --- a/cookbooks/db/recipes/base.rb +++ b/cookbooks/db/recipes/base.rb @@ -17,13 +17,19 @@ # limitations under the License. # -include_recipe "postgresql" +include_recipe "accounts" include_recipe "git" +include_recipe "postgresql" include_recipe "python" passwords = data_bag_item("db", "passwords") wal_secrets = data_bag_item("db", "wal-secrets") +ruby_version = node[:passenger][:ruby_version] +db_version = node[:db][:cluster].split("/").first +pg_config = "/usr/lib/postgresql/#{db_version}/bin/pg_config" +function_directory = "/srv/www.openstreetmap.org/rails/db/functions/#{db_version}" + postgresql_munin "openstreetmap" do cluster node[:db][:cluster] database "openstreetmap" @@ -35,7 +41,7 @@ directory "/srv/www.openstreetmap.org" do end rails_port "www.openstreetmap.org" do - ruby "2.5" + ruby ruby_version directory "/srv/www.openstreetmap.org/rails" user "rails" group "rails" @@ -48,10 +54,6 @@ rails_port "www.openstreetmap.org" do gpx_dir "/store/rails/gpx" end -db_version = node[:db][:cluster].split("/").first -pg_config = "/usr/lib/postgresql/#{db_version}/bin/pg_config" -function_directory = "/srv/www.openstreetmap.org/rails/db/functions/#{db_version}" - directory function_directory do owner "rails" group "rails" @@ -60,7 +62,7 @@ end execute function_directory do action :nothing - command "make PG_CONFIG=#{pg_config} DESTDIR=#{function_directory}" + command "make BUNDLE=bundle#{ruby_version} PG_CONFIG=#{pg_config} DESTDIR=#{function_directory}" cwd "/srv/www.openstreetmap.org/rails/db/functions" user "rails" group "rails" diff --git a/roles/db-master.rb b/roles/db-master.rb index 3bfdbd7ca..19f9d55d9 100644 --- a/roles/db-master.rb +++ b/roles/db-master.rb @@ -3,7 +3,6 @@ description "Role applied to all the master database server" default_attributes( :postgresql => { - :versions => ["9.5"], :settings => { :defaults => { :wal_level => "hot_standby", diff --git a/roles/db-slave.rb b/roles/db-slave.rb index 5b5c09b33..30c4a79bf 100644 --- a/roles/db-slave.rb +++ b/roles/db-slave.rb @@ -3,7 +3,6 @@ description "Role applied to all slave database servers" default_attributes( :postgresql => { - :versions => ["9.5"], :settings => { :defaults => { :hot_standby => "on", diff --git a/roles/db.rb b/roles/db.rb index bb13e00c5..c4bd4cfa4 100644 --- a/roles/db.rb +++ b/roles/db.rb @@ -39,7 +39,6 @@ default_attributes( "/store/rails" => { :host => "ironbelly", :path => "/store/rails" } }, :postgresql => { - :versions => ["9.5"], :settings => { :defaults => { :listen_addresses => "*", diff --git a/roles/eddie.rb b/roles/eddie.rb index c96483527..0dbe9dd0a 100644 --- a/roles/eddie.rb +++ b/roles/eddie.rb @@ -2,9 +2,6 @@ name "eddie" description "Master role applied to eddie" default_attributes( - :db => { - :cluster => "9.5/main" - }, :networking => { :interfaces => { :internal_ipv4 => { diff --git a/roles/karm.rb b/roles/karm.rb index a8f6b9e29..ab1470756 100644 --- a/roles/karm.rb +++ b/roles/karm.rb @@ -2,9 +2,6 @@ name "karm" description "Master role applied to karm" default_attributes( - :db => { - :cluster => "9.5/main" - }, :networking => { :interfaces => { :internal_ipv4 => { diff --git a/roles/katla.rb b/roles/katla.rb index 6f5376f08..6143cf533 100644 --- a/roles/katla.rb +++ b/roles/katla.rb @@ -2,9 +2,6 @@ name "katla" description "Master role applied to katla" default_attributes( - :db => { - :cluster => "9.5/main" - }, :devices => { :store_slow => { :comment => "RAID array mounted on /store/arrays/slow", diff --git a/test/data_bags/db/wal-secrets.json b/test/data_bags/db/wal-secrets.json new file mode 100644 index 000000000..6f558f217 --- /dev/null +++ b/test/data_bags/db/wal-secrets.json @@ -0,0 +1,4 @@ +{ + "id": "wal-secrets", + "s3_key": "s3-key" +} -- 2.39.5