-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #24819 - Add support for hostgroup content facet
- Loading branch information
1 parent
015620a
commit 66b1f85
Showing
19 changed files
with
239 additions
and
101 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
22 changes: 11 additions & 11 deletions
22
app/lib/katello/validators/hostgroup_kickstart_repository_validator.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
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
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,19 @@ | ||
module Katello | ||
module Hostgroup | ||
class ContentFacet < Katello::Model | ||
audited :associated_with => :lifecycle_environment | ||
self.table_name = 'katello_hostgroup_content_facets' | ||
include Facets::HostgroupFacet | ||
|
||
belongs_to :kickstart_repository, :class_name => "::Katello::Repository", :foreign_key => :kickstart_repository_id, :inverse_of => :kickstart_hostgroup_content_facets | ||
|
||
belongs_to :content_view, :inverse_of => :hostgroup_content_facets, :class_name => "Katello::ContentView" | ||
belongs_to :lifecycle_environment, :inverse_of => :hostgroup_content_facets, :class_name => "Katello::KTEnvironment" | ||
belongs_to :content_source, :class_name => "::SmartProxy", :foreign_key => :content_source_id, :inverse_of => :hostgroup_content_facets | ||
|
||
validates_with Katello::Validators::ContentViewEnvironmentValidator | ||
validates_with Katello::Validators::HostgroupKickstartRepositoryValidator | ||
validates_with ::AssociationExistsValidator, attributes: [:content_source] | ||
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
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
16 changes: 16 additions & 0 deletions
16
db/migrate/20180904122343_create_hostgroup_content_facet.katello.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,16 @@ | ||
class CreateHostgroupContentFacet < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :katello_hostgroup_content_facets do |t| | ||
t.column :hostgroup_id, :integer, :null => false | ||
t.column :kickstart_repository_id, :integer, :null => true | ||
t.column :content_source_id, :integer, :null => true | ||
t.column :content_view_id, :integer, :null => true | ||
t.column :lifecycle_environment_id, :integer, :null => true | ||
end | ||
add_foreign_key :katello_hostgroup_content_facets, :katello_repositories, :column => :kickstart_repository_id | ||
add_foreign_key :katello_hostgroup_content_facets, :hostgroups, :column => :hostgroup_id | ||
add_foreign_key :katello_hostgroup_content_facets, :katello_content_views, :column => :content_view_id | ||
add_foreign_key :katello_hostgroup_content_facets, :smart_proxies, :name => "katello_hostgroup_content_facets_content_source_id_fk", :column => "content_source_id" | ||
add_foreign_key :katello_hostgroup_content_facets, :katello_environments, :column => :lifecycle_environment_id | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
db/migrate/20200514092553_move_katello_fields_from_hostgroups.katello.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,53 @@ | ||
class MoveKatelloFieldsFromHostgroups < ActiveRecord::Migration[6.0] | ||
def up | ||
if User.where(login: User::ANONYMOUS_ADMIN).exists? | ||
User.as_anonymous_admin do | ||
copy_data_from_hostgroup | ||
end | ||
end | ||
|
||
change_table :hostgroups do |table| | ||
table.remove( | ||
:content_source_id, | ||
:kickstart_repository_id, | ||
:content_view_id, | ||
:lifecycle_environment_id | ||
) | ||
end | ||
end | ||
|
||
def down | ||
change_table :hostgroups do |t| | ||
t.column :kickstart_repository_id, :integer, :null => true | ||
t.column :content_source_id, :integer, :null => true | ||
t.column :content_view_id, :integer, :null => true | ||
t.column :lifecycle_environment_id, :integer, :null => true | ||
end | ||
end | ||
|
||
def copy_data_from_hostgroup | ||
hg_table = ::Hostgroup.arel_table | ||
hostgroups = ::Hostgroup.unscoped.where( | ||
hg_table[:content_source_id].eq(nil) | ||
.and(hg_table[:kickstart_repository_id].eq(nil)) | ||
.and(hg_table[:content_view_id].eq(nil)) | ||
.and(hg_table[:lifecycle_environment_id].eq(nil)) | ||
.not) | ||
hostgroups.in_batches do |batch| | ||
batch.pluck( | ||
:id, | ||
:content_source_id, | ||
:kickstart_repository_id, | ||
:content_view_id, | ||
:lifecycle_environment_id | ||
).each do |hostgroup_id, content_source_id, kickstart_repository_id, content_view_id, lifecycle_environment_id| | ||
content_facet = ::Katello::Hostgroup::ContentFacet.find_or_create_by(hostgroup_id: hostgroup_id) | ||
content_facet.content_source_id = content_source_id | ||
content_facet.kickstart_repository_id = kickstart_repository_id | ||
content_facet.content_view_id = content_view_id | ||
content_facet.lifecycle_environment_id = lifecycle_environment_id | ||
content_facet.save! | ||
end | ||
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
Oops, something went wrong.