From 7b913c939d3e344dd936d5ce38ee77de437d3143 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 13:51:27 -0700 Subject: [PATCH 01/11] add directory move if var/log/vault is not a link --- libraries/vault_service.rb | 6 ++++++ test/integration/default/inspec/default_spec.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libraries/vault_service.rb b/libraries/vault_service.rb index 8ef7c29..bb9d752 100644 --- a/libraries/vault_service.rb +++ b/libraries/vault_service.rb @@ -87,6 +87,12 @@ def action_enable # if /data directory mounted then we need to symlink /var/log/vault to /data/var/log/vault if ::File.directory?('/data') + # if /var/log/vault exists and is not a link, move to /var/log/vault.[created_at timestamp] + path = '/var/log/vault' + if ::File.directory?(path) && !::File.symlink?(path) + created_at = ::File.birthtime(path).strftime('%Y%m%d%H%M%S') + new_path = "#{path}.#{created_at}" + ::FileUtils.mv(path, new_path) link '/var/log/vault' do to ::File.join('/data', '/var/log/vault') action :create diff --git a/test/integration/default/inspec/default_spec.rb b/test/integration/default/inspec/default_spec.rb index 8dfd43c..e483978 100644 --- a/test/integration/default/inspec/default_spec.rb +++ b/test/integration/default/inspec/default_spec.rb @@ -20,6 +20,10 @@ its('content') { should match /.*reporting.*/ } end +describe file('/var/run/vault') do + it {should be_symlink} +end + describe service('vault') do it { should be_installed } it { should be_enabled } From 80d6968a7ed9a7ceeb49c8f6a94552702e031106 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 13:53:52 -0700 Subject: [PATCH 02/11] fix path bug --- test/integration/default/inspec/default_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/default/inspec/default_spec.rb b/test/integration/default/inspec/default_spec.rb index e483978..7b4f07e 100644 --- a/test/integration/default/inspec/default_spec.rb +++ b/test/integration/default/inspec/default_spec.rb @@ -20,7 +20,7 @@ its('content') { should match /.*reporting.*/ } end -describe file('/var/run/vault') do +describe file('/var/log/vault') do it {should be_symlink} end From b944589105df196fa90b31ec89c83d689f77cd1f Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 13:59:09 -0700 Subject: [PATCH 03/11] bum,p versions --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index 26cacea..a2945ad 100644 --- a/metadata.rb +++ b/metadata.rb @@ -6,7 +6,7 @@ long_description 'Application cookbook for installing and configuring Vault.' issues_url 'https://github.com/johnbellone/vault-cookbook/issues' source_url 'https://github.com/johnbellone/vault-cookbook/' -version '1002.7.9' +version '1002.7.10' supports 'ubuntu', '>= 12.04' supports 'redhat', '>= 6.4' From f498264c4b43cbd2b6ef3857ed75b3f5d8bcf461 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:09:34 -0700 Subject: [PATCH 04/11] add integration tests --- .kitchen.yml | 6 ++++ .../default/inspec/default_spec.rb | 4 --- .../test_data_dir/inspec/default_spec.rb | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 test/integration/test_data_dir/inspec/default_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index eff7f8b..78de36f 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -27,6 +27,12 @@ suites: - name: default provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb + - name: test-data-dir + provisioner: &default-provisioner + policyfile: test/fixtures/policies/default.rb + pre_create_command: mkdir -p /data + provisioner: &default-provisioner + policyfile: test/fixtures/policies/default.rb - name: test_unauthenticated_metrics provisioner: <<: *default-provisioner diff --git a/test/integration/default/inspec/default_spec.rb b/test/integration/default/inspec/default_spec.rb index 7b4f07e..8dfd43c 100644 --- a/test/integration/default/inspec/default_spec.rb +++ b/test/integration/default/inspec/default_spec.rb @@ -20,10 +20,6 @@ its('content') { should match /.*reporting.*/ } end -describe file('/var/log/vault') do - it {should be_symlink} -end - describe service('vault') do it { should be_installed } it { should be_enabled } diff --git a/test/integration/test_data_dir/inspec/default_spec.rb b/test/integration/test_data_dir/inspec/default_spec.rb new file mode 100644 index 0000000..7b4f07e --- /dev/null +++ b/test/integration/test_data_dir/inspec/default_spec.rb @@ -0,0 +1,31 @@ +describe file('/opt/vault/1.8.5/vault') do + it { should be_file } + it { should be_executable } +end + +describe group('vault') do + it { should exist } +end + +describe user('vault') do + it { should exist } +end + +describe file('/etc/vault/vault.json') do + its('mode') { should eq 0640 } + it { should be_file } + it { should be_owned_by 'vault' } + it { should be_grouped_into 'vault' } + its('content') { should match /.*log_level.*/ } + its('content') { should match /.*reporting.*/ } +end + +describe file('/var/log/vault') do + it {should be_symlink} +end + +describe service('vault') do + it { should be_installed } + it { should be_enabled } + it { should be_running } +end From ea823bc4d1e4be343f99db12c59526c3bff4c755 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:13:57 -0700 Subject: [PATCH 05/11] change to post converge .kitchen yml --- .kitchen.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 78de36f..4289976 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -30,9 +30,8 @@ suites: - name: test-data-dir provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb - pre_create_command: mkdir -p /data - provisioner: &default-provisioner - policyfile: test/fixtures/policies/default.rb + lifecycle: + post_converge: mkdir -p /var/log/vault - name: test_unauthenticated_metrics provisioner: <<: *default-provisioner From a1b1b2363965baf8ca0e1ab5be65be24993459a8 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:16:12 -0700 Subject: [PATCH 06/11] create /data on remote test --- .kitchen.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index 4289976..30c1194 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -31,7 +31,8 @@ suites: provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb lifecycle: - post_converge: mkdir -p /var/log/vault + post_converge: + - remote: mkdir -p /var/log/vault - name: test_unauthenticated_metrics provisioner: <<: *default-provisioner From 6d65f5c3dcdc28b2d7d39d64312cb5906d2bb5fc Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:16:24 -0700 Subject: [PATCH 07/11] create /data on remote test --- .kitchen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index 30c1194..b527364 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -32,7 +32,7 @@ suites: policyfile: test/fixtures/policies/default.rb lifecycle: post_converge: - - remote: mkdir -p /var/log/vault + - remote: mkdir -p /data - name: test_unauthenticated_metrics provisioner: <<: *default-provisioner From 0213cecf14e1658bc105361c30301f1f4339e468 Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:25:17 -0700 Subject: [PATCH 08/11] fix typo --- libraries/vault_service.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/vault_service.rb b/libraries/vault_service.rb index bb9d752..d2def46 100644 --- a/libraries/vault_service.rb +++ b/libraries/vault_service.rb @@ -93,6 +93,7 @@ def action_enable created_at = ::File.birthtime(path).strftime('%Y%m%d%H%M%S') new_path = "#{path}.#{created_at}" ::FileUtils.mv(path, new_path) + end link '/var/log/vault' do to ::File.join('/data', '/var/log/vault') action :create From 683a79d53363d9c1b679f24ecc69063cfebd088a Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 14:33:34 -0700 Subject: [PATCH 09/11] change to post_create --- .kitchen.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index b527364..ea75011 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -31,8 +31,8 @@ suites: provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb lifecycle: - post_converge: - - remote: mkdir -p /data + post_create: + - remote: sudo mkdir -p /data - name: test_unauthenticated_metrics provisioner: <<: *default-provisioner From b2777e1e7627c2d4a2abd321c199ec245bd785ef Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 15:06:33 -0700 Subject: [PATCH 10/11] remove whitespace --- .kitchen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index ea75011..cf2a58a 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -31,7 +31,7 @@ suites: provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb lifecycle: - post_create: + post_create: - remote: sudo mkdir -p /data - name: test_unauthenticated_metrics provisioner: From b06f1fb0398ebc09f5785e9b4aaa94537b7b1f7c Mon Sep 17 00:00:00 2001 From: rickzhang Date: Thu, 12 Sep 2024 15:29:32 -0700 Subject: [PATCH 11/11] typo in test name --- .kitchen.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index cf2a58a..7cf63b9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -27,8 +27,9 @@ suites: - name: default provisioner: &default-provisioner policyfile: test/fixtures/policies/default.rb - - name: test-data-dir - provisioner: &default-provisioner + - name: test_data_dir + provisioner: + <<: *default-provisioner policyfile: test/fixtures/policies/default.rb lifecycle: post_create: