From a770736c067ec13f8157f183cb30287555284a27 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Sun, 2 Aug 2015 03:08:33 -0500 Subject: [PATCH 1/2] dev testing --- .kitchen.yml | 4 ++-- Gemfile | 7 ------- libraries/resource_logstash.rb | 4 ++-- libraries/resource_logstash_forwarder.rb | 2 +- test/cookbooks/ellktest/metadata.rb | 2 ++ test/cookbooks/ellktest/recipes/default.rb | 23 +++++++++++++++++++++- test/integration/nodes/node00.json | 7 +++++++ 7 files changed, 36 insertions(+), 13 deletions(-) delete mode 100644 Gemfile create mode 100644 test/integration/nodes/node00.json diff --git a/.kitchen.yml b/.kitchen.yml index f9b6309..6a895e9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,9 +7,9 @@ # publish_all: true platforms: -#- name: centos-5 +- name: centos-5 - name: centos-6 -#- name: centos-7 +- name: centos-7 #- name: fedora #- name: ubuntu-12 # run_list: diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 151ce85..0000000 --- a/Gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source 'https://rubygems.org' - -gem 'berkshelf' - -group :integration do - gem 'test-kitchen' -end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb index ee0cdfb..6384436 100644 --- a/libraries/resource_logstash.rb +++ b/libraries/resource_logstash.rb @@ -22,8 +22,8 @@ class Logstash < Chef::Resource::LWRPBase attribute :path, kind_of: String, default: '/opt/logstash' - attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' - attribute :key_location, kind_of: String, default: '/etc/logstash/logstash.key' + attribute :crt_location, kind_of: String, required: true, default: '/etc/logstash/logstash.crt' + attribute :key_location, kind_of: String, required: true, default: '/etc/logstash/logstash.key' attribute :port, kind_of: Integer, default: 5043 attribute :conf_options, kind_of: Hash, default: {} diff --git a/libraries/resource_logstash_forwarder.rb b/libraries/resource_logstash_forwarder.rb index b1180e2..c4c650c 100644 --- a/libraries/resource_logstash_forwarder.rb +++ b/libraries/resource_logstash_forwarder.rb @@ -19,7 +19,7 @@ class LogstashForwarder < Chef::Resource::LWRPBase # configuration attribute :crt_location, kind_of: String, required: true, default: nil - attribute :key_location, kind_of: String, required: true, default: nil + attribute :key_location, kind_of: String, required: false, default: nil attribute :port, kind_of: Integer, default: 5043 attribute :timeout, kind_of: Integer, default: 15 attribute :logstash_servers, kind_of: Array, default: ['localhost:5043'] diff --git a/test/cookbooks/ellktest/metadata.rb b/test/cookbooks/ellktest/metadata.rb index 7923ed7..a8c76aa 100644 --- a/test/cookbooks/ellktest/metadata.rb +++ b/test/cookbooks/ellktest/metadata.rb @@ -8,3 +8,5 @@ depends 'ellk' depends 'runit' +depends 'yum' +depends 'apt' diff --git a/test/cookbooks/ellktest/recipes/default.rb b/test/cookbooks/ellktest/recipes/default.rb index 1706714..26af134 100644 --- a/test/cookbooks/ellktest/recipes/default.rb +++ b/test/cookbooks/ellktest/recipes/default.rb @@ -1,5 +1,21 @@ # test a single node with all four projects -%w( tar nano htop java-1.8.0-openjdk-headless ).each do |pkg| + +packages = %w( tar nano htop ) + +case node[:platform_family] +when 'debian' + include_recipe 'apt' + packages << 'openjdk-7-jre-headless' +when 'rhel' + include_recipe 'yum' + if node[:platform_version].to_f > 5 + packages << 'java-1.8.0-openjdk-headless' + else + packages << 'java-1.7.0-openjdk-headless' + end +end + +packages.each do |pkg| package pkg end @@ -20,6 +36,11 @@ datadir '/tmp/es_datadir' end +es_server = search(:node, 'tags:elasticsearch') +es_server.each do |es| + Chef::Log.info("#{es["name"]} has IP address #{es["ipaddress"]}") +end + bonus_env = { 'HELLO' => 'WORLD', 'LS_USER' => 'kibana' } # for testing sake # demonstrate sneaking in extra configuration when sourceing outside the ellk cookbook bonus_conf = { 'test_value' => 'merged hash from a recipe!' } diff --git a/test/integration/nodes/node00.json b/test/integration/nodes/node00.json new file mode 100644 index 0000000..6ba04c8 --- /dev/null +++ b/test/integration/nodes/node00.json @@ -0,0 +1,7 @@ +{ + "id": "node00", + "run_list": ["ellktest::default]"], + "automatic": { + "ipaddress": "127.0.0.1" + } +} \ No newline at end of file From d5d620566fccef29bee0ff35da415ed3a6272ba7 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 3 Aug 2015 19:55:22 -0500 Subject: [PATCH 2/2] update testing for more types --- .kitchen.yml | 18 +++++------- libraries/provider_logstash_forwarder.rb | 2 +- .../logstash-forwarder.conf.erb | 2 +- test/cookbooks/ellktest/recipes/default.rb | 28 ++++++++++--------- .../helpers/serverspec/elasticsearch.rb | 6 ++-- test/integration/helpers/serverspec/kibana.rb | 2 -- .../helpers/serverspec/logstash.rb | 2 -- .../helpers/serverspec/logstash_forwarder.rb | 2 -- test/integration/nodes/node00.json | 7 ----- 9 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 test/integration/nodes/node00.json diff --git a/.kitchen.yml b/.kitchen.yml index 6a895e9..8a3480a 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -9,17 +9,13 @@ platforms: - name: centos-5 - name: centos-6 -- name: centos-7 -#- name: fedora -#- name: ubuntu-12 -# run_list: -# - recipe[apt] -#- name: ubuntu-14 -# run_list: -# - recipe[apt] -#- name: debian -# run_list: -# - recipe[apt] +- name: ubuntu-12 +- name: ubuntu-14 +- name: ubuntu-15 + +transport: + name: ssh + compression: none provisioner: name: chef_zero diff --git a/libraries/provider_logstash_forwarder.rb b/libraries/provider_logstash_forwarder.rb index ab2dd9f..b06179c 100644 --- a/libraries/provider_logstash_forwarder.rb +++ b/libraries/provider_logstash_forwarder.rb @@ -42,7 +42,7 @@ class LogstashForwarder < Chef::Provider::LWRPBase variables options: { 'crt_location' => new_resource.crt_location, 'files' => new_resource.files, - 'key_location' => new_resource.key_location, + # 'key_location' => new_resource.key_location, 'logstash_servers' => new_resource.logstash_servers, 'timeout' => new_resource.timeout }.merge(new_resource.conf_options) diff --git a/templates/default/logstash-forwarder/logstash-forwarder.conf.erb b/templates/default/logstash-forwarder/logstash-forwarder.conf.erb index 859e5ba..02f5682 100644 --- a/templates/default/logstash-forwarder/logstash-forwarder.conf.erb +++ b/templates/default/logstash-forwarder/logstash-forwarder.conf.erb @@ -3,7 +3,7 @@ { "network": { "servers": <%= @options['logstash_servers'].to_json %>, - "ssl key": "<%= @options['key_location'] %>", +# "ssl key": "<%= @options['key_location'] %>", "ssl ca": "<%= @options['crt_location'] %>", "timeout": <%= @options['timeout'] %> }, diff --git a/test/cookbooks/ellktest/recipes/default.rb b/test/cookbooks/ellktest/recipes/default.rb index 26af134..6b0610b 100644 --- a/test/cookbooks/ellktest/recipes/default.rb +++ b/test/cookbooks/ellktest/recipes/default.rb @@ -1,5 +1,3 @@ -# test a single node with all four projects - packages = %w( tar nano htop ) case node[:platform_family] @@ -8,10 +6,10 @@ packages << 'openjdk-7-jre-headless' when 'rhel' include_recipe 'yum' - if node[:platform_version].to_f > 5 - packages << 'java-1.8.0-openjdk-headless' + if node[:platform_version].to_i == 5 + packages << 'java-1.7.0-openjdk' else - packages << 'java-1.7.0-openjdk-headless' + packages << 'java-1.8.0-openjdk-headless' end end @@ -19,7 +17,10 @@ package pkg end -include_recipe 'runit::default' +include_recipe 'runit' +link '/usr/local/bin/sv' do + to '/usr/bin/sv' +end # create certs (subject = localhost) secrets = Chef::DataBagItem.load('secrets', 'logstash') @@ -32,17 +33,16 @@ content logstash_crt end +## ELASTICSEARCH elasticsearch 'default' do datadir '/tmp/es_datadir' + version '1.7.1' + checksum '86a0c20eea6ef55b14345bff5adf896e6332437b19180c4582a346394abde019' + url 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.tar.gz' end -es_server = search(:node, 'tags:elasticsearch') -es_server.each do |es| - Chef::Log.info("#{es["name"]} has IP address #{es["ipaddress"]}") -end - +## LOGSTASH bonus_env = { 'HELLO' => 'WORLD', 'LS_USER' => 'kibana' } # for testing sake -# demonstrate sneaking in extra configuration when sourceing outside the ellk cookbook bonus_conf = { 'test_value' => 'merged hash from a recipe!' } logstash 'default' do crt_location '/tmp/logstash.crt' @@ -52,13 +52,15 @@ conf_options bonus_conf end +## LOGSTASH-FORWARDER logstash_forwarder 'default' do crt_location '/tmp/logstash.crt' - key_location '/tmp/logstash.key' + # key_location '/tmp/logstash.key' logstash_servers ['localhost:5043'] files [{ 'paths' => ['/var/log/messages', '/var/log/*log', '/var/log/kibana/current'], 'fields' => { 'type' => 'syslog' } }] end +## KIBANA kibana 'default' do port 8080 end diff --git a/test/integration/helpers/serverspec/elasticsearch.rb b/test/integration/helpers/serverspec/elasticsearch.rb index 154e057..930599e 100644 --- a/test/integration/helpers/serverspec/elasticsearch.rb +++ b/test/integration/helpers/serverspec/elasticsearch.rb @@ -1,5 +1,3 @@ -# sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' - shared_examples 'elasticsearch' do describe command('sv status elasticsearch') do its(:stdout) { should match 'run: elasticsearch' } @@ -18,12 +16,12 @@ its(:content) { should match 'elasticsearch' } end - describe file('/opt/elasticsearch/elasticsearch-1.7.0/config/elasticsearch.yml') do + describe file('/opt/elasticsearch/elasticsearch-1.7.1/config/elasticsearch.yml') do it { should be_file } its(:content) { should match '# This file was generated by Chef' } end - describe file('/opt/elasticsearch/elasticsearch-1.7.0/config/logging.yml') do + describe file('/opt/elasticsearch/elasticsearch-1.7.1/config/logging.yml') do it { should be_file } its(:content) { should match '# This file was generated by Chef' } end diff --git a/test/integration/helpers/serverspec/kibana.rb b/test/integration/helpers/serverspec/kibana.rb index 9566b8f..6b02308 100644 --- a/test/integration/helpers/serverspec/kibana.rb +++ b/test/integration/helpers/serverspec/kibana.rb @@ -1,5 +1,3 @@ -# sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' - shared_examples 'kibana' do describe command('sv status kibana') do its(:stdout) { should match 'run: kibana' } diff --git a/test/integration/helpers/serverspec/logstash.rb b/test/integration/helpers/serverspec/logstash.rb index 5cc05d7..c425313 100644 --- a/test/integration/helpers/serverspec/logstash.rb +++ b/test/integration/helpers/serverspec/logstash.rb @@ -1,5 +1,3 @@ -# sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' - shared_examples 'logstash' do describe command('sv status logstash') do its(:stdout) { should match 'run: logstash' } diff --git a/test/integration/helpers/serverspec/logstash_forwarder.rb b/test/integration/helpers/serverspec/logstash_forwarder.rb index e75602c..bf02ee3 100644 --- a/test/integration/helpers/serverspec/logstash_forwarder.rb +++ b/test/integration/helpers/serverspec/logstash_forwarder.rb @@ -1,5 +1,3 @@ -# sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' - shared_examples 'logstash_forwarder' do describe command('sv status logstash-forwarder') do its(:stdout) { should match 'run: logstash-forwarder' } diff --git a/test/integration/nodes/node00.json b/test/integration/nodes/node00.json deleted file mode 100644 index 6ba04c8..0000000 --- a/test/integration/nodes/node00.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "id": "node00", - "run_list": ["ellktest::default]"], - "automatic": { - "ipaddress": "127.0.0.1" - } -} \ No newline at end of file