forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #17148: Allow searching for hypervisors
- Loading branch information
Showing
10 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20170122204325_add_hypervisor_to_subscription_facets.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddHypervisorToSubscriptionFacets < ActiveRecord::Migration | ||
def change | ||
add_column :katello_subscription_facets, :hypervisor, :boolean, :default => false | ||
add_column :katello_subscription_facets, :hypervisor_host_id, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# !!! PLEASE KEEP THIS SCRIPT IDEMPOTENT !!! | ||
# | ||
|
||
Bookmark.without_auditing do | ||
bookmarks = [ | ||
{:name => "list hypervisors", :query => 'hypervisor = true', :controller => "hosts"} | ||
] | ||
|
||
bookmarks.each do |input| | ||
next if audit_modified? Bookmark, input[:name], :controller => input[:controller] | ||
b = Bookmark.find_or_create_by({ :public => true }.merge(input)) | ||
fail "Unable to create bookmark: #{format_errors b}" if b.nil? || b.errors.any? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
lib/katello/tasks/update_subscription_facet_backend_data.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace :katello do | ||
task :update_subscription_facet_backend_data => ["environment"] do | ||
def error(message) | ||
@errors << message | ||
@errors << "\n" | ||
end | ||
|
||
def report_errors | ||
if @errors.any? | ||
filename = "subscription_facet_upgrade-#{Time.now.to_i}.log" | ||
path = "/var/log/foreman/#{filename}" | ||
path = "/tmp/#{filename}" unless File.writable?(path) | ||
|
||
file = File.open(path, 'w') | ||
@errors.each { |error| file.write(error) } | ||
file.close | ||
$stderr.print "***********************************\n" | ||
$stderr.print "*************WARNING***************\n" | ||
$stderr.print "Errors detected during upgrade step.\n" | ||
$stderr.print "Details saved to: #{file.path}\n" | ||
$stderr.print "This step can be rerun with:\n" | ||
$stderr.print " foreman-rake katello:update_subscription_facet_backend_data\n" | ||
$stderr.print "You are likely encountering a bug.\n" | ||
$stderr.print "***********************************\n" | ||
end | ||
end | ||
|
||
@errors ||= [] | ||
User.current = User.anonymous_api_admin | ||
puts _("Updating backend data for subscription facets") | ||
|
||
#there may be some invalid hosts, if there are create a primary interface | ||
::Host.includes(:interfaces).find_each do |host| | ||
if host.primary_interface.nil? | ||
host.interfaces.create!(:primary => true) | ||
end | ||
end | ||
|
||
Katello::Host::SubscriptionFacet.find_each do |subscription_facet| | ||
begin | ||
candlepin_attrs = subscription_facet.candlepin_consumer.consumer_attributes | ||
subscription_facet.import_database_attributes(candlepin_attrs) | ||
subscription_facet.host = ::Host::Managed.find(subscription_facet.host_id) | ||
subscription_facet.save! | ||
|
||
host = subscription_facet.host | ||
host.name = ::Katello::Host::SubscriptionFacet.sanitize_name(host.name) | ||
host.save! if host.name_changed? | ||
|
||
Katello::Host::SubscriptionFacet.update_facts(subscription_facet.host, candlepin_attrs[:facts]) | ||
rescue StandardError => exception | ||
error("Error: #{subscription_facet.host.name} - #{subscription_facet.host.id}") | ||
error(candlepin_attrs) | ||
error(exception.message) | ||
error(exception.backtrace.join("\n")) | ||
error("\n") | ||
end | ||
end | ||
report_errors | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace :katello do | ||
namespace :upgrades do | ||
namespace '3.3' do | ||
task :hypervisors => ["katello:update_subscription_facet_backend_data"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters