From f86027ff161032ed9853d79ab1587172afb67d52 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Fri, 5 Feb 2016 17:26:49 -0800 Subject: [PATCH 1/2] Fixed Windows data path and added tests --- .kitchen.yml | 17 ++++++ attributes/default.rb | 4 +- libraries/helpers.rb | 4 +- .../serverspec/localhost/default_spec.rb | 28 ++++++++++ .../helpers/serverspec/spec_helper.rb | 7 ++- .../serverspec/localhost/default_spec.rb | 52 +++++++++++++++++++ .../serverspec/localhost/logging_spec.rb | 11 ++++ 7 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 test/integration/windefault/serverspec/localhost/default_spec.rb create mode 100644 test/integration/windefault/serverspec/localhost/logging_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index d4473994..0bbdfd61 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -62,3 +62,20 @@ suites: acl_master_token: doublesecret acl_datacenter: fortmeade acl_default_policy: deny + excludes: + - windows-2012r2 + - centos-7.2 + - centos-6.7 + - name: windefault + includes: + - windows-2012r2 + run_list: + - recipe[consul::default] + attributes: + consul: + service_user: vagrant + config: *default-config + service: + nssm_params: + AppStdout: C:\foo\bar\out.log + AppStderr: C:\foo\bar\err.log diff --git a/attributes/default.rb b/attributes/default.rb index c48c8457..07aa31e3 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -15,7 +15,7 @@ default['consul']['config']['bag_item'] = 'consul' default['consul']['config']['path'] = join_path config_prefix_path, 'consul.json' -default['consul']['config']['data_dir'] = windows? ? join_path(data_prefix_path, 'data') : data_prefix_path +default['consul']['config']['data_dir'] = data_path default['consul']['config']['ca_file'] = join_path config_prefix_path, 'ssl', 'CA', 'ca.crt' default['consul']['config']['cert_file'] = join_path config_prefix_path, 'ssl', 'certs', 'consul.crt' default['consul']['config']['key_file'] = join_path config_prefix_path, 'ssl', 'private', 'consul.key' @@ -44,7 +44,7 @@ # Windows only default['consul']['service']['nssm_params'] = { - 'AppDirectory' => join_path(data_prefix_path, 'data'), + 'AppDirectory' => data_path, 'AppStdout' => join_path(config_prefix_path, 'stdout.log'), 'AppStderr' => join_path(config_prefix_path, 'error.log'), 'AppRotateFiles' => 1, diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 28a52a76..ba2feb1a 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -40,8 +40,8 @@ def config_prefix_path windows? ? join_path(program_files, 'consul') : join_path('/etc', 'consul') end - def data_prefix_path - windows? ? join_path(program_files, 'consul') : join_path('/var/lib', 'consul') + def data_path + windows? ? join_path(program_files, 'consul', 'data') : join_path('/var/lib', 'consul') end def command(config_file, config_dir) diff --git a/test/integration/default/serverspec/localhost/default_spec.rb b/test/integration/default/serverspec/localhost/default_spec.rb index ac97018e..42b771c5 100644 --- a/test/integration/default/serverspec/localhost/default_spec.rb +++ b/test/integration/default/serverspec/localhost/default_spec.rb @@ -38,3 +38,31 @@ its(:stdout) { should match %r{\bbootstrap=1\b} } its(:stdout) { should match %r{\bdc=fortmeade\b} } end + +config_file = '/etc/consul/consul.json' +config_dir = '/etc/consul/conf.d' +data_dir = '/var/lib/consul' + +describe file(config_file) do + it { should be_file } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } + + it { should be_mode 640 } +end + +describe file(config_dir) do + it { should be_directory } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } + + 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' } + + it { should be_mode 755 } +end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb index 37af1b45..c1fddf06 100644 --- a/test/integration/helpers/serverspec/spec_helper.rb +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -1,3 +1,8 @@ require 'serverspec' -set :backend, :exec +if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil? + set :backend, :exec +else + set :backend, :cmd + set :os, family: 'windows' +end diff --git a/test/integration/windefault/serverspec/localhost/default_spec.rb b/test/integration/windefault/serverspec/localhost/default_spec.rb new file mode 100644 index 00000000..45ec00bf --- /dev/null +++ b/test/integration/windefault/serverspec/localhost/default_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe file('C:\Program Files\consul\consul.exe') do + it { should be_file } +end + +describe service('consul') do + it { should be_enabled } + it { should be_running } +end + +[8301, 8400, 8500, 8600].each do |p| + describe port(p) do + it { should be_listening } + end +end + +describe command('& "C:\Program Files\consul\consul.exe" 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' +config_dir = 'C:\Program Files\consul\conf.d' +data_dir = 'C:\Program Files\consul\data' + +describe file(config_file) do + it { should be_file } +# it { should be_owned_by 'consul' } +# it { should be_grouped_into 'consul' } + +# it { should be_mode 640 } +end + +describe file(config_dir) do + it { should be_directory } +# it { should be_owned_by 'consul' } +# it { should be_grouped_into 'consul' } + +# 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' } + +# it { should be_mode 755 } +end diff --git a/test/integration/windefault/serverspec/localhost/logging_spec.rb b/test/integration/windefault/serverspec/localhost/logging_spec.rb new file mode 100644 index 00000000..203a0045 --- /dev/null +++ b/test/integration/windefault/serverspec/localhost/logging_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +context 'logging' do + describe file('C:\foo\bar\out.log') do + it { should be_file } + end + + describe file('C:\foo\bar\err.log') do + it { should be_file } + end +end \ No newline at end of file From 4b571f1f515661f5f9df0e9277e058d7b313cab4 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Sat, 6 Feb 2016 11:08:44 -0800 Subject: [PATCH 2/2] Clean up --- .../serverspec/localhost/default_spec.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/integration/windefault/serverspec/localhost/default_spec.rb b/test/integration/windefault/serverspec/localhost/default_spec.rb index 45ec00bf..6f76cf45 100644 --- a/test/integration/windefault/serverspec/localhost/default_spec.rb +++ b/test/integration/windefault/serverspec/localhost/default_spec.rb @@ -9,7 +9,7 @@ it { should be_running } end -[8301, 8400, 8500, 8600].each do |p| +[8300, 8400, 8500, 8600].each do |p| describe port(p) do it { should be_listening } end @@ -29,24 +29,12 @@ describe file(config_file) do it { should be_file } -# it { should be_owned_by 'consul' } -# it { should be_grouped_into 'consul' } - -# it { should be_mode 640 } end describe file(config_dir) do it { should be_directory } -# it { should be_owned_by 'consul' } -# it { should be_grouped_into 'consul' } - -# 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' } - -# it { should be_mode 755 } end