diff --git a/.gitignore b/.gitignore index 6e377cd..dc96c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,6 @@ Puppetfile.lock # Ignore vagrant-generated files .vagrant + +# Beaker +log/ diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 2edc669..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -driver: - name: docker - use_sudo: false - disable_upstart: false - -provisioner: - name: puppet_apply - manifests_path: test - modules_path: modules - hiera_data_path: data - hiera_config_path: data/hiera.yaml - manifest: init.pp - -platforms: - - name: ubuntu-14.04 - driver_config: - image: midonet/ubuntu:14.04 - privileged: true - run_command: /sbin/init - ssh_timeout: 10 - ssh_retries: 5 - - name: centos-7 - driver_config: - image: midonet/centos:centos7 - privileged: true - volume: /sys/fs/cgroup:/sys/fs/cgroup:ro - run_command: /usr/sbin/init - ssh_timeout: 10 - ssh_retries: 5 - -suites: - - name: default diff --git a/Gemfile b/Gemfile index 94320f5..40147de 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,48 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || 'https://rubygems.org' -puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] -gem 'puppet', puppetversion -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'puppet-lint', '>= 0.3.2' -gem 'facter', '>= 1.7.0' -gem 'test-kitchen', :git => 'git://github.com/jdevesa/test-kitchen', :branch => 'remove_ssh_retry_options' -gem 'kitchen-puppet' -gem 'librarian-puppet', '>= 2.0.1' -gem 'kitchen-docker', :git => 'git://github.com/jdevesa/kitchen-docker.git', :branch => 'wait_for_ssh' -gem 'kitchen-vagrant' +def location_for(place, fake_version = nil) + if place =~ /^(git:[^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + +group :development, :unit_tests do + gem 'rspec-puppet', '~> 2.1', :require => false + gem 'rspec-core', '3.1.7', :require => false + gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false + gem 'puppet-lint', '>= 0.3.2', :require => false + gem 'metadata-json-lint', :require => false +end + +group :system_tests do + + if beaker_version = ENV['BEAKER_VERSION'] + gem 'beaker', *location_for(beaker_version) + end + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + + gem 'serverspec', :require => false + gem 'beaker-puppet_install_helper', :require => false +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/Rakefile b/Rakefile index 1c844cc..de4d508 100644 --- a/Rakefile +++ b/Rakefile @@ -1,33 +1,8 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' -require 'rspec/core/rake_task' + +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('relative') PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_autoloader_layout') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] - -desc "Validate manifests, templates, and ruby files" -task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end - Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| - sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ - end - Dir['templates/**/*.erb'].each do |template| - sh "erb -P -x -T '-' #{template} | ruby -c" - end -end - -task :lint do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet-lint --no-80chars-check --no-autoloader_layout-check #{manifest}" - end -end - -begin - require 'kitchen/rake_tasks' - Kitchen::RakeTasks.new -rescue LoadError - puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] -end diff --git a/spec/acceptance/midonet_agent_spec.rb b/spec/acceptance/midonet_agent_spec.rb new file mode 100644 index 0000000..aace4d6 --- /dev/null +++ b/spec/acceptance/midonet_agent_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper_acceptance' + +describe 'midonet all-in-one' do + + context 'default parameters' do + it 'should work with no errors' do + pp = <<-EOS + class { 'midonet': } + EOS + + # Run it twice for test the idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end + end +end diff --git a/spec/acceptance/nodesets/centos-70-x64.yml b/spec/acceptance/nodesets/centos-70-x64.yml new file mode 100644 index 0000000..f3e3938 --- /dev/null +++ b/spec/acceptance/nodesets/centos-70-x64.yml @@ -0,0 +1,8 @@ +HOSTS: + centos-70-x64: + platform: centos-70-x64 + image: midonet/centos:centos7 + hypervisor: docker + docker_cmd: '["/sbin/init"]' +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..ca062de --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,8 @@ +HOSTS: + ubuntu-14-04: + platform: ubuntu-14.04-x64 + image: midonet/ubuntu:14.04 + hypervisor: docker + docker_cmd: '["/sbin/init"]' +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..ca062de --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,8 @@ +HOSTS: + ubuntu-14-04: + platform: ubuntu-14.04-x64 + image: midonet/ubuntu:14.04 + hypervisor: docker + docker_cmd: '["/sbin/init"]' +CONFIG: + type: foss diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..91cd642 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..5f0c956 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,32 @@ +require 'beaker-rspec' +require 'beaker/puppet_install_helper' + +run_puppet_install_helper + +UNSUPPORTED_PLATFORMS = ['Suse','windows','AIX','Solaris'] + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + hosts.each do |host| + copy_module_to(host, :source => proj_root, :module_name => 'midonet') + scp_to(host, proj_root + '/data/hiera.yaml', "#{default['puppetpath']}/hiera.yaml") + shell("/bin/touch #{default['puppetpath']}/hiera.yaml") + on host, puppet('module install ripienaar-module_data'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-stdlib --version 4.5.0'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install midonet-zookeeper'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install midonet-cassandra'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-inifile'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-apt'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-java'), {:acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-tomcat'), {:acceptable_exit_codes => [0,1] } + end + end +end