From a995b715c892199ab15096cf88a0359e441737c5 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Fri, 16 Sep 2016 12:25:21 -0700 Subject: [PATCH 1/3] Added integration tests for Windows --- .kitchen.yml | 7 + test/fixtures/policies/_base.rb | 6 +- .../default/serverspec/default_spec.rb | 144 +++++++++--------- .../default/serverspec/windows_spec.rb | 53 +++++++ .../helpers/serverspec/spec_helper.rb | 7 +- 5 files changed, 142 insertions(+), 75 deletions(-) create mode 100644 test/integration/default/serverspec/windows_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index 164cab4b..10a19d16 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -26,6 +26,13 @@ platforms: named_run_list: freebsd - name: windows-2012r2 named_run_list: windows + driver_config: + network: + - ["forwarded_port", {guest: 3389, host: 3389}] + - ["forwarded_port", {guest: 5985, host: 5985}] + communicator: winrm + customize: + usbehci: "off" suites: - name: default diff --git a/test/fixtures/policies/_base.rb b/test/fixtures/policies/_base.rb index 790336d4..599ba424 100644 --- a/test/fixtures/policies/_base.rb +++ b/test/fixtures/policies/_base.rb @@ -1,8 +1,8 @@ default_source :community default_source :chef_repo, '..' cookbook 'consul', path: '../../..' -run_list 'sudo::default', 'consul::default', "consul_spec::#{name}" -named_run_list :centos, 'yum::default', 'yum-centos::default', run_list +run_list 'consul::default', "consul_spec::#{name}" +named_run_list :centos, 'yum::default', 'yum-centos::default',run_list named_run_list :debian, 'apt::default', run_list -named_run_list :freebsd, 'freebsd::default', run_list +named_run_list :freebsd, 'freebsd::default', 'sudo::default', run_list named_run_list :windows, 'windows::default', run_list diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index c735eade..05b6fbc6 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -1,95 +1,97 @@ require 'spec_helper' -consul_version = '0.6.4' -consul_executable = "/opt/consul/#{consul_version}/consul" +unless windows? + consul_version = '0.6.4' + consul_executable = "/opt/consul/#{consul_version}/consul" -describe file(consul_executable) do - it { should be_file } - it { should be_executable } -end + describe file(consul_executable) do + it { should be_file } + it { should be_executable } + end -describe group('consul') do - it { should exist } -end + describe group('consul') do + it { should exist } + end -describe user('consul') do - it { should exist } - it { should belong_to_group('consul') } -end + describe user('consul') do + it { should exist } + it { should belong_to_group('consul') } + end -describe command("su - consul -c 'echo successfully logged in'") do - its(:stdout) { should_not match /successfully logged in/ } - its(:exit_status) { should_not eq 0 } -end + describe command("su - consul -c 'echo successfully logged in'") do + its(:stdout) { should_not match /successfully logged in/ } + its(:exit_status) { should_not eq 0 } + end -describe service('consul') do - it { should be_enabled } - it { should be_running } -end + describe service('consul') do + it { should be_enabled } + it { should be_running } + end -[8300, 8400, 8500, 8600].each do |p| - describe port(p) do - it { should be_listening } + [8300, 8400, 8500, 8600].each do |p| + describe port(p) do + it { should be_listening } + end end -end -describe command('/opt/consul/0.6.4/consul members -detailed') do - its(:exit_status) { should eq 0 } - its(:stdout) { should match %r{\balive\b} } - its(:stdout) { should match %r{\brole=consul\b} } - its(:stdout) { should match %r{\bbootstrap=1\b} } - its(:stdout) { should match %r{\bdc=fortmeade\b} } -end + describe command('/opt/consul/0.6.4/consul members -detailed') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match %r{\balive\b} } + its(:stdout) { should match %r{\brole=consul\b} } + its(:stdout) { should match %r{\bbootstrap=1\b} } + its(:stdout) { should match %r{\bdc=fortmeade\b} } + end -config_dir = '/etc/consul' -config_file = '/etc/consul/consul.json' -confd_dir = '/etc/consul/conf.d' -data_dir = '/var/lib/consul' + config_dir = '/etc/consul' + config_file = '/etc/consul/consul.json' + confd_dir = '/etc/consul/conf.d' + data_dir = '/var/lib/consul' -describe file(config_dir) do - it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'consul' } + describe file(config_dir) do + it { should be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'consul' } - it { should be_mode 755 } -end + it { should be_mode 755 } + end -describe file(config_file) do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'consul' } + describe file(config_file) do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'consul' } - it { should be_mode 640 } -end + it { should be_mode 640 } + end -describe file(confd_dir) do - it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'consul' } + describe file(confd_dir) do + it { should be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'consul' } - it { should be_mode 755 } -end + it { should be_mode 755 } + end -describe file(data_dir) do - it { should be_directory } - it { should be_owned_by 'consul' } - it { should be_grouped_into 'consul' } + describe file(data_dir) do + it { should be_directory } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } - it { should be_mode 750 } -end + it { should be_mode 750 } + end -describe file("#{confd_dir}/consul_definition_check.json") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'consul' } + describe file("#{confd_dir}/consul_definition_check.json") do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'consul' } - it { should be_mode 640 } -end + it { should be_mode 640 } + end -describe file("#{confd_dir}/consul_watch_check.json") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'consul' } + describe file("#{confd_dir}/consul_watch_check.json") do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'consul' } - it { should be_mode 640 } + it { should be_mode 640 } + end end diff --git a/test/integration/default/serverspec/windows_spec.rb b/test/integration/default/serverspec/windows_spec.rb new file mode 100644 index 00000000..e0e9177c --- /dev/null +++ b/test/integration/default/serverspec/windows_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +if windows? + consul_version = '0.6.4' + consul_executable = "C:\\Program Files\\consul\\#{consul_version}\\consul.exe" + + describe file(consul_executable) do + it { should be_file } + end + + describe service('consul') do + it { should be_enabled } + it { should be_running } + end + + [8300, 8400, 8500, 8600].each do |p| + describe port(p) do + it { should be_listening } + end + end + + describe command("& '#{consul_executable}' members -detailed") do + its(:exit_status) { should eq 0 } + its(:stdout) { should match %r{\balive\b} } + its(:stdout) { should match %r{\brole=consul\b} } + its(:stdout) { should match %r{\bbootstrap=1\b} } + its(:stdout) { should match %r{\bdc=fortmeade\b} } + end + + config_file = 'C:\Program Files\consul\consul.json' + confd_dir = 'C:\Program Files\consul\conf.d' + data_dir = 'C:\Program Files\consul\data' + + describe file(config_file) do + it { should be_file } + end + + describe file(confd_dir) do + it { should be_directory } + end + + describe file(data_dir) do + it { should be_directory } + end + + describe file("#{confd_dir}/consul_definition_check.json") do + it { should be_file } + end + + describe file("#{confd_dir}/consul_watch_check.json") do + it { should be_file } + end +end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb index c606a37c..5b6ee36f 100644 --- a/test/integration/helpers/serverspec/spec_helper.rb +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -1,10 +1,15 @@ require 'serverspec' -if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil? +def windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil +end + +if !windows? set :backend, :exec else set :backend, :cmd set :os, family: 'windows' + set :architecture, :x86_64 end # Tells serverspec to use a login shell for running chkconfig/service, From 4e02836032b28b80e1ac407b4728117f2c2a6d39 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Fri, 16 Sep 2016 14:24:59 -0700 Subject: [PATCH 2/3] Adding sudo back to centos run_list --- test/fixtures/policies/_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/policies/_base.rb b/test/fixtures/policies/_base.rb index 599ba424..7e44fa7e 100644 --- a/test/fixtures/policies/_base.rb +++ b/test/fixtures/policies/_base.rb @@ -2,7 +2,7 @@ default_source :chef_repo, '..' cookbook 'consul', path: '../../..' run_list 'consul::default', "consul_spec::#{name}" -named_run_list :centos, 'yum::default', 'yum-centos::default',run_list +named_run_list :centos, 'yum::default', 'yum-centos::default', 'sudo::default',run_list named_run_list :debian, 'apt::default', run_list named_run_list :freebsd, 'freebsd::default', 'sudo::default', run_list named_run_list :windows, 'windows::default', run_list From ebf82b0a644a87746571ba740c8bceb6267eed64 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Mon, 19 Sep 2016 13:56:26 -0700 Subject: [PATCH 3/3] Unified default linux and windows serverspec files --- .../default/serverspec/default_spec.rb | 100 +++++++++++------- .../default/serverspec/windows_spec.rb | 53 ---------- 2 files changed, 60 insertions(+), 93 deletions(-) delete mode 100644 test/integration/default/serverspec/windows_spec.rb diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index a8a1a8e5..f8cc3ae6 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -1,14 +1,21 @@ require 'spec_helper' -unless windows? - consul_version = '0.7.0' +consul_version = '0.7.0' + +if windows? + consul_executable = "C:\\Program Files\\consul\\#{consul_version}\\consul.exe" + consul_command = "& '#{consul_executable}'" +else consul_executable = "/opt/consul/#{consul_version}/consul" + consul_command = consul_executable +end - describe file(consul_executable) do - it { should be_file } - it { should be_executable } - end +describe file(consul_executable) do + it { should be_file } + it { should be_executable } unless windows? +end +unless windows? describe group('consul') do it { should exist } end @@ -22,76 +29,89 @@ its(:stdout) { should_not match /successfully logged in/ } its(:exit_status) { should_not eq 0 } end +end - describe service('consul') do - it { should be_enabled } - it { should be_running } - end +describe service('consul') do + it { should be_enabled } + it { should be_running } +end - [8300, 8400, 8500, 8600].each do |p| - describe port(p) do - it { should be_listening } - end +[8300, 8400, 8500, 8600].each do |p| + describe port(p) do + it { should be_listening } end +end - describe command("#{consul_executable} members -detailed") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match %r{\balive\b} } - its(:stdout) { should match %r{\brole=consul\b} } - its(:stdout) { should match %r{\bbootstrap=1\b} } - its(:stdout) { should match %r{\bdc=fortmeade\b} } - end +describe command("#{consul_command} members -detailed") do + its(:exit_status) { should eq 0 } + its(:stdout) { should match %r{\balive\b} } + its(:stdout) { should match %r{\brole=consul\b} } + its(:stdout) { should match %r{\bbootstrap=1\b} } + its(:stdout) { should match %r{\bdc=fortmeade\b} } +end +unless windows? config_dir = '/etc/consul' - config_file = '/etc/consul/consul.json' - confd_dir = '/etc/consul/conf.d' - data_dir = '/var/lib/consul' describe file(config_dir) do it { should be_directory } it { should be_owned_by 'root' } it { should be_grouped_into 'consul' } - it { should be_mode 755 } end +end - describe file(config_file) do - it { should be_file } +if windows? + config_file = 'C:\Program Files\consul\consul.json' + confd_dir = 'C:\Program Files\consul\conf.d' + data_dir = 'C:\Program Files\consul\data' +else + config_file = '/etc/consul/consul.json' + confd_dir = '/etc/consul/conf.d' + data_dir = '/var/lib/consul' +end + +describe file(config_file) do + it { should be_file } + unless windows? it { should be_owned_by 'root' } it { should be_grouped_into 'consul' } - it { should be_mode 640 } end +end - describe file(confd_dir) do - it { should be_directory } +describe file(confd_dir) do + it { should be_directory } + unless windows? it { should be_owned_by 'root' } it { should be_grouped_into 'consul' } - it { should be_mode 755 } end +end - describe file(data_dir) do - it { should be_directory } +describe file(data_dir) do + it { should be_directory } + unless windows? it { should be_owned_by 'consul' } it { should be_grouped_into 'consul' } - it { should be_mode 750 } end +end - describe file("#{confd_dir}/consul_definition_check.json") do - it { should be_file } +describe file("#{confd_dir}/consul_definition_check.json") do + it { should be_file } + unless windows? it { should be_owned_by 'root' } it { should be_grouped_into 'consul' } - it { should be_mode 640 } end +end - describe file("#{confd_dir}/consul_watch_check.json") do - it { should be_file } +describe file("#{confd_dir}/consul_watch_check.json") do + it { should be_file } + unless windows? it { should be_owned_by 'root' } it { should be_grouped_into 'consul' } - it { should be_mode 640 } end end diff --git a/test/integration/default/serverspec/windows_spec.rb b/test/integration/default/serverspec/windows_spec.rb deleted file mode 100644 index 8ba25397..00000000 --- a/test/integration/default/serverspec/windows_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' - -if windows? - consul_version = '0.7.0' - consul_executable = "C:\\Program Files\\consul\\#{consul_version}\\consul.exe" - - describe file(consul_executable) do - it { should be_file } - end - - describe service('consul') do - it { should be_enabled } - it { should be_running } - end - - [8300, 8400, 8500, 8600].each do |p| - describe port(p) do - it { should be_listening } - end - end - - describe command("& '#{consul_executable}' members -detailed") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match %r{\balive\b} } - its(:stdout) { should match %r{\brole=consul\b} } - its(:stdout) { should match %r{\bbootstrap=1\b} } - its(:stdout) { should match %r{\bdc=fortmeade\b} } - end - - config_file = 'C:\Program Files\consul\consul.json' - confd_dir = 'C:\Program Files\consul\conf.d' - data_dir = 'C:\Program Files\consul\data' - - describe file(config_file) do - it { should be_file } - end - - describe file(confd_dir) do - it { should be_directory } - end - - describe file(data_dir) do - it { should be_directory } - end - - describe file("#{confd_dir}/consul_definition_check.json") do - it { should be_file } - end - - describe file("#{confd_dir}/consul_watch_check.json") do - it { should be_file } - end -end