Sha256: d0e025a6305230d7e897c16ec49508f1e7ec5640ba6c52aa7b910758e89efaf9

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

namespace :katello do
  namespace :reset_backends do
    service_stop = "sudo /sbin/service %s status > /dev/null && sudo /sbin/service %s stop"
    service_start = "sudo /sbin/service %s start"

    task :pulp do
      SERVICES = %w(httpd pulp_workers pulp_resource_manager pulp_celerybeat).freeze
      system(service_stop.gsub("%s", "mongod"))

      SERVICES.each { |s| system(service_stop.gsub("%s", s)) }
      system("sudo rm -rf /var/lib/mongodb/pulp_database*")
      system(service_start.gsub("%s", "mongod"))
      sleep(10)
      fail "Cannot migrate pulp database" unless system("sudo -u apache /usr/bin/pulp-manage-db")
      SERVICES.each { |s| system(service_start.gsub("%s", s)) }
      puts "Pulp database reset."
    end

    task :candlepin do
      tomcat = File.exist?('/var/lib/tomcat') ? 'tomcat' : 'tomcat6'

      system(service_stop.gsub("%s", tomcat))
      system("sudo /usr/share/candlepin/cpdb --drop --create")
      system(service_start.gsub("%s", tomcat))
      puts "Candlepin database reset."
    end
  end

  task :reset_default_smart_proxy do
    User.current = User.anonymous_admin
    hostname = Socket.gethostname.chomp
    SmartProxy.where(name: hostname, url: "https://#{hostname}:9090").first_or_create!
  end

  desc "Resets Foreman/Katello development environemnt. WARNING: This will destroy all your Foreman and Katello data."
  task :reset_backends do
    Rake::Task['katello:reset_backends:candlepin'].invoke
    Rake::Task['katello:reset_backends:pulp'].invoke
  end

  task :reset => ['environment'] do
    ENV['SEED_ADMIN_PASSWORD'] ||= 'changeme'
    ENV['SEED_ORGANIZATION'] ||= 'Default Organization'
    ENV['SEED_LOCATION'] ||= 'Default Location'
    Rake::Task['katello:reset_backends'].invoke
    Rake::Task['db:drop'].invoke
    Rake::Task['db:create'].invoke

    # Otherwise migration and seeds fail because they require a reloaded environment
    system('rake db:migrate')
    system('rake db:seed')
    Rake::Task['katello:reset_default_smart_proxy'].invoke
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
katello-3.9.1 lib/katello/tasks/reset.rake
katello-3.9.0 lib/katello/tasks/reset.rake
katello-3.8.1 lib/katello/tasks/reset.rake
katello-3.9.0.rc2 lib/katello/tasks/reset.rake
katello-3.9.0.rc1 lib/katello/tasks/reset.rake
katello-3.7.1.1 lib/katello/tasks/reset.rake
katello-3.7.1 lib/katello/tasks/reset.rake
katello-3.8.0 lib/katello/tasks/reset.rake
katello-3.8.0.rc3 lib/katello/tasks/reset.rake
katello-3.8.0.rc2 lib/katello/tasks/reset.rake
katello-3.7.0 lib/katello/tasks/reset.rake
katello-3.8.0.rc1 lib/katello/tasks/reset.rake
katello-3.7.0.rc2 lib/katello/tasks/reset.rake
katello-3.7.0.rc1 lib/katello/tasks/reset.rake