Satellite 6: Sync Katello repos with Pulp repos

When you skip,unlock or delete a task in katello that caused a repository to be deleted or not created in pulp we get various strange behavior between the 2 sub systems of satellite 6. This mostly comes up when you are upgrading to a later version and is very difficult to debug. Mostly this shows a 404 Resource Not Found.

So solution for is to cleanup the repos present in Katello. Luckily we can do this via the foreman-rake console.

#foreman-rake console
User.current = User.first
::Katello::Repository.puppet_type.each do |repo|
  begin
    puts "Checking #{repo.name} - #{repo.id}"
    Katello.pulp_server.extensions.repository.retrieve_with_details(repo.pulp_id)
  rescue RestClient::ResourceNotFound
    puts "Deleting #{repo.name} - #{repo.id}"
    repo.destroy!
  end
end

::Katello::ContentViewPuppetEnvironment.all.each do |repo|
  begin
    puts "Checking #{repo.name} - #{repo.id}"
    Katello.pulp_server.extensions.repository.retrieve_with_details(repo.pulp_id)
  rescue RestClient::ResourceNotFound
    puts "Deleting #{repo.name} - #{repo.id}"
    repo.destroy!
  end
end

So basically we loop over every repo present in Katello and fetch the corresponding pulp repo. If this fails we delete it from Katello.