openstack-chef-repo/Rakefile
Jan Klare 481af2f96a adaptions for refactored cookbooks in mitaka cycle
* added new test scenarion allione (and all the needed files for it)
* removed old test scenarios aio-nova and aio-neutron as well as multi-neutron
  and multi-node and the related files since they will not work with the
  refactored cookbooks
* removed databag items for currently untested service cookbooks
* modified Rakefile to use new test scenarios for local and jenkins integration
  testing
* adapted README and docs to fit new test setup and explain the new
  attributes/template logic (with TODO)
* adapted Berksfile to use the master apache2 cookbook to comply with the
  dependencies in identity and dashboard
* removed image_upload recipe since this is already done in the
  integration-test::setup one
* moved recipe integration-test to a different chef_run to allow all services to
  be restarted in delayed actions of first run before using them
* removed heat from the testing stack until refactored
* removed tempest unit tests 'run_tests.sh' from integration testing scenarion,
  since there is no need to run tempests unit tests in our deployment

Depends-On: I0547182085eed91d05384fdd7734408a839a9a2c
Depends-On: I3262b2e6f792f37c32a446e6567790b82bdd4613
Depends-On: I80ed8a7892b59f7fd582505445a31b0df8d68752
Depends-On: Ia7fd927f42f4a1e484e8f2d34c52b1dc6d0ce6dd
Depends-On: Ifd11f86c576d7dbb709bdd302d41e39e900e1b74
Depends-On: Ida408a025f1a3e6a632108a9a32877026e286116
Depends-On: Idadc97bd7380d6c4f9f6f33d9c6b1215a5f24772
Depends-On: I9ac9eeb29ab27f31394830e4b6f999d5870cc0e4
Depends-On: Ifa5a7f4e1df47a3961976e64f654224864c3dcb4
Depends-On: I9cc1b5cc069987ac83e064322c2291772505ff5f
Implements: blueprint cookbook-refactoring

Change-Id: Icf0921229e9473a842d7ce5706027d56229e11d4
2016-02-10 09:25:55 +01:00

187 lines
5.6 KiB
Ruby

