Last active
July 15, 2016 09:10
-
-
Save viq/1c9f9479b8f8d6f3631b7931e984f7aa to your computer and use it in GitHub Desktop.
test-kitchen with lxc, cfengine and serverspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
driver: | |
name: vagrant | |
vagrantfile_erb: Vagrantfile.erb | |
#provision: true | |
#http_proxy: http://10.0.2.2:8123 | |
#https_proxy: https://10.0.2.2:8123 | |
provisioner: | |
name: cfengine | |
#chef_omnibus_url: http://www.getchef.com/chef/install.sh | |
#cfenging_type: community | |
#cfengine_policy_server_address: 10.0.2.15 | |
cfengine_files: cfengine_files | |
cf_agent_args: -KI -D testrun | |
cf_agent_runs: 3 | |
platforms: | |
- name: debian-7-amd64 | |
driver: | |
#box: debian-7.11-amd64 | |
box: debian/wheezy64 | |
provider: lxc | |
provision: true | |
- name: debian-8-amd64 | |
driver: | |
box: deb8 | |
provider: lxc | |
suites: | |
- name: es | |
run_list: | |
- elasticsearch.cf | |
- name: pkg | |
run_list: | |
- packages.cf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── bootstrap.sh | |
├── cfengine_files | |
│ └── inputs | |
│ ├── elasticsearch.cf | |
│ └── packages.cf | |
├── .kitchen | |
│ ├── kitchen-vagrant | |
│ └── logs | |
│ ├── default-debian-6-amd64.log | |
│ ├── default-debian-7-amd64.log | |
│ ├── elasticsearch-debian-7-amd64.log | |
│ ├── es-debian-7-amd64.log | |
│ ├── es-debian-8-amd64.log | |
│ ├── kitchen.log | |
│ ├── pkg-debian-6-amd64.log | |
│ ├── pkg-debian-7-amd64.log | |
│ └── pkg-debian-8-amd64.log | |
├── .kitchen.yml | |
├── .ruby-gemset | |
├── .ruby-version | |
├── test | |
│ └── integration | |
│ ├── default | |
│ │ └── serverspec | |
│ ├── es | |
│ │ └── serverspec | |
│ │ └── elasticsearch_spec.rb | |
│ └── pkg | |
│ └── serverspec | |
│ └── packages_spec.rb | |
└── Vagrantfile.erb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body common control | |
{ | |
inputs => { "$(sys.libdir)/stdlib.cf" }; | |
bundlesequence => { "elasticsearch" }; | |
} | |
bundle agent elasticsearch | |
{ | |
vars: | |
"esrepokey" string => "D27D666CD88E42B4"; | |
#"aptkeys" slist => execresult("apt-key finger | grep fingerprint | cut -d= -f2 | tr -d ' '","useshell"); | |
"esrepo" string => "deb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main"; | |
"es_packages" slist => { "elasticsearch" }; | |
debian_6:: | |
"es_deps" slist => { "openjdk-6-jre-headless" }; | |
debian_7:: | |
"es_deps" slist => { "openjdk-7-jre-headless" }; | |
debian_8:: | |
"es_deps" slist => { "openjdk-7-jre-headless" }; | |
files: | |
"/etc/apt/sources.list.d/elasticsearch.list" | |
perms => m("644"), | |
handle => "elasticsearch_repo", | |
comment => "Repository for ElasticSearch packages", | |
create => "true", | |
edit_line => append_if_no_line("$(esrepo)"); | |
classes: | |
"es_key_present" expression => returnszero("apt-key finger | grep fingerprint | cut -d= -f2 | tr -d ' '| grep $(esrepokey)", "useshell"); | |
packages: | |
es_key_present:: | |
"elasticsearch"; | |
commands: | |
!es_key_present:: | |
"/usr/bin/wget -qO /tmp/es.key https://packages.elasticsearch.org/GPG-KEY-elasticsearch"; | |
"/usr/bin/apt-key add /tmp/es.key"; | |
#"/usr/bin/apt-key adv --keyserver hkp://keys.gnupg.net --recv-key $(esrepokey)"; | |
"/usr/bin/apt-get update"; | |
methods: | |
"packages" usebundle => package_present("$(es_deps)"); | |
es_key_present:: | |
"packages" usebundle => package_present("$(es_packages)"); | |
services: | |
es_key_present:: | |
"elasticsearch" | |
service_policy => "start"; | |
reports: | |
es_key_present:: | |
"Apt key present: '$(esrepokey)'"; | |
} | |
body service_method elasticsearch { | |
service_autostart_policy => "boot_time"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'serverspec' | |
set :backend, :exec | |
puts os | |
describe package('elasticsearch') do | |
it { should be_installed } | |
end | |
if os[:family] == 'debian' | |
if os[:release] >= '6' and os[:release] < '7' | |
describe package('openjdk-6-jre-headless') do | |
it { should be_installed } | |
end | |
elsif os[:release] >= '7' | |
describe package('openjdk-7-jre-headless') do | |
it { should be_installed } | |
end | |
end | |
end | |
describe service('elasticsearch') do | |
it { should be_running } | |
end | |
describe port('9200') do | |
it { should be_listening } | |
end | |
describe port('9300') do | |
it { should be_listening } | |
end | |
describe file('/etc/apt/sources.list.d/elasticsearch.list') do | |
it { should be_file } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body common control | |
{ | |
inputs => { "$(sys.libdir)/stdlib.cf" }; | |
bundlesequence => { "manage_packages" }; | |
} | |
bundle agent manage_packages | |
{ | |
vars: | |
"packages" | |
slist => { "tmux", "vim", "multitail", "htop", "tree", "tor" }; | |
methods: | |
"packages" usebundle => package_latest("${packages}"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'spec_helper' | |
require 'serverspec' | |
#require 'pathname' | |
set :backend, :exec | |
#Dir["./shared/**/*.rb"].sort.each{ |f| require f } | |
#include Serverspec::Helper::Exec | |
#include Serverspec::Helper::DetectOS | |
#include Serverspec::Helper::Properties | |
#RSpec.configure do |c| | |
# c.before :all do | |
# c.path = '/sbin:/usr/sbin:/bin:/usr/bin' | |
# end | |
#end | |
describe "packages" do | |
["tmux", "vim", "multitail", "htop", "tree", "tor"].each do |pkg| | |
describe package("#{pkg}") do | |
it { should be_installed } | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |c| | |
c.vm.box = "<%= config[:box] %>" | |
c.vm.box_url = "<%= config[:box_url] %>" | |
<% if config[:vm_hostname] %> | |
c.vm.hostname = "<%= config[:vm_hostname] %>" | |
<% end %> | |
<% if config[:guest] %> | |
c.vm.guest = <%= config[:guest] %> | |
<% end %> | |
<% if config[:username] %> | |
c.ssh.username = "<%= config[:username] %>" | |
<% end %> | |
<% if config[:ssh_key] %> | |
c.ssh.private_key_path = "<%= config[:ssh_key] %>" | |
<% end %> | |
<% Array(config[:network]).each do |opts| %> | |
c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>) | |
<% end %> | |
c.vm.synced_folder ".", "/vagrant", disabled: true | |
<% config[:synced_folders].each do |source, destination, options| %> | |
c.vm.synced_folder "<%= source %>", "<%= destination %>", <%= options %> | |
<% end %> | |
c.cache.auto_detect = false | |
c.cache.scope = :box | |
#c.proxy.http = "http://10.0.2.2:8138" | |
#c.proxy.https = "https://10.0.2.2:8138" | |
c.vm.provider :<%= config[:provider] %> do |p| | |
<% config[:customize].each do |key, value| %> | |
<% case config[:provider] | |
when "virtualbox" %> | |
p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"] | |
<% when "rackspace", "softlayer" %> | |
p.<%= key %> = "<%= value%>" | |
<% when /^vmware_/ %> | |
<% if key == :memory %> | |
<% unless config[:customize].include?(:memsize) %> | |
p.vmx["memsize"] = "<%= value %>" | |
<% end %> | |
<% else %> | |
p.vmx["<%= key %>"] = "<%= value %>" | |
<% end %> | |
<% end %> | |
<% end %> | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment