From 30dd425ca92e70fb558ca28078533120332e01d2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 19 Feb 2020 23:33:41 +0000 Subject: [PATCH] Add test for trac cookbook --- .kitchen.yml | 3 +++ .travis.yml | 3 +++ cookbooks/trac/attributes/default.rb | 1 + cookbooks/trac/metadata.rb | 1 + cookbooks/trac/recipes/default.rb | 19 ++++++++++++++++- roles/trac.rb | 7 ------- test/data_bags/accounts/trac.json | 7 +++++++ .../trac/serverspec/apache_spec.rb | 21 +++++++++++++++++++ 8 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 cookbooks/trac/attributes/default.rb create mode 100644 test/data_bags/accounts/trac.json create mode 100644 test/integration/trac/serverspec/apache_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index ec4e81755..2e48b43d5 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -219,6 +219,9 @@ suites: - name: tools run_list: - recipe[tools::default] + - name: trac + run_list: + - recipe[trac::default] - name: web-backend run_list: - recipe[web::backend] diff --git a/.travis.yml b/.travis.yml index e5f5b0b23..4df85e104 100644 --- a/.travis.yml +++ b/.travis.yml @@ -163,6 +163,9 @@ jobs: - name: "Test Kitchen (tools)" script: - bundle exec kitchen test tools-ubuntu-1804 + - name: "Test Kitchen (trac)" + script: + - bundle exec kitchen test trac-ubuntu-1804 - name: "Test Kitchen (web::backend)" script: - bundle exec kitchen test web-backend-ubuntu-1804 diff --git a/cookbooks/trac/attributes/default.rb b/cookbooks/trac/attributes/default.rb new file mode 100644 index 000000000..1683a2a79 --- /dev/null +++ b/cookbooks/trac/attributes/default.rb @@ -0,0 +1 @@ +default[:accounts][:users][:trac][:status] = :role diff --git a/cookbooks/trac/metadata.rb b/cookbooks/trac/metadata.rb index 57fe9e358..4c308e1e1 100644 --- a/cookbooks/trac/metadata.rb +++ b/cookbooks/trac/metadata.rb @@ -6,4 +6,5 @@ description "Installs and configures trac servers" version "1.0.0" supports "ubuntu" +depends "accounts" depends "apache" diff --git a/cookbooks/trac/recipes/default.rb b/cookbooks/trac/recipes/default.rb index 8c397db8a..347b41b9b 100644 --- a/cookbooks/trac/recipes/default.rb +++ b/cookbooks/trac/recipes/default.rb @@ -17,17 +17,30 @@ # limitations under the License. # +include_recipe "accounts" include_recipe "apache" package %w[ trac - trac-git ruby ] site_name = "trac.openstreetmap.org" site_directory = "/srv/#{site_name}" +directory "/var/lib/trac" do + owner "trac" + group "trac" + mode 0o755 +end + +execute "trac-initenv-#{site_name}" do + command "trac-admin /var/lib/trac initenv #{site_name} sqlite:db/trac.db" + user "trac" + group "trac" + not_if { ::File.exist?("/var/lib/trac/VERSION") } +end + template "/var/lib/trac/conf/trac.ini" do source "trac.ini.erb" owner "trac" @@ -73,6 +86,10 @@ end apache_module "wsgi" +apache_module "authnz_external" do + package "libapache2-mod-authnz-external" +end + ssl_certificate "trac.openstreetmap.org" do domains ["trac.openstreetmap.org", "trac.osm.org"] notifies :reload, "service[apache2]" diff --git a/roles/trac.rb b/roles/trac.rb index 8f916ed13..9276c8895 100644 --- a/roles/trac.rb +++ b/roles/trac.rb @@ -1,13 +1,6 @@ name "trac" description "Role applied to all trac servers" -default_attributes( - :accounts => { - :users => { - :trac => { :status => :role } - } - } -) run_list( "recipe[trac]" ) diff --git a/test/data_bags/accounts/trac.json b/test/data_bags/accounts/trac.json new file mode 100644 index 000000000..9c89cb1cf --- /dev/null +++ b/test/data_bags/accounts/trac.json @@ -0,0 +1,7 @@ +{ + "id": "trac", + "uid": "509", + "comment": "trac.openstreetmap.org", + "home": "/var/lib/trac", + "manage_home": false +} diff --git a/test/integration/trac/serverspec/apache_spec.rb b/test/integration/trac/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/trac/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