From a48d3c6dbc350bfb430691dbc128ff06ad8f979a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 20 Feb 2020 21:47:45 +0000 Subject: [PATCH] Add test for tile cookbook --- .kitchen.yml | 3 +++ .travis.yml | 3 +++ cookbooks/tile/attributes/default.rb | 12 +++++++++++ cookbooks/tile/metadata.rb | 1 + cookbooks/tile/recipes/default.rb | 11 +++++++++- cookbooks/tile/templates/default/apache.erb | 4 ++-- .../tile/templates/default/replicate.erb | 19 +++++++++++------ roles/bowser.rb | 1 - roles/odin.rb | 1 - roles/pyrene.rb | 1 - roles/rhaegal.rb | 1 - roles/scorch.rb | 1 - roles/tile.rb | 5 ++++- roles/ysera.rb | 1 - test/data_bags/accounts/tile.json | 6 ++++++ test/data_bags/tile/blocks.json | 9 ++++++++ .../tile/serverspec/apache_spec.rb | 21 +++++++++++++++++++ 17 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 test/data_bags/accounts/tile.json create mode 100644 test/data_bags/tile/blocks.json create mode 100644 test/integration/tile/serverspec/apache_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index e91b64040..a1a674889 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -225,6 +225,9 @@ suites: taginfo: sites: - name: taginfo.example.com + - name: tile + run_list: + - recipe[tile::default] - name: tilecache run_list: - recipe[tilecache::default] diff --git a/.travis.yml b/.travis.yml index d699655dd..eac9850a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -169,6 +169,9 @@ jobs: - name: "Test Kitchen (taginfo)" script: - bundle exec kitchen test taginfo-ubuntu-1804 + - name: "Test Kitchen (tile)" + script: + - bundle exec kitchen test tile-ubuntu-1804 - name: "Test Kitchen (tilecache)" script: - bundle exec kitchen test tilecache-ubuntu-1804 diff --git a/cookbooks/tile/attributes/default.rb b/cookbooks/tile/attributes/default.rb index 7ef34a958..ae89aa8d6 100644 --- a/cookbooks/tile/attributes/default.rb +++ b/cookbooks/tile/attributes/default.rb @@ -1,2 +1,14 @@ +default[:tile][:database][:cluster] = "10/main" +default[:tile][:database][:postgis] = "2.4" +default[:tile][:database][:node_file] = "/store/database/nodes" +default[:tile][:database][:multi_geometry] = true +default[:tile][:database][:hstore] = true +default[:tile][:database][:style_file] = nil +default[:tile][:database][:tag_transform_script] = nil + default[:tile][:data] = {} default[:tile][:styles] = {} + +default[:postgresql][:versions] |= ["10"] + +default[:accounts][:users][:tile][:status] = :role diff --git a/cookbooks/tile/metadata.rb b/cookbooks/tile/metadata.rb index 716401065..0c44f9c6c 100644 --- a/cookbooks/tile/metadata.rb +++ b/cookbooks/tile/metadata.rb @@ -6,6 +6,7 @@ description "Installs and configures tile servers" version "1.0.0" supports "ubuntu" +depends "accounts" depends "apache" depends "git" depends "munin" diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index c1327d811..9aa99b934 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -17,6 +17,7 @@ # limitations under the License. # +include_recipe "accounts" include_recipe "apache" include_recipe "git" include_recipe "munin" @@ -394,6 +395,7 @@ end postgresql_extension "hstore" do cluster node[:tile][:database][:cluster] database "gis" + only_if { node[:tile][:database][:hstore] } end %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table| @@ -419,7 +421,14 @@ postgresql_munin "gis" do database "gis" end -file node[:tile][:node_file] do +directory File.dirname(node[:tile][:database][:node_file]) do + owner "root" + group "root" + mode 0o755 + recursive true +end + +file node[:tile][:database][:node_file] do owner "tile" group "www-data" mode 0o660 diff --git a/cookbooks/tile/templates/default/apache.erb b/cookbooks/tile/templates/default/apache.erb index e5d7f1719..182b590e5 100644 --- a/cookbooks/tile/templates/default/apache.erb +++ b/cookbooks/tile/templates/default/apache.erb @@ -12,8 +12,8 @@ # SSLEngine on SSLProxyEngine on - SSLCertificateFile /etc/ssl/certs/<%= node.name %>.pem - SSLCertificateKeyFile /etc/ssl/private/<%= node.name %>.key + SSLCertificateFile /etc/ssl/certs/<%= node[:fqdn] %>.pem + SSLCertificateKeyFile /etc/ssl/private/<%= node[:fqdn] %>.key # Configure location of static files and CGI scripts DocumentRoot /srv/tile.openstreetmap.org/html diff --git a/cookbooks/tile/templates/default/replicate.erb b/cookbooks/tile/templates/default/replicate.erb index 81fc66419..83fec6fb7 100644 --- a/cookbooks/tile/templates/default/replicate.erb +++ b/cookbooks/tile/templates/default/replicate.erb @@ -47,13 +47,20 @@ do # Apply the changes to the database osm2pgsql --database gis --slim --append --number-processes=1 \ -<% if node[:tile][:node_file] -%> - --flat-nodes=<%= node[:tile][:node_file] %> \ +<% if node[:tile][:database][:node_file] -%> + --flat-nodes=<%= node[:tile][:database][:node_file] %> \ <% end -%> -<% if node[:tile][:styles][:default][:revision] >= "v4.0.0" -%> - --multi-geometry --hstore \ - --style=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.style \ - --tag-transform-script=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.lua \ +<% if node[:tile][:database][:multi_geometry] -%> + --multi-geometry \ +<% end -%> +<% if node[:tile][:database][:hstore] -%> + --hstore \ +<% end -%> +<% if node[:tile][:database][:style_file] -%> + --style=<%= node[:tile][:database][:style_file] %> \ +<% end -%> +<% if node[:tile][:database][:tag_transform_script] -%> + --tag-transform-script=<%= node[:tile][:database][:tag_transform_script] %> \ <% end -%> ${file} diff --git a/roles/bowser.rb b/roles/bowser.rb index c7cda250a..7334805ff 100644 --- a/roles/bowser.rb +++ b/roles/bowser.rb @@ -41,7 +41,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/roles/odin.rb b/roles/odin.rb index 9b7975aaf..de22a363c 100644 --- a/roles/odin.rb +++ b/roles/odin.rb @@ -51,7 +51,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/roles/pyrene.rb b/roles/pyrene.rb index 9164524f0..f320526a8 100644 --- a/roles/pyrene.rb +++ b/roles/pyrene.rb @@ -50,7 +50,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/roles/rhaegal.rb b/roles/rhaegal.rb index ed44c2944..6ff245d85 100644 --- a/roles/rhaegal.rb +++ b/roles/rhaegal.rb @@ -67,7 +67,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/roles/scorch.rb b/roles/scorch.rb index 82c6eb573..a5c557474 100644 --- a/roles/scorch.rb +++ b/roles/scorch.rb @@ -64,7 +64,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/roles/tile.rb b/roles/tile.rb index 9061e2bce..8de66fff5 100644 --- a/roles/tile.rb +++ b/roles/tile.rb @@ -5,7 +5,6 @@ default_attributes( :accounts => { :users => { :tile => { - :status => :role, :members => [:jburgess, :tomh] } } @@ -67,6 +66,10 @@ default_attributes( } }, :tile => { + :database => { + :style_file => "/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.style", + :tag_transform_script => "/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.lua" + }, :data => { :simplified_land_polygons => { :url => "https://osmdata.openstreetmap.de/download/simplified-land-polygons-complete-3857.zip", diff --git a/roles/ysera.rb b/roles/ysera.rb index 8bc9d14c0..3e537b264 100644 --- a/roles/ysera.rb +++ b/roles/ysera.rb @@ -42,7 +42,6 @@ default_attributes( :cluster => "10/main", :postgis => "2.4" }, - :node_file => "/store/database/nodes", :styles => { :default => { :tile_directories => [ diff --git a/test/data_bags/accounts/tile.json b/test/data_bags/accounts/tile.json new file mode 100644 index 000000000..435cb15f9 --- /dev/null +++ b/test/data_bags/accounts/tile.json @@ -0,0 +1,6 @@ +{ + "id": "tile", + "uid": "515", + "comment": "tile.openstreetmap.org", + "home": "/srv/tile.openstreetmap.org" +} diff --git a/test/data_bags/tile/blocks.json b/test/data_bags/tile/blocks.json new file mode 100644 index 000000000..7088976d0 --- /dev/null +++ b/test/data_bags/tile/blocks.json @@ -0,0 +1,9 @@ +{ + "id": "blocks", + "user_agents": [ + "dummy" + ], + "referers": [ + "https://www.example.com/" + ] +} diff --git a/test/integration/tile/serverspec/apache_spec.rb b/test/integration/tile/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/tile/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 -- 2.43.2