diff --git a/README.md b/README.md index dbec5ca..397752e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ folsom implementation of the openstack puppet modules. # prereqs -1. Ensure that you have rake and rubygems installed +1. Ensure that you have rubygems installed 2. install vagrant and dependencies: @@ -16,9 +16,9 @@ vagrant should be installed (the latest version of vagrant is generally availabl virtualbox should be installed -3. Install librarian-puppet. +3. Install librarian-puppet-simple. - > gem install librarian-puppet + > gem install librarian-puppet-simple 3. it is strongly recommended that you set up a proxy (like squid!) to speed up perforance of package installation. If you do not use a proxy, you need to change some settings in @@ -28,28 +28,23 @@ your site manifest. This project contains the following files -Vagrantfile - used to specify the virtual machines that vagrant can use to -spin up test openstack environments. +Vagrantfile + specifies virtual machines that build openstack test/dev environments. -Rakefile - stores tasks that can be used to build out openstack environments - -Puppetfile - used by librarian puppet to install the required modules +Puppetfile + used by librarian puppet to install the required modules manifests/setup/hosts.pp - -stores basic host setup (ip addresses for vagrant targets) + stores basic host setup (ip addresses for vagrant targets) manifests/setup/percise64.pp - -stores apt setup, configured to use a proxy, and folsom package pointer(s) + stores apt setup, configured to use a proxy, and folsom package pointer(s) manifests/setup/centos.pp - -stores yum setup, configuration for a local yum repo machine, and folsom package pointer(s) + stores yum setup, configuration for a local yum repo machine, and folsom package pointer(s) manifests/site.pp - -just what you'd expect it to be. + stores site manifests for configuring openstack # installing module deps @@ -78,10 +73,8 @@ Too see a list of the virtual machines that are managed by vagrant, run keystone not created mysql not created -To see a list of all available rake tasks, run: -(rake tasks have not yet been defined) - - > rake -T +The best maintained examples are for a two node install +based on a compute and controller. Deploy a controller and a compute node: diff --git a/Rakefile b/Rakefile deleted file mode 100644 index d265c16..0000000 --- a/Rakefile +++ /dev/null @@ -1,238 +0,0 @@ -require 'yaml' -require 'rubygems' - -def base_dir - File.expand_path(File.dirname(__FILE__)) -end - -$LOAD_PATH << File.join(base_dir, 'lib') - -require 'puppetlabs/os_tester' - -include Puppetlabs::OsTester - -def github_password - YAML.load_file(File.join(base_dir, '.github_auth'))['password'] -end - -def github_admins - YAML.load_file(File.join(base_dir, '.github_auth'))['admins'].to_a -end - -def github_login - YAML.load_file(File.join(base_dir, '.github_auth'))['login'] -end - -def log_file - return @log_file if @log_file - log_dir = File.join(base_dir, 'logs') - log_file = File.join(log_dir, "#{Time.now.to_i.to_s}.log") - FileUtils.mkdir(log_dir) unless File.exists?(log_dir) - FileUtils.touch(log_file) - @log_file = log_file -end - -namespace :openstack do - - desc 'get testable pull requests' - task :testable_pull_requests do - testable_pull_requests( - ['cinder', 'nova', 'glance', 'openstack', 'keystone', 'horizon'], - github_admins, - github_login, - github_password, - 'ready_for_testing' - ) - end - - desc 'clone all required modules' - task :setup do - cmd_system('librarian-puppet install') - end - - desc 'destroy all vms' - task 'destroy' do - destroy_all_vms - end - - desc 'destroy all swift vms' - task 'destroy_swift' do - destroy_swift_vms - end - - desc 'deploys the entire environment' - task :deploy_two_node do - deploy_two_node - end - - desc 'deploy a swift cluster' - task :deploy_swift do - deploy_swift_cluster - end - -end - - -namespace :git do - - cwd = base_dir - - desc 'for all repos in the module directory, add a read/write remote' - task :dev_setup do - dev_setup(github_login) - end - - desc 'pull the latest version of all code' - task :pull_all do - pull_all - end - - desc 'shows the current state of code that has not been commited' - task :status_all do - status_all - end - - desc 'make sure that the current version from the module file matches the last tagged version' - task :check_tags , [:project_name] do |t, args| - # I need to be able to return this as a data structure - # when I start to do more complicated things like - # automated releases, I will need this data - check_tags(args.project_name) - end - - desc 'make sure that the current version from the module file matches the last tagged version' - task :check_all_tags do - check_tags - end - - task :check_sha_all do - each_repo do |module_name| - print module_name + ':' - puts git_cmd('rev-parse HEAD --quiet') - end - end - - desc 'prints the total number of people that have contributed to all projects.' - task :num_contributors do - puts contributor_hash.size - end - - desc 'print the names of all contributors (and what projects they contributed to' - task :list_contributors do - contributor_hash.each do |k, v| - puts "#{k}:#{v[:repos].inspect}" - end - end - - - desc 'total number of contributions for each user across all projects' - task :user_contributions do - contrib = {} - contributor_hash.each do |k,v| - contrib[k] = v[:repos].values.inject(0) {|result, x| result + x } - end - contrib.sort_by {|name, num| num }.reverse.each {|x| puts "#{x[0]}:#{x[1]}" } - end -end - - -namespace :github do - - desc 'pick a single pull request to test. Accepts the project name and number of PR to test' - # you can also specify the OPERATINGSYSTEM to test as an ENV variable - task :checkout_pull_request, [:project_name, :number] do |t, args| - checkout_pr( - args.project_name, - args.number, - [github_login] + github_admins, - 'schedule_for_testing', - { - :login => github_login, - :password => github_password - } - ) - end - -end - -namespace :test do - - desc 'run openstack puppet module unit tests' - task :unit do - command = "export MODULEPATH=#{base_dir}/modules;export GEM_HOME=#{base_dir}/.vendor;" - status = ['cinder', 'nova', 'glance', 'openstack', 'keystone', 'horizon', 'swift'].collect do |proj| - Dir.chdir("modules/#{proj}") do - local_command = command + "bundle exec rake spec_standalone" - puts local_command - system(local_command) - end - end.uniq - exit 1 if status != [true] - end - - desc 'reset test environment' - task :reset do - refresh_modules - destroy_all_vms - end - - desc 'Checkout fresh master environment and test a two node deployment' - task 'openstack_master' do - refresh_modules - system "bash -c 'rspec spec/test_two_node.rb;echo $?' 2>&1 | tee #{log_file}" - end - - desc 'Checkout fresh master environment and test the deployment of a swift cluster' - task 'swift_master' do - refresh_modules - system "bash -c 'rspec spec/test_swift_cluster.rb;echo $?' 2>&1 | tee #{log_file}" - end - - desc 'checkout a PR and test swift' - task 'swift_pull_request', [:repo_name, :pull_request_number] do |t, args| - test_pull_request( - args.repo_name, - args.pull_request_number, - github_admins, - github_login, - github_password, - 'spec/test_swift_cluster.rb', - log_file, - 'schedule_for_testing' - ) - end - - desc 'checkout and test a pull request, publish the results' - task 'pull_request', [:repo_name, :pull_request_number] do |t, args| - test_pull_request( - args.repo_name, - args.pull_request_number, - github_admins, - github_login, - github_password, - 'spec/test_two_node.rb', - log_file, - 'schedule_for_testing' - ) - end - - desc 'test openstack with basic test script on redhat and ubuntu' - task 'two_node' do - test_two_node(['redhat', 'ubuntu']) - end - - desc 'test swift cluster' - task 'swift_proxy' do - test_swift - end - - desc 'test all in one deployment on redhat/ubuntu (not yet implemented)' - task 'all_in_one' do - - end - - desc 'test that openstack can boot an image from the vagrant box' - task :controller do - on_box('openstack_controller', 'sudo bash /tmp/test_nova.sh;exit $?') - end -end diff --git a/Vagrantfile b/Vagrantfile index 2b91edb..7879110 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -48,41 +48,41 @@ Vagrant::Config.run do |config| 'ip1' => '172.16.0.14' } }, - {'nova_controller' => - { - 'memory' => 512, - 'ip1' => '172.16.0.5' - } - }, - {'glance' => - { - 'memory' => 512, - 'ip1' => '172.16.0.6' - } - }, - {'keystone' => - { - 'memory' => 512, - 'ip1' => '172.16.0.7' - } - }, - {'mysql' => - { - 'memory' => 512, - 'ip1' => '172.16.0.8' - } - }, - {'cinder' => - { - 'memory' => 512, - 'ip1' => '172.16.0.9' - } - }, - { 'quantum_agent' => { - 'memory' => 512, - 'ip1' => '172.16.0.10' - } - }, + #{'nova_controller' => + # { + # 'memory' => 512, + # 'ip1' => '172.16.0.5' + # } + #}, + #{'glance' => + # { + # 'memory' => 512, + # 'ip1' => '172.16.0.6' + # } + #}, + #{'keystone' => + # { + # 'memory' => 512, + # 'ip1' => '172.16.0.7' + # } + #}, + #{'mysql' => + # { + # 'memory' => 512, + # 'ip1' => '172.16.0.8' + # } + #}, + #{'cinder' => + # { + # 'memory' => 512, + # 'ip1' => '172.16.0.9' + # } + #}, + #{ 'quantum_agent' => { + # 'memory' => 512, + # 'ip1' => '172.16.0.10' + # } + #}, { 'swift_proxy' => { 'memory' => 512, 'ip1' => '172.16.0.21', diff --git a/lib/puppetlabs/os_tester.rb b/lib/puppetlabs/os_tester.rb deleted file mode 100644 index 652956c..0000000 --- a/lib/puppetlabs/os_tester.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# class that hold utilities that I use to test openstack -# -module Puppetlabs - module OsTester - - require 'yaml' - require 'github_api' - require 'open3' - # need to fix this lib stuff. its is lame :( - require 'puppetlabs/os_tester/system' - require 'puppetlabs/os_tester/git' - require 'puppetlabs/os_tester/github' - require 'puppetlabs/os_tester/librarian' - require 'puppetlabs/os_tester/openstack' - require 'puppetlabs/os_tester/swift' - - class TestException < Exception - end - - - include System - include Git - include Swift - include Openstack - include Github - include Librarian - end -end diff --git a/lib/puppetlabs/os_tester/git.rb b/lib/puppetlabs/os_tester/git.rb deleted file mode 100644 index 80ce693..0000000 --- a/lib/puppetlabs/os_tester/git.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'puppetlabs/os_tester/system' - -module Puppetlabs - module OsTester - - module Git - - include Puppetlabs::OsTester::System - - def git_cmd(cmd, print=true) - cmd_system('git ' + cmd, print) - end - # adds the specified remote name as a read/write remote - def dev_setup(remote_name) - each_repo do |module_name| - # need to handle more failure cases - remotes = git_cmd('remote') - if remotes.include?(remote_name) - puts "Did not have to add remote #{remote_name} to #{module_name}" - elsif ! remotes.include?('origin') - raise(TestException, "Repo #{module_name} has no remote called origin, failing") - else - remote_url = git_cmd('remote show origin').detect {|x| x =~ /\s+Push\s+URL: / } - if remote_url =~ /(git|https?):\/\/(.+)\/(.+)?\/(.+)/ - url = "git@#{$2}:#{remote_name}/#{$4}" - else - puts "remote_url #{remote_url} did not have the expected format. weird..." - end - puts "Adding remote #{remote_name} as #{url}" - git_cmd("remote add #{remote_name} #{url}") - end - end - end - - def pull_all - each_repo do |module_name| - puts "Pulling repo: #{module_name}" - puts ' ' + git_cmd('pull').join("\n ") - end - end - - def status_all - each_repo do |module_name| - status = git_cmd('status', false) - if status.include?('nothing to commit (working directory clean)') - puts "Module #{module_name} has not changed" if verbose - else - puts "Uncommitted changes for: #{module_name}" - puts " #{status.join("\n ")}" - end - end - end - - def check_tags(project_name=nil) - each_repo do |module_name| - require 'puppet' - if ! project_name || project_name == module_name - modulefile = File.join(Dir.getwd, 'Modulefile') - if File.exists?(modulefile) - print module_name - metadata = ::Puppet::ModuleTool::Metadata.new - ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile) - print ':' + metadata.version - branch_output = git_cmd('branch') - if branch_output.first =~ /\* (.+)/ - puts ":#{$1}" - puts ' ' + git_cmd("log #{metadata.version}..HEAD --oneline").join("\n ") - puts '' - else - puts ' ' + branch_output.join("\n ") - end - else - puts "#{module_name} does not have a Modulefile" - end - end - end - end - - end - - end -end diff --git a/lib/puppetlabs/os_tester/github.rb b/lib/puppetlabs/os_tester/github.rb deleted file mode 100644 index b5e4843..0000000 --- a/lib/puppetlabs/os_tester/github.rb +++ /dev/null @@ -1,250 +0,0 @@ - -require 'puppetlabs/os_tester/librarian' - -module Puppetlabs - module OsTester - - module Github - - include Puppetlabs::OsTester::Librarian - - # checkout a specified pull request and test it - # - # Parameters: - # repo_name:: - # short name of the repo to pull from (ex: nova, glance, ...) - # pull_request_number:: - # number of pull request to pull for testing - # github_login:: - # log in used for authentication. This user must specify the test message - # in the comments of this pull request. This is also the user that will - # post the test results. - # github_password:: - # password for github user. - # rspec_test:: - # file path for rspec file to use to test pull request. - # log_file:: - # location of log file where test results are written. - # TODO - get rid of this in favor of a real logger - # test_message:: - # message that indicates that a pull request can be tested. It should - # be written by the github user as a PR comment on the PR being tested. - def test_pull_request( - repo_name, - pull_request_number, - github_login, - github_password, - rspec_test, - log_file, - test_message = 'schedule_for_testing' - ) - # reset everthing to master - refresh_modules - checkout_pr( - repo_name, - pull_request_number, - [github_login], - test_message, - { - :login => github_login, - :password => github_password - } - ) - system "bash -c 'rspec #{rspec_test}; echo $?' 2>&1 | tee #{log_file}" - results = File.read(log_file) - publish_results( - repo_name, - pull_request_number, - results.split("\n").last == '0' ? 'passed' : 'failed', - results, - { - :login => github_login, - :password => github_password - } - ) - end - - # figure out if a certain pull request can be tested. - # Pull requests can only be tested if they have a comment - # that contains the speficied expected_body in a PR comment - # created by one of the approved admin. - # - # Parameters: - # pr:: - # pull request object to be verified. - # admin_users:: - # array of users who can approve pull requests for testing - # expected_body:: - # expected body of a message that means a PR can be tested. - def testable_pull_request?( - pr, - admin_users, - expected_body = 'test_it', - options = {} - ) - if ! pr['merged'] - if pr['mergeable'] - if pr['comments'] > 0 - comments = ::Github.new(options).issues.comments.all( - pr['base']['user']['login'], - pr['base']['repo']['name'], - pr['number'] - ) - puts 'going through comments' - comments.each do |comment| - if admin_users.include?(comment['user']['login']) - if comment['body'] == expected_body - return true - end - end - end - else - puts "PR: #{pr['number']} from #{pr['base']['repo']['name']} has no issue commments.\ - I will not test it. We only test things approved. - " - end - else - puts "PR: #{pr['number']} from #{pr['base']['repo']['name']} cannot be merged, will not test" - end - else - puts "PR: #{pr['number']} from #{pr['base']['repo']['name']} was already merged, will not test" - end - puts "Did not find comment matching #{expected_body}" - return false - end - - def checkedoutfile_name - '.current_testing' - end - - def checkedout_file - File.join(base_dir, checkedoutfile_name) - end - - def checkedout_branch - return @checkout_branch_results if @checkout_branch_results_results - co_file = checkedout_file - if File.exists?(co_file) - @checkout_branch_results = YAML.load_file(co_file) - else - @checkout_branch_results = {} - end - end - - def write_checkedout_file(project_name, number) - File.open(checkedout_file, 'w') do |fh| - fh.write({ - :project => project_name, - :number => number - }.to_yaml) - end - end - - def checkout_pr(project_name, number, admin_users, expected_body, options) - # but I should write some kind of repo select - # depends on https://github.com/peter-murach/github - require 'github_api' - - each_repo do |repo_name| - if repo_name == project_name - pr = ::Github.new(options).pull_requests.get('puppetlabs', "puppetlabs-#{project_name}", number) - # need to be able to override this? - if checkedout_branch[:project] - if checkedout_branch[:project] == project_name and checkedout_branch[:number] == number - puts "#{project_name}/#{number} already checkout out, not doing it again" - return - else - raise(TestException, "Wanted to checkout: #{project_name}/#{number}, but #{checkedout_branch[:project]}/#{checkedout_branch[:number]} was already checked out") - end - end - - if testable_pull_request?(pr, admin_users, expected_body, options) - clone_url = pr['head']['repo']['clone_url'] - remote_name = pr['head']['user']['login'] - sha = pr['head']['sha'] - - base_ref = pr['base']['ref'] - if base_ref != 'master' - raise(TestException, "At the moment, I do not support non-master base refs") - end - - unless (diffs = git_cmd("diff origin/master")) == [] - raise(TestException, "There are differences between the current checked out branch and master, you need to clean up these branhces before running any tests\n#{diffs.join("\n")}") - end - - write_checkedout_file(project_name, number) - puts 'found one that we should test' - # TODO I am not sure how reliable all of this is going - # to be - remotes = git_cmd('remote') - unless remotes.include?(remote_name) - git_cmd("remote add #{remote_name} #{clone_url}") - end - git_cmd("fetch #{remote_name}") - # TODO does that work if master has been updated? - git_cmd("merge #{sha}") - else - raise("pull request #{project_name}/#{number} is not testable") - end - end - end - end - - # publish a string as a gist. - # publish a link to that gist as a issue comment. - def publish_results(project_name, number, outcome, body, options) - require 'github_api' - github = ::Github.new(options) - gist_response = github.gists.create( - 'description' => "#{project_name}/#{number}@#{Time.now.strftime("%Y%m%dT%H%M%S%z")}", - 'public' => true, - 'files' => { - 'file1' => {'content' => body} - } - ) - comments = github.issues.comments.create( - 'puppetlabs', - "puppetlabs-#{project_name}", - number, - 'body' => "Test #{outcome}. Results can be found here: #{gist_response.html_url}" - ) - end - - def testable_pull_requests( - project_names, - admin_users, - github_login, - github_password, - test_message = 'schedule_for_testing' - ) - testable_pull_requests = {} - each_repo do |repo_name| - if project_names.include?(repo_name) - options = { :login => github_login, :password => github_password } - prs = ::Github.new(options).pull_requests.list('puppetlabs', "puppetlabs-#{repo_name}") - prs.each do |pr| - # the data structure of pr returned from list (above) appears to be in a different format - # than this get call, therefor, I need to get the number, and make this extra call. - # this seems to justify my experience so far that this github_api plugin may not be worth using. - number = pr['number'] - pr = ::Github.new(options).pull_requests.get('puppetlabs', "puppetlabs-#{repo_name}", number) - # I know this is lazy to do b/c it means every pull request will be validated twice based - # on the current workflow with jenkins (where this will populate parameterized builds - # that also check if the pull request is valid - if testable_pull_request?(pr, admin_users + github_login.to_a, test_message, options) - if testable_pull_requests[repo_name] - testable_pull_requests[repo_name].push(number) - else - testable_pull_requests[repo_name] = [number] - end - end - end - end - end - puts testable_pull_requests.inspect - end - - end # end Github - - end -end diff --git a/lib/puppetlabs/os_tester/librarian.rb b/lib/puppetlabs/os_tester/librarian.rb deleted file mode 100644 index 84925ae..0000000 --- a/lib/puppetlabs/os_tester/librarian.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'puppetlabs/os_tester/system' - -module Puppetlabs - module OsTester - - module Librarian - - include Puppetlabs::OsTester::System - - def refresh_modules - ['modules', '.librarian', 'Puppetfile.lock', '.tmp', checkedoutfile_name].each do |dir| - if File.exists?(File.join(base_dir, dir )) - FileUtils.rm_rf(File.join(base_dir, dir)) - end - end - FileUtils.rm(checkedout_file) if File.exists?(checkedout_file) - cmd_system('librarian-puppet install') - end - - def each_repo(&block) - require 'librarian/puppet' - require 'librarian/puppet/source/git' - # create a manifest - # TODO replace this to use librarian puppet - env = Librarian::Puppet::Environment.new() - # this is the lock file, so it assumes that install has been run - env.lock.manifests.each do |manifest| - # I only care about git sources - if manifest.source.is_a? Librarian::Puppet::Source::Git - module_name = manifest.name.split('/', 2)[1] - module_path = File.join(env.install_path,module_name) - if File.directory?(module_path) - Dir.chdir(module_path) do - yield module_name - end - else - puts "Module directory #{module_path} does not exist... How strange." - end - else - puts "Found a non-git manifest: #{manifest.class}, ignoring" - end - end - end - end - end -end diff --git a/lib/puppetlabs/os_tester/openstack.rb b/lib/puppetlabs/os_tester/openstack.rb deleted file mode 100644 index e16ebd0..0000000 --- a/lib/puppetlabs/os_tester/openstack.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'puppetlabs/os_tester/system' -require 'puppetlabs/os_tester/vagrant' - -module Puppetlabs - module OsTester - # given a pull request, return true if we should test it. - # this means that is can be merged, and has a comment where one of the admin users - - module Openstack - - include Puppetlabs::OsTester::System - include Puppetlabs::OsTester::Vagrant - - # deplpoy a controller/compute setup - def deploy_two_node - ['openstack_controller', 'compute1'].each do |vm| - vagrant_command('up', vm) - end - end - - # Test a controller compute setup. - # deletes all VMs in the current Vagrant project before - # building a 2 node openstack environment and firing off - # an integration test. - # - # == Parameters: - # oses:: - # A list of operatingsystems that should be tested on. - # - # == Returns: - # TODO document - def test_two_node(oses = []) - require 'yaml' - #Rake::Task['openstack:setup'.to_sym].invoke - oses.each do |os| - update_vagrant_os(os) - cmd_system('vagrant destroy -f') - deploy_two_node - # I should check this to see if the last line is cirros - on_box('openstack_controller', 'sudo bash /tmp/test_nova.sh;exit $?') - end - end - - # print a hash of all of the contributors - # == Parameters: - # repos_i_care_about:: - # An Array that specifies a list of repos to check the contributors for. - # - # == Returns: - # A hash that maps a user to a hash that contains its :email - # and a list of the specified repos that they have - # contribited to - # - def contributor_hash( - repos_i_care_about = ['nova', 'glance', 'openstack', 'keystone', 'swift', 'horizon', 'cinder'] - ) - contributors = {} - each_repo do |module_name| - if repos_i_care_about.include?(module_name) - logs = git_cmd('log --format=short', print=false) - user_lines = logs.select {|x| x =~ /^Author:\s+(.*)$/ } - user_lines.collect do |x| - if x =~ /^Author:\s+(.*)?\s+<((\S+)@(\S+))>$/ - unless ['root', 'vagrant', 'Dan'].include?($1) - if contributors[$1] - if contributors[$1][:repos][module_name] - contributors[$1][:repos][module_name] += 1 - else - contributors[$1][:repos][module_name] = 1 - end - else - contributors[$1] = {:email => $2, :repos => {module_name => 1} } - end - else - # trimming out extra users - end - else - puts "Skipping unexpected line #{x}" - end - end - end - end - contributors - end - end - end -end - diff --git a/lib/puppetlabs/os_tester/swift.rb b/lib/puppetlabs/os_tester/swift.rb deleted file mode 100644 index 33c9b40..0000000 --- a/lib/puppetlabs/os_tester/swift.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'puppetlabs/os_tester/system' -require 'puppetlabs/os_tester/vagrant' - -module Puppetlabs - module OsTester - # swift deployment methods - module Swift - - include Puppetlabs::OsTester::System - include Puppetlabs::OsTester::Vagrant - - def swift_nodes - [ - 'swift_storage_1', - 'swift_storage_2', - 'swift_storage_3', - 'swift_proxy', - 'swift_keystone' - ] - end - - def destroy_swift_vms - puts "About to destroy all swift vms..." - swift_nodes.each do |x| - cmd_system("vagrant destroy #{x} --force") - end - puts "Destroyed all swift vms" - begin - on_box('puppetmaster', 'export RUBYLIB=/etc/puppet/modules-0/ruby-puppetdb/lib/; puppet query node --only-active --deactivate --puppetdb_host=puppetmaster.puppetlabs.lan --puppetdb_port=8081 --config=/etc/puppet/puppet.conf --ssldir=/var/lib/puppet/ssl --certname=puppetmaster.puppetlabs.lan') - on_box('puppetmaster', 'rm /var/lib/puppet/ssl/*/swift*;rm /var/lib/puppet/ssl/ca/signed/swift*;') - rescue BoxNotCreated - end - end - - # deploys a 3 node swift cluster in parallel - def deploy_swift_cluster - vagrant_command('up', 'swift_keystone') - parallel_provision( - [ - 'swift_storage_1', - 'swift_storage_2', - 'swift_storage_3' - ] - ) - vagrant_command('up', 'swift_proxy') - parallel_provision( - [ - 'swift_storage_1', - 'swift_storage_2', - 'swift_storage_3' - ] - ) - end - - # test that our swift cluster if functional - def test_swift - on_box('swift_proxy', 'ruby /tmp/swift_test_file.rb;exit $?') - end - - # deploys a puppetmaster. this is required for deploying swift - def deploy_puppetmaster - vagrant_command('up', 'puppetmaster') - end - - end - end -end diff --git a/lib/puppetlabs/os_tester/system.rb b/lib/puppetlabs/os_tester/system.rb deleted file mode 100644 index f716b37..0000000 --- a/lib/puppetlabs/os_tester/system.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Puppetlabs - module OsTester - module System - - # Run a system command - # Parameters: - # cmd:: - # the command that needs to be executed. - # print:: - # if the returned output should be printed to stdout. - # Return: - # An array of the lines of stdout. - def cmd_system (cmd, print=true) - puts "Running cmd: #{Array(cmd).join(' ')}" if print - output = `#{cmd}`.split("\n") - puts output.join("\n") if print - raise(StandardError, "Cmd #{cmd} failed") unless $?.success? - #Open3.popen3(*cmd) do |i, o, e, t| - # output = o.read.split("\n") - # raise StandardError, e.read unless (t ? t.value : $?).success? - #end - output - end - end - end -end diff --git a/lib/puppetlabs/os_tester/vagrant.rb b/lib/puppetlabs/os_tester/vagrant.rb deleted file mode 100644 index 96d0be8..0000000 --- a/lib/puppetlabs/os_tester/vagrant.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'puppetlabs/os_tester/system' - -module Puppetlabs - module OsTester - # vagrant helper methods - module Vagrant - - include Puppetlabs::OsTester::System - - class BoxNotCreated < Exception - end - - # run a vagrant command - # Parameters: - # cmd:: - # vagrant command that should be run. - # box:: - # box that the command should be applied to. - # Return: - # TODO - figire out the return - def vagrant_command(cmd, box='') - require 'vagrant' - env = ::Vagrant::Environment.new(:ui_class => ::Vagrant::UI::Colored) - puts "Running #{cmd} on #{box ? box : 'all'}" - env.cli(cmd, box) - end - - # run a command on an image as sudo. return the output - # Parameters: - # box:: - # box that the command should be applied to. - # cmd:: - # command that should be run as sudo on the box. - # Returns: - # stdout from the executed ssh command. - # - # TODO make these two method argument lists consistent - def on_box (box, cmd) - require 'vagrant' - env = ::Vagrant::Environment.new(:ui_class => ::Vagrant::UI::Colored) - raise("Invalid VM: #{box}") unless vm = env.vms[box.to_sym] - raise(BoxNotCreated, "VM: #{box} was not already created") unless vm.created? - ssh_data = '' - #vm.channel.sudo(cmd) do |type, data| - vm.channel.sudo(cmd) do |type, data| - ssh_data = data - env.ui.info(ssh_data.chomp, :prefix => false) - end - ssh_data - end - - # destroy all vagrant images - def destroy_all_vms - puts "About to destroy all vms..." - vagrant_command('destroy -f') - puts "Destroyed all vms" - end - - # provision a list of vms in parallel - def parallel_provision(vms) - require 'thread' - results = {} - threads = [] - queue = Queue.new - vms.each {|vm| vagrant_command(['up', '--no-provision'], vm) } - vms.each do |vm| - threads << Thread.new do - result = cmd_system("vagrant provision #{vm}") - # I cant use a regular vagrant call - #result = vagrant_command('provision', vm) - queue.push({vm => {'result' => result}}) - end - end - threads.each do |aThread| - begin - aThread.join - rescue Exception => spawn_err - puts("Failed spawning vagrant provision thread: #{spawn_err}") - end - end - until queue.empty? - provision_results = queue.pop - results.merge!(provision_results) - end - results - end - - # update the operatingsystem in the vagrant conig file - def update_vagrant_os(os) - cfg = File.join(base_dir, 'config.yaml') - yml = YAML.load_file(cfg).merge({'operatingsystem' => os}) - File.open(cfg, 'w') {|f| f.write(yml.to_yaml) } - end - end - end -end