From: Tom Hughes Date: Sun, 16 Feb 2020 15:37:45 +0000 (+0000) Subject: Add tests for web cookbook X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/9802985c84fa828a7a94ac5a7aafbd5b0f6e5a2c?hp=85bd960b218b23411744b080d3f2df4f55fdee27 Add tests for web cookbook --- diff --git a/.kitchen.yml b/.kitchen.yml index 4cff8942b..03549801f 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -175,3 +175,15 @@ suites: - name: tools run_list: - recipe[tools::default] + - name: web-backend + run_list: + - recipe[web::backend] + - name: web-cgimap + run_list: + - recipe[web::cgimap] + - name: web-frontend + run_list: + - recipe[web::frontend] + - name: web-rails + run_list: + - recipe[web::rails] diff --git a/.travis.yml b/.travis.yml index 5057de2f0..c822da4f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -120,3 +120,15 @@ jobs: - name: "Test Kitchen (tools)" script: - bundle exec kitchen test tools-ubuntu-1804 + - name: "Test Kitchen (web::backend)" + script: + - bundle exec kitchen test web-backend-ubuntu-1804 + - name: "Test Kitchen (web::cgimap)" + script: + - bundle exec kitchen test web-cgimap-ubuntu-1804 + - name: "Test Kitchen (web::frontend)" + script: + - bundle exec kitchen test web-frontend-ubuntu-1804 + - name: "Test Kitchen (web::rails)" + script: + - bundle exec kitchen test web-rails-ubuntu-1804 diff --git a/cookbooks/apt/attributes/default.rb b/cookbooks/apt/attributes/default.rb index f75ed9e34..a949a1c02 100644 --- a/cookbooks/apt/attributes/default.rb +++ b/cookbooks/apt/attributes/default.rb @@ -1,4 +1,3 @@ -default_unless[:apt][:sources] = [] - +default[:apt][:sources] = [ "openstreetmap" ] default[:apt][:unattended_upgrades][:enable] = true default[:apt][:unattended_upgrades][:remove_unused_dependencies] = true diff --git a/cookbooks/web/attributes/default.rb b/cookbooks/web/attributes/default.rb index 79890cbdb..7c995d9d8 100644 --- a/cookbooks/web/attributes/default.rb +++ b/cookbooks/web/attributes/default.rb @@ -1,4 +1,6 @@ default[:web][:base_directory] = "/srv/www.openstreetmap.org" -default[:web][:pid_directory] = "/var/run/web" +default[:web][:pid_directory] = "/run/web" default[:web][:log_directory] = "/var/log/web" default[:web][:primary_cluster] = false + +default[:accounts][:users][:rails][:status] = :role diff --git a/cookbooks/web/metadata.rb b/cookbooks/web/metadata.rb index 81096e2f1..89feed9a8 100644 --- a/cookbooks/web/metadata.rb +++ b/cookbooks/web/metadata.rb @@ -9,6 +9,7 @@ supports "ubuntu" depends "accounts" depends "apache" depends "apt" +depends "chef" depends "geoipupdate" depends "git" depends "memcached" diff --git a/cookbooks/web/recipes/base.rb b/cookbooks/web/recipes/base.rb index 00f77af6c..450b35138 100644 --- a/cookbooks/web/recipes/base.rb +++ b/cookbooks/web/recipes/base.rb @@ -22,6 +22,7 @@ node.default[:nfs]["/store/rails"] = { :path => "/store/rails" } +include_recipe "accounts" include_recipe "nfs" directory node[:web][:base_directory] do diff --git a/cookbooks/web/recipes/cgimap.rb b/cookbooks/web/recipes/cgimap.rb index 22d6d02f0..ba9799c4c 100644 --- a/cookbooks/web/recipes/cgimap.rb +++ b/cookbooks/web/recipes/cgimap.rb @@ -17,6 +17,7 @@ # limitations under the License. # +include_recipe "apt" include_recipe "tools" include_recipe "web::base" diff --git a/cookbooks/web/recipes/rails.rb b/cookbooks/web/recipes/rails.rb index c007d8e5d..79debaa69 100644 --- a/cookbooks/web/recipes/rails.rb +++ b/cookbooks/web/recipes/rails.rb @@ -17,15 +17,15 @@ # limitations under the License. # -include_recipe "tools" -include_recipe "web::base" - include_recipe "apache" -include_recipe "passenger" -include_recipe "geoipupdate" +include_recipe "apt" include_recipe "git" +include_recipe "geoipupdate" include_recipe "munin" include_recipe "nodejs" +include_recipe "passenger" +include_recipe "tools" +include_recipe "web::base" web_passwords = data_bag_item("web", "passwords") db_passwords = data_bag_item("db", "passwords") diff --git a/cookbooks/web/resources/rails_port.rb b/cookbooks/web/resources/rails_port.rb index 200f39514..3c8d9ae1e 100644 --- a/cookbooks/web/resources/rails_port.rb +++ b/cookbooks/web/resources/rails_port.rb @@ -79,6 +79,7 @@ action :create do imagemagick nodejs geoip-database + tzdata ] package %w[ diff --git a/cookbooks/web/templates/default/apache.frontend.erb b/cookbooks/web/templates/default/apache.frontend.erb index 4c283299b..d77ca4159 100644 --- a/cookbooks/web/templates/default/apache.frontend.erb +++ b/cookbooks/web/templates/default/apache.frontend.erb @@ -194,7 +194,7 @@ # ProxySet lbmethod=bybusyness -<% node[:web][:backends].each do |backend| -%> +<% Array(node[:web][:backends]).each do |backend| -%> BalancerMember https://<%= backend %> disablereuse=on <% end -%> diff --git a/roles/base.rb b/roles/base.rb index 771901def..f7a533251 100644 --- a/roles/base.rb +++ b/roles/base.rb @@ -10,9 +10,6 @@ default_attributes( :jburgess => { :status => :administrator } } }, - :apt => { - :sources => ["openstreetmap"] - }, :munin => { :plugins => { :chrony => { diff --git a/roles/web.rb b/roles/web.rb index 3276e43e4..85e4e9821 100644 --- a/roles/web.rb +++ b/roles/web.rb @@ -5,7 +5,6 @@ default_attributes( :accounts => { :users => { :rails => { - :status => :role, :members => [:tomh, :grant] } } diff --git a/test/data_bags/accounts/rails.json b/test/data_bags/accounts/rails.json new file mode 100644 index 000000000..564acef02 --- /dev/null +++ b/test/data_bags/accounts/rails.json @@ -0,0 +1,6 @@ +{ + "id": "rails", + "uid": "500", + "comment": "Rails", + "manage_home": false +} diff --git a/test/data_bags/geoipupdate/license-keys.json b/test/data_bags/geoipupdate/license-keys.json new file mode 100644 index 000000000..a53c128b0 --- /dev/null +++ b/test/data_bags/geoipupdate/license-keys.json @@ -0,0 +1,4 @@ +{ + "id": "license-keys", + "149244": "key" +} diff --git a/test/data_bags/web/passwords.json b/test/data_bags/web/passwords.json new file mode 100644 index 000000000..ad20fa1a1 --- /dev/null +++ b/test/data_bags/web/passwords.json @@ -0,0 +1,17 @@ +{ + "id": "passwords", + "secret_key_base": "base", + "potlatch2_key": "potlatch2", + "id_key": "id", + "oauth_key": "oauth", + "google_auth_secret": "google", + "facebook_auth_secret": "facebook", + "windowslive_auth_secret": "windowslive", + "github_auth_secret": "github", + "wikipedia_auth_secret": "wikipedia", + "mapquest_key": "mapquest", + "mapzen_valhalla_key": "mapzen-valhalla", + "thunderforest_key": "thunderforest", + "totp_key": "totp", + "aws_key": "aws" +} diff --git a/test/data_bags/web/piwik.json b/test/data_bags/web/piwik.json new file mode 100644 index 000000000..f9b73748a --- /dev/null +++ b/test/data_bags/web/piwik.json @@ -0,0 +1,12 @@ +{ + "id": "piwik", + "location": "piwik", + "site": 100, + "goals": { + "signup": 1001, + "mapnik": 1002, + "cyclemap": 1003, + "transportmap": 1004, + "mapquest": 1005 + } +} diff --git a/test/integration/web-backend/serverspec/apache_spec.rb b/test/integration/web-backend/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/web-backend/serverspec/apache_spec.rb @@ -0,0 +1,21 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("apache2") do + it { should be_installed } +end + +describe service("apache2") do + it { should be_enabled } + it { should be_running } +end + +describe port(80) do + it { should be_listening.with("tcp") } +end + +describe port(443) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/web-backend/serverspec/cgimap_spec.rb b/test/integration/web-backend/serverspec/cgimap_spec.rb new file mode 100644 index 000000000..d91e14576 --- /dev/null +++ b/test/integration/web-backend/serverspec/cgimap_spec.rb @@ -0,0 +1,13 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe service("cgimap") do + it { should be_enabled } + it { should be_running } +end + +describe port(8000) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/web-backend/serverspec/rails_spec.rb b/test/integration/web-backend/serverspec/rails_spec.rb new file mode 100644 index 000000000..478549a6e --- /dev/null +++ b/test/integration/web-backend/serverspec/rails_spec.rb @@ -0,0 +1,14 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe service("api-statistics") do + it { should be_enabled } + it { should be_running } +end + +describe service("rails-jobs@storage") do + it { should be_enabled } + it { should be_running } +end diff --git a/test/integration/web-cgimap/serverspec/cgimap_spec.rb b/test/integration/web-cgimap/serverspec/cgimap_spec.rb new file mode 100644 index 000000000..d91e14576 --- /dev/null +++ b/test/integration/web-cgimap/serverspec/cgimap_spec.rb @@ -0,0 +1,13 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe service("cgimap") do + it { should be_enabled } + it { should be_running } +end + +describe port(8000) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/web-frontend/serverspec/apache_spec.rb b/test/integration/web-frontend/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/web-frontend/serverspec/apache_spec.rb @@ -0,0 +1,21 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("apache2") do + it { should be_installed } +end + +describe service("apache2") do + it { should be_enabled } + it { should be_running } +end + +describe port(80) do + it { should be_listening.with("tcp") } +end + +describe port(443) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/web-frontend/serverspec/rails_spec.rb b/test/integration/web-frontend/serverspec/rails_spec.rb new file mode 100644 index 000000000..3c4c194cd --- /dev/null +++ b/test/integration/web-frontend/serverspec/rails_spec.rb @@ -0,0 +1,14 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe service("api-statistics") do + it { should be_enabled } + it { should be_running } +end + +describe service("rails-jobs@mailers") do + it { should be_enabled } + it { should be_running } +end diff --git a/test/integration/web-rails/serverspec/apache_spec.rb b/test/integration/web-rails/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/web-rails/serverspec/apache_spec.rb @@ -0,0 +1,21 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("apache2") do + it { should be_installed } +end + +describe service("apache2") do + it { should be_enabled } + it { should be_running } +end + +describe port(80) do + it { should be_listening.with("tcp") } +end + +describe port(443) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/web-rails/serverspec/rails_spec.rb b/test/integration/web-rails/serverspec/rails_spec.rb new file mode 100644 index 000000000..d02a65898 --- /dev/null +++ b/test/integration/web-rails/serverspec/rails_spec.rb @@ -0,0 +1,9 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe service("api-statistics") do + it { should be_enabled } + it { should be_running } +end