From f4a5916362e9a37b07e63b7e222c54d7aaeab0a8 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 25 Jun 2020 19:32:50 +0000 Subject: [PATCH] Add test for dns cookbook --- .github/workflows/test-kitchen.yml | 1 + .kitchen.yml | 3 +++ cookbooks/dns/attributes/default.rb | 3 +++ cookbooks/dns/metadata.rb | 3 ++- cookbooks/dns/recipes/default.rb | 4 +++- roles/dns.rb | 6 ------ test/data_bags/dns/passwords.json | 7 +++++++ .../integration/dns/serverspec/apache_spec.rb | 21 +++++++++++++++++++ 8 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 cookbooks/dns/attributes/default.rb create mode 100644 test/data_bags/dns/passwords.json create mode 100644 test/integration/dns/serverspec/apache_spec.rb diff --git a/.github/workflows/test-kitchen.yml b/.github/workflows/test-kitchen.yml index fbe5238fe..61290de5f 100644 --- a/.github/workflows/test-kitchen.yml +++ b/.github/workflows/test-kitchen.yml @@ -25,6 +25,7 @@ jobs: - devices - dhcpd - dmca + - dns - docker - donate - elasticsearch diff --git a/.kitchen.yml b/.kitchen.yml index 133d124ee..17d9839f6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -93,6 +93,9 @@ suites: - name: dmca run_list: - recipe[dmca::default] + - name: dns + run_list: + - recipe[dns::default] - name: docker run_list: - recipe[docker::default] diff --git a/cookbooks/dns/attributes/default.rb b/cookbooks/dns/attributes/default.rb new file mode 100644 index 000000000..5bc8153d6 --- /dev/null +++ b/cookbooks/dns/attributes/default.rb @@ -0,0 +1,3 @@ +default[:dns][:repository] = "/var/lib/git/public/dns.git" + +default[:accounts][:users][:git][:status] = :role diff --git a/cookbooks/dns/metadata.rb b/cookbooks/dns/metadata.rb index ee177a46b..fb1120681 100644 --- a/cookbooks/dns/metadata.rb +++ b/cookbooks/dns/metadata.rb @@ -6,5 +6,6 @@ description "Configure DNS management" version "1.0.0" supports "ubuntu" -depends "git" +depends "accounts" depends "apache" +depends "git" diff --git a/cookbooks/dns/recipes/default.rb b/cookbooks/dns/recipes/default.rb index 2fbca1f24..4d21c21f7 100644 --- a/cookbooks/dns/recipes/default.rb +++ b/cookbooks/dns/recipes/default.rb @@ -17,8 +17,9 @@ # limitations under the License. # -include_recipe "git" +include_recipe "accounts" include_recipe "apache" +include_recipe "git" geoservers = search(:node, "roles:geodns").collect(&:name).sort @@ -132,6 +133,7 @@ cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do owner "git" group "git" mode 0o750 + only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") } end template "/usr/local/bin/dns-check" do diff --git a/roles/dns.rb b/roles/dns.rb index 25ac17f00..c2af27b58 100644 --- a/roles/dns.rb +++ b/roles/dns.rb @@ -1,12 +1,6 @@ name "dns" description "Role applied to DNS management servers" -default_attributes( - :dns => { - :repository => "/var/lib/git/public/dns.git" - } -) - run_list( "recipe[dns]" ) diff --git a/test/data_bags/dns/passwords.json b/test/data_bags/dns/passwords.json new file mode 100644 index 000000000..cd7b6c96c --- /dev/null +++ b/test/data_bags/dns/passwords.json @@ -0,0 +1,7 @@ +{ + "id": "passwords", + "rsync": "rsync", + "statuscake": "statuscake", + "gandi": "gandi", + "cloudflare": "cloudflare" +} diff --git a/test/integration/dns/serverspec/apache_spec.rb b/test/integration/dns/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/dns/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.39.5