current_dir = File.dirname(__FILE__)
client_opts = "--force-formatter -z --config #{current_dir}/.chef/knife.rb"
task default: ["test"]
desc "Default gate tests to run"
task :test => [:rubocop, :berks_vendor, :json_check]
def run_command(command)
if File.exist?('Gemfile.lock')
sh %(bundle exec #{command})
else
sh %(chef exec #{command})
end
end
task :destroy_all do
Rake::Task[:destroy_machines].invoke
run_command('rm -rf Gemfile.lock && rm -rf Berksfile.lock && rm -rf cookbooks/')
end
desc "Destroy machines"
task :destroy_machines do
run_command("chef-client #{client_opts} destroy_all.rb")
end
desc "Vendor your cookbooks/"
task :berks_vendor do
run_command('berks vendor cookbooks')
end
desc "Create Chef Key"
task :create_key do
if not File.exist?('.chef/validator.pem')
require 'openssl'
File.binwrite('.chef/validator.pem', OpenSSL::PKey::RSA.new(2048).to_pem)
end
end
desc "All-in-One build"
task :allinone => :create_key do
run_command("chef-client #{client_opts} vagrant_linux.rb allinone.rb")
end
#desc "Multi-Neutron build"
#task :multi_neutron => :create_key do
# run_command("chef-client #{client_opts} vagrant_linux.rb multi-neutron.rb")
#end
desc "Blow everything away"
task clean: [:destroy_all]
# CI tasks
require 'rubocop/rake_task'
desc 'Run RuboCop'
RuboCop::RakeTask.new(:rubocop)
desc "Validate data bags, environments and roles"
task :json_check do
require 'json'
['data_bags/*', 'environments', 'roles'].each do |sub_dir|
Dir.glob(sub_dir + '/*.json') do |env_file|
puts "Checking #{env_file}"
JSON.parse(File.read(env_file))
end
end
end
# Helper for running various testing commands
def _run_commands(desc, commands, openstack=true)
puts "## Running #{desc}"
commands.each do |command, options|
options.each do |option|
if openstack
sh %(sudo bash -c '. /root/openrc && #{command} #{option}')
else
sh %(#{command} #{option})
end
end
end
puts "## Finished #{desc} tests"
end
# Helper for looking at the starting environment
def _run_env_queries # rubocop:disable Metrics/MethodLength
_run_commands('basic env queries', {
'uname' => ['-a'],
'pwd' => [''],
'env' => [''],
'ifconfig' => [''] },
false
)
end
# Helper for setting up basic query tests
def _run_basic_queries # rubocop:disable Metrics/MethodLength
_run_commands('basic test queries', {
'curl' => ['-v http://localhost', '-kv https://localhost'],
'sudo netstat' => ['-nlp'],
'nova-manage' => ['version', 'db version'],
'nova' => %w(--version service-list hypervisor-list net-list image-list),
'glance-manage' => %w(db_version),
'glance' => %w(--version image-list),
'keystone-manage' => %w(db_version),
'keystone' => %w(--version user-list endpoint-list role-list service-list tenant-list),
'cinder-manage' => ['version list', 'db version'],
'cinder' => %w(--version list),
'rabbitmqctl' => %w(cluster_status),
'ifconfig' => [''],
'neutron' => %w(agent-list ext-list net-list port-list subnet-list quota-list),
'ovs-vsctl' => %w(show) }
)
end
# Helper for setting up basic nova tests
def _run_nova_tests # rubocop:disable Metrics/MethodLength
uuid = `sudo bash -c '. /root/openrc && cinder list | grep test_volume | cut -d " " -f 2'`
_run_commands('nova boot tests pre', {
'nova' => ['list', "boot test --image cirros --flavor 1 --block-device-mapping vdb=#{uuid.chomp!}:::1"],
'sleep' => ['25'] }
)
_run_commands('nova boot tests post', {
'nova' => ['list', 'show test', 'delete test'],
'sleep' => ['25'],
'cinder' => ['list'] }
)
end
# Helper for setting up neutron local network
def _setup_local_network # rubocop:disable Metrics/MethodLength
_run_commands('neutron local network setup', {
'neutron' => ['net-create local_net --provider:network_type local',
'subnet-create local_net --name local_subnet 192.168.1.0/24'] }
)
end
# Helper for setting up cinder storage volume
def _setup_cinder_volume # rubocop:disable Metrics/MethodLength
_run_commands('cinder storage volume setup', {
'cinder' => ['create --display_name test_volume 1'] }
)
end
# Helper for setting up tempest and upload the default cirros image. Tempest
# itself is not yet used for integration tests.
def _setup_tempest(client_opts)
sh %(sudo chef-client #{client_opts} -E allinone-ubuntu14 -r 'recipe[openstack-integration-test::setup]')
end
def _dump_logs
paths = []
%w(nova neutron keystone cinder glance).each do |project|
paths << "-r \"\" /etc/#{project}/*"
paths << "-r \"\" /var/log/#{project}/*"
end
_run_commands('Dump Logs', {
'sleep' => ['25'],
'grep' => paths }
)
end
desc "Integration test on Infra"
task :integration => [:create_key, :berks_vendor] do
# This is a workaround for allowing chef-client to run in local mode
sh %(sudo mkdir /etc/chef && sudo cp .chef/encrypted_data_bag_secret /etc/chef/openstack_data_bag_secret)
_run_env_queries
# Workaround for https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1499199
sh %(sudo apt-get purge -y libvirt0)
# Three passes to make sure of cookbooks idempotency
for i in 1..3
puts "####### Pass #{i}"
# Kick off chef client in local mode, will converge OpenStack right on the gate job "in place"
sh %(sudo chef-client #{client_opts} -E allinone-ubuntu14 -r 'role[allinone]')
_setup_tempest(client_opts)
_dump_logs
_setup_local_network if i == 1
_run_basic_queries
_setup_cinder_volume
_run_nova_tests
end
# TODO (jklare) utilise tempest to run tests against openstack
# TODO (MRV) gather logs
end