From 9f03cda7c61fa59ec206b26655ec6586e184e051 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Tue, 31 Oct 2023 10:07:27 +0000 Subject: [PATCH] Fix markdown (#792) * Fix markdown Signed-off-by: Dan Webb * Migrate from rspec to inspec Busser has been pulled from Ruby gems and is no longer maintained Signed-off-by: Dan Webb * Change ServerSpec for InSpec Signed-off-by: Dan Webb --------- Signed-off-by: Dan Webb --- CHANGELOG.md | 2 + documentation/install.md | 2 +- documentation/install_repository.md | 2 +- kitchen.yml | 3 + mlc_config.json | 0 .../default/controls/extension_spec.rb | 9 ++ .../default/controls/service_spec.rb | 7 ++ .../integration/default/controls/user_spec.rb | 11 +++ test/integration/default/inspec.yml | 7 ++ .../helpers/serverspec/chef_examples.rb | 11 --- .../helpers/serverspec/configure_examples.rb | 97 ------------------- .../helpers/serverspec/install_examples.rb | 28 ------ .../helpers/serverspec/plugin_examples.rb | 26 ----- .../helpers/serverspec/service_examples.rb | 31 ------ .../helpers/serverspec/spec_helper.rb | 31 ------ .../helpers/serverspec/user_examples.rb | 20 ---- .../serverspec/default_spec.rb | 37 ------- .../serverspec/default_spec.rb | 34 ------- .../package/controls/package_test.rb | 7 ++ test/integration/package/inspec.yml | 9 ++ .../controls/default_spec.rb} | 2 + test/integration/repository/inspec.yml | 9 ++ .../repository/serverspec/default_spec.rb | 13 --- .../shieldwatcher/serverspec/default_spec.rb | 15 --- .../tarball/serverspec/default_spec.rb | 9 -- 25 files changed, 68 insertions(+), 354 deletions(-) delete mode 100644 mlc_config.json create mode 100644 test/integration/default/controls/extension_spec.rb create mode 100644 test/integration/default/controls/service_spec.rb create mode 100644 test/integration/default/controls/user_spec.rb create mode 100644 test/integration/default/inspec.yml delete mode 100644 test/integration/helpers/serverspec/chef_examples.rb delete mode 100644 test/integration/helpers/serverspec/configure_examples.rb delete mode 100644 test/integration/helpers/serverspec/install_examples.rb delete mode 100644 test/integration/helpers/serverspec/plugin_examples.rb delete mode 100644 test/integration/helpers/serverspec/service_examples.rb delete mode 100644 test/integration/helpers/serverspec/spec_helper.rb delete mode 100644 test/integration/helpers/serverspec/user_examples.rb delete mode 100644 test/integration/override_default/serverspec/default_spec.rb delete mode 100644 test/integration/override_package/serverspec/default_spec.rb create mode 100644 test/integration/package/controls/package_test.rb create mode 100644 test/integration/package/inspec.yml rename test/integration/{package/package_test.rb => repository/controls/default_spec.rb} (71%) create mode 100644 test/integration/repository/inspec.yml delete mode 100644 test/integration/repository/serverspec/default_spec.rb delete mode 100644 test/integration/shieldwatcher/serverspec/default_spec.rb delete mode 100644 test/integration/tarball/serverspec/default_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index d2fa876c3..885d91ae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix markdown errors + ## 5.1.6 - *2023-09-28* ## 5.1.5 - *2023-09-04* diff --git a/documentation/install.md b/documentation/install.md index 330bd5fe2..ab821e306 100644 --- a/documentation/install.md +++ b/documentation/install.md @@ -1,6 +1,6 @@ # `elasticsearch_install` -The install_repository.rb class is part of the Elasticsearch Cookbook and is responsible for managing the installation and removal of Elasticsearch repositories. It includes helper methods from the ElasticsearchCookbook::Helpers module and utilizes partials _common.rb and_repository.rb for defining properties related to Elasticsearch instances and repository options. +The install_repository.rb class is part of the Elasticsearch Cookbook and is responsible for managing the installation and removal of Elasticsearch repositories. It includes helper methods from the ElasticsearchCookbook::Helpers module and utilizes `partials/_common.rb` and `partials/_repository.rb` for defining properties related to Elasticsearch instances and repository options. ## Properties diff --git a/documentation/install_repository.md b/documentation/install_repository.md index fd7285001..2bec1e566 100644 --- a/documentation/install_repository.md +++ b/documentation/install_repository.md @@ -1,6 +1,6 @@ # install_repository -The install_repository.rb class is part of the Elasticsearch Cookbook and is responsible for managing the installation and removal of Elasticsearch repositories. It includes helper methods from the ElasticsearchCookbook::Helpers module and utilizes partials _common.rb and_repository.rb for defining properties related to Elasticsearch instances and repository options. +The install_repository.rb class is part of the Elasticsearch Cookbook and is responsible for managing the installation and removal of Elasticsearch repositories. It includes helper methods from the ElasticsearchCookbook::Helpers module and utilizes `partials/_common.rb` and `partials/_repository.rb` for defining properties related to Elasticsearch instances and repository options. ## Notes diff --git a/kitchen.yml b/kitchen.yml index 74f7d1865..31f6b82ce 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -12,6 +12,9 @@ provisioner: log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> nodes_path: "test/fixtures/nodes" +verifier: + name: inspec + platforms: - name: ubuntu-18.04 - name: ubuntu-20.04 diff --git a/mlc_config.json b/mlc_config.json deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/integration/default/controls/extension_spec.rb b/test/integration/default/controls/extension_spec.rb new file mode 100644 index 000000000..e3f2c5edf --- /dev/null +++ b/test/integration/default/controls/extension_spec.rb @@ -0,0 +1,9 @@ +auth_data = 'testuser:testpass@' + +control 'Plugin' do + describe http("http://#{auth_data}127.0.0.1:9200/_cat/plugins") do + its('status') { should eq 200 } + its('body') { should match(/analysis-icu/) } + its('body') { should match(/mapper-size/) } + end +end diff --git a/test/integration/default/controls/service_spec.rb b/test/integration/default/controls/service_spec.rb new file mode 100644 index 000000000..00419b595 --- /dev/null +++ b/test/integration/default/controls/service_spec.rb @@ -0,0 +1,7 @@ +control 'Service' do + describe service('elasticsearch') do + it { should be_installed } + it { should be_enabled } + it { should be_running } + end +end diff --git a/test/integration/default/controls/user_spec.rb b/test/integration/default/controls/user_spec.rb new file mode 100644 index 000000000..440c32675 --- /dev/null +++ b/test/integration/default/controls/user_spec.rb @@ -0,0 +1,11 @@ +control 'User' do + describe group('elasticsearch') do + it { should exist } + end + + describe user('elasticsearch') do + it { should exist } + it { should have_login_shell '/bin/bash' } + it { should belong_to_group 'elasticsearch' } + end +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml new file mode 100644 index 000000000..8754a25b4 --- /dev/null +++ b/test/integration/default/inspec.yml @@ -0,0 +1,7 @@ +--- +name: default +title: Default Tests for ElasticSearch +summary: This InSpec profile contains integration tests for the ElasticSearch cookbook +supports: + - os-family: linux + - os-family: bsd diff --git a/test/integration/helpers/serverspec/chef_examples.rb b/test/integration/helpers/serverspec/chef_examples.rb deleted file mode 100644 index aff02ebe4..000000000 --- a/test/integration/helpers/serverspec/chef_examples.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'chef version' do |version, _args = {}| - describe package('chef') do - it { should be_installed } - end - - describe command('chef-client -v') do - its(:stdout) { should match(/Chef: #{version}/) } - end -end diff --git a/test/integration/helpers/serverspec/configure_examples.rb b/test/integration/helpers/serverspec/configure_examples.rb deleted file mode 100644 index da210ab0c..000000000 --- a/test/integration/helpers/serverspec/configure_examples.rb +++ /dev/null @@ -1,97 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'elasticsearch configure' do |args = {}| - path_conf = args[:path_conf] || '/etc/elasticsearch' - path_data = args[:path_data] || '/var/lib/elasticsearch' - path_logs = args[:path_logs] || '/var/log/elasticsearch' - path_sysconfig = args[:path_sysconfig] || (rhel? ? '/etc/sysconfig/elasticsearch' : '/etc/default/elasticsearch') - - expected_user = args[:user] || 'elasticsearch' - expected_group = args[:group] || expected_user || 'elasticsearch' - - expected_config = args[:config] || [ - 'cluster.name: elasticsearch', - 'node.name: .+', - 'path.data: \/.+', - 'path.logs: \/.+', - ] - - expected_environment = args[:env] || [ - 'ES_PATH_CONF=.+', - 'DATA_DIR=.+', - 'ES_HOME=.+', - 'ES_STARTUP_SLEEP_TIME=.+', - 'LOG_DIR=.+', - 'MAX_LOCKED_MEMORY=.+', - 'MAX_MAP_COUNT=.+', - 'MAX_OPEN_FILES=.+', - 'PID_DIR=.+', - 'RESTART_ON_UPGRADE=.+', - ] - - expected_jvm_options = args[:jvmopts] || %w( - HeapDumpOnOutOfMemoryError - ErrorFile - ) - - describe file(path_conf) do - it { should be_directory } - it { should be_mode 750 } - it { should be_owned_by expected_user } unless package? - it { should be_grouped_into expected_group } unless package? - end - - [path_data, path_logs].each do |p| - describe file(p) do - it { should be_directory } - it { should be_mode 755 } - it { should be_owned_by expected_user } unless package? - it { should be_grouped_into expected_group } unless package? - end - end - - describe file(path_sysconfig) do - it { should be_file } - it { should be_mode 644 } - - expected_environment.each do |line| - its(:content) { should contain(/#{line}/) } - end - - if package? - its(:content) { should_not contain(/ES_GROUP=.+/) } - its(:content) { should_not contain(/ES_USER=.+/) } - end - end - - describe file("#{path_conf}/elasticsearch.yml") do - it { should be_file } - it { should be_mode 640 } - it { should be_owned_by expected_user } - it { should be_grouped_into expected_group } - - expected_config.each do |line| - its(:content) { should contain(/#{line}/) } - end - end - - describe file("#{path_conf}/jvm.options") do - it { should be_file } - it { should be_mode 644 } - it { should be_owned_by expected_user } - it { should be_grouped_into expected_group } - - expected_jvm_options.each do |line| - its(:content) { should contain(/#{line}/) } - end - end - - describe file("#{path_conf}/log4j2.properties") do - it { should be_file } - it { should be_mode 640 } - it { should be_owned_by expected_user } - it { should be_grouped_into expected_group } - - its(:content) { should match(/logger.action.name = org.elasticsearch.action/) } - end -end diff --git a/test/integration/helpers/serverspec/install_examples.rb b/test/integration/helpers/serverspec/install_examples.rb deleted file mode 100644 index 03580d787..000000000 --- a/test/integration/helpers/serverspec/install_examples.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'elasticsearch install' do |args = {}| - dir = args[:dir] || '/usr/share' - version = args[:version] || '7.8.0' - - expected_user = args[:user] || 'elasticsearch' - expected_group = args[:group] || expected_user || 'elasticsearch' - - describe file("#{dir}/elasticsearch-#{version}"), if: tarball? do - it { should be_directory } - it { should be_owned_by expected_user } - it { should be_grouped_into expected_group } - end - - describe file("#{dir}/elasticsearch"), if: tarball? do - it { should be_symlink } - end - - describe file('/usr/local/bin/elasticsearch'), if: tarball? do - it { should be_symlink } - it { should be_linked_to("#{dir}/elasticsearch-#{version}/bin/elasticsearch") } - end - - describe package('elasticsearch'), if: package? do - it { should be_installed } - end -end diff --git a/test/integration/helpers/serverspec/plugin_examples.rb b/test/integration/helpers/serverspec/plugin_examples.rb deleted file mode 100644 index 76d9a4bc1..000000000 --- a/test/integration/helpers/serverspec/plugin_examples.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'elasticsearch plugin' do |plugin_name, args = {}| - expected_user = args[:user] || (package? ? 'root' : 'elasticsearch') - expected_group = args[:group] || expected_user || 'elasticsearch' - expected_home = args[:home] || '/usr/share/elasticsearch' - expected_plugin = args[:plugin] || "#{expected_home}/plugins/#{plugin_name}" - expected_response_code = args[:response_code] || 200 - auth_data = args[:auth_data] || 'testuser:testpass@' - - describe file(expected_plugin) do - it { should be_directory } - it { should be_owned_by expected_user } - it { should be_grouped_into expected_group } - end - - describe command("curl -s -o /dev/null -w \"%{http_code}\" http://#{auth_data}127.0.0.1:9200/_cat/plugins") do - its(:stdout) { should match(/#{expected_response_code}/) } - end - - if expected_response_code == 200 - describe command("curl -v http://#{auth_data}127.0.0.1:9200/_cat/plugins") do - its(:stdout) { should match(/#{plugin_name}/) } - end - end -end diff --git a/test/integration/helpers/serverspec/service_examples.rb b/test/integration/helpers/serverspec/service_examples.rb deleted file mode 100644 index 394595c82..000000000 --- a/test/integration/helpers/serverspec/service_examples.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'elasticsearch service' do |service_name = 'elasticsearch', args = {}| - content_match = args[:content] || 'elasticsearch' - - describe file("/usr/lib/systemd/system/#{service_name}.service") do - it { should be_file } - it { should be_mode 644 } - - if package? - its(:content) { should contain(/ES_SD_NOTIFY=true/) } - else - its(:content) { should_not contain(/ES_SD_NOTIFY=true/) } - end - end - - # we should move to inspec here ASAP, as this doesn't pass due to serverspec - describe service(service_name) do - it { should be_enabled } - it { should be_running } - end - - # always sleep before checking the service; it needs time to stabilize - describe command('sleep 30') do - its(:exit_status) { should eq 0 } - end - - describe command('curl http://testuser:testpass@localhost:9200') do - its(:stdout) { should match(/#{content_match}/) } - end -end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb deleted file mode 100644 index 758fb0d4e..000000000 --- a/test/integration/helpers/serverspec/spec_helper.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'serverspec' - -base_path = File.dirname(__FILE__) -Dir["#{base_path}/*_examples.rb"].each do |ex| - require_relative ex -end - -set :backend, :exec -set :path, '/usr/sbin:/sbin:/usr/local/sbin:/bin:/usr/bin:$PATH' - -def rhel? - %w(redhat).include?(os[:family]) -end - -def debian? - %w(ubuntu debian).include?(os[:family]) -end - -def package? - if debian? - system('dpkg -l elasticsearch >/dev/null 2>&1') - elsif rhel? - system('rpm -qa | grep elasticsearch >/dev/null 2>&1') - else - raise "I don't recognize #{os[:family]}, so I can't check for an elasticsearch package" - end -end - -def tarball? - !package? -end diff --git a/test/integration/helpers/serverspec/user_examples.rb b/test/integration/helpers/serverspec/user_examples.rb deleted file mode 100644 index 2b5cc8c1e..000000000 --- a/test/integration/helpers/serverspec/user_examples.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative 'spec_helper' - -shared_examples_for 'elasticsearch user' do |args = {}| - expected_user = args[:user] || 'elasticsearch' - expected_group = args[:group] || expected_user || 'elasticsearch' - # expected_home = args[:home] || (package? ? "/usr/share/#{expected_user}" : "/usr/local/#{expected_user}") - expected_shell = args[:shell] || '/bin/bash' - - describe group(expected_group) do - it { should exist } - it { should have_gid(args[:gid]) } if args[:gid] - end - - describe user(expected_user) do - it { should exist } - it { should have_login_shell expected_shell } - it { should belong_to_group expected_group } - it { should have_uid(args[:uid]) } if args[:uid] - end -end diff --git a/test/integration/override_default/serverspec/default_spec.rb b/test/integration/override_default/serverspec/default_spec.rb deleted file mode 100644 index 0f304a977..000000000 --- a/test/integration/override_default/serverspec/default_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative 'spec_helper' - -describe 'non-standard elasticsearch install and configure' do - path_component = rhel? ? 'sysconfig' : 'default' - - it_behaves_like 'elasticsearch user', user: 'elasticsearch', - uid: 1111, - shell: '/bin/sh', - group: 'bar', - gid: 2222 - - it_behaves_like 'elasticsearch install', dir: '/usr/local/awesome', - package: 'elasticsearch', - user: 'elasticsearch', - group: 'bar' - - it_behaves_like 'elasticsearch configure', dir: '/usr/local/awesome', - user: 'elasticsearch', - group: 'bar', - path_conf: '/usr/local/awesome/etc/elasticsearch', - path_data: '/usr/local/awesome/var/data/elasticsearch', - path_logs: '/usr/local/awesome/var/log/elasticsearch', - path_sysconfig: "/etc/#{path_component}/elasticsearch-crazy", - jvmopts: ['java.awt.headless', 'UseG1GC'] - - it_behaves_like 'elasticsearch service', 'elasticsearch-crazy' -end - -describe 'removed elasticsearch users should NOT exist' do - describe group('deleteme') do - it { should_not exist } - end - - describe user('deleteme') do - it { should_not exist } - end -end diff --git a/test/integration/override_package/serverspec/default_spec.rb b/test/integration/override_package/serverspec/default_spec.rb deleted file mode 100644 index c9a71b79c..000000000 --- a/test/integration/override_package/serverspec/default_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative 'spec_helper' - -describe 'non-standard elasticsearch install and configure' do - path_component = rhel? ? 'sysconfig' : 'default' - - it_behaves_like 'elasticsearch user', user: 'elasticsearch', - uid: 1111, - shell: '/bin/sh', - group: 'elasticsearch', - gid: 2222 - - it_behaves_like 'elasticsearch install', dir: '/usr/local/awesome', - package: 'elasticsearch', - user: 'elasticsearch', - group: 'elasticsearch' - - it_behaves_like 'elasticsearch configure', dir: '/usr/local/awesome', - user: 'elasticsearch', - group: 'elasticsearch', - path_sysconfig: "/etc/#{path_component}/elasticsearch-crazy", - jvmopts: ['java.awt.headless', 'UseG1GC'] - - it_behaves_like 'elasticsearch service', 'elasticsearch-crazy' -end - -describe 'removed elasticsearch users should NOT exist' do - describe group('deleteme') do - it { should_not exist } - end - - describe user('deleteme') do - it { should_not exist } - end -end diff --git a/test/integration/package/controls/package_test.rb b/test/integration/package/controls/package_test.rb new file mode 100644 index 000000000..a4311d2d5 --- /dev/null +++ b/test/integration/package/controls/package_test.rb @@ -0,0 +1,7 @@ +control 'Elasticsearch package' do + describe package('elasticsearch') do + it { should be_installed } + end +end + +include_controls 'default' diff --git a/test/integration/package/inspec.yml b/test/integration/package/inspec.yml new file mode 100644 index 000000000..40ad186d6 --- /dev/null +++ b/test/integration/package/inspec.yml @@ -0,0 +1,9 @@ +name: elasticsearch package test +title: Elasticsearch Package Test +version: 0.1.0 +supports: + - os-family: linux + - os-family: bsd +depends: + - name: default + path: test/integration/default diff --git a/test/integration/package/package_test.rb b/test/integration/repository/controls/default_spec.rb similarity index 71% rename from test/integration/package/package_test.rb rename to test/integration/repository/controls/default_spec.rb index ece06cf11..a61b256b8 100644 --- a/test/integration/package/package_test.rb +++ b/test/integration/repository/controls/default_spec.rb @@ -1,3 +1,5 @@ describe package('elasticsearch') do it { should be_installed } end + +include_controls 'default' diff --git a/test/integration/repository/inspec.yml b/test/integration/repository/inspec.yml new file mode 100644 index 000000000..5a60e1ebf --- /dev/null +++ b/test/integration/repository/inspec.yml @@ -0,0 +1,9 @@ +name: elasticsearch repository test +title: Elasticsearch Repository Test +version: 0.1.0 +supports: + - os-family: linux + - os-family: bsd +depends: + - name: default + path: test/integration/default diff --git a/test/integration/repository/serverspec/default_spec.rb b/test/integration/repository/serverspec/default_spec.rb deleted file mode 100644 index 27a069851..000000000 --- a/test/integration/repository/serverspec/default_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative 'spec_helper' - -describe 'standard elasticsearch install and configure' do - it_behaves_like 'elasticsearch user' - it_behaves_like 'elasticsearch install' - it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'analysis-icu' - it_behaves_like 'elasticsearch service' -end - -describe package('elasticsearch') do - it { should be_installed } -end diff --git a/test/integration/shieldwatcher/serverspec/default_spec.rb b/test/integration/shieldwatcher/serverspec/default_spec.rb deleted file mode 100644 index 5f65dffc9..000000000 --- a/test/integration/shieldwatcher/serverspec/default_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative 'spec_helper' - -describe 'standard elasticsearch install and configure' do - it_behaves_like 'elasticsearch user' - it_behaves_like 'elasticsearch install' - it_behaves_like 'elasticsearch configure' - - # because shield, these now should return failures - it_behaves_like 'elasticsearch plugin', 'analysis-icu', auth_data: '', response_code: 401 - it_behaves_like 'elasticsearch service', 'elasticsearch', auth_data: '', content: 'missing authentication' -end - -describe package('elasticsearch') do - it { should be_installed } -end diff --git a/test/integration/tarball/serverspec/default_spec.rb b/test/integration/tarball/serverspec/default_spec.rb deleted file mode 100644 index 66f333b33..000000000 --- a/test/integration/tarball/serverspec/default_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative 'spec_helper' - -describe 'standard elasticsearch install and configure' do - it_behaves_like 'elasticsearch user' - it_behaves_like 'elasticsearch install' - it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'analysis-icu' - it_behaves_like 'elasticsearch service' -end