Project

General

Profile

« Previous | Next » 

Revision b2e94920

Added by David Davis about 10 years ago

Composite Content Views: Publish and yum content validation

View differences:

app/lib/katello/errors.rb
class ContentViewRepositoryOverlap < StandardError; end
class ContentViewDefinitionBadContent < StandardError; end
class ContentViewTaskInProgress < StandardError; end
class SystemGroupEmptyException < StandardError
app/models/katello/content_view.rb
has_many :content_view_components, :class_name => "Katello::ContentViewComponent", :dependent => :destroy
has_many :components, :through => :content_view_components, :class_name => "Katello::ContentViewVersion",
:source => :content_view_version
:source => :content_view_version do
def <<(*args)
# this doesn't go through validation and generate a nice error message
# for the API/UI to use
fail "Adding components without doing validation is not supported"
end
end
has_many :distributors, :class_name => "Katello::Distributor", :dependent => :restrict
has_many :content_view_repositories, :dependent => :destroy
......
:presence => true
validates :name, :presence => true, :uniqueness => {:scope => :organization_id}
validates :organization_id, :presence => true
validate :check_repo_conflicts
validates_with Validators::KatelloNameFormatValidator, :attributes => :name
validates_with Validators::KatelloLabelFormatValidator, :attributes => :label
......
where("#{Katello::ContentViewVersion.table_name}.content_view_id" => self.id)
end
def repositories_to_publish
if composite?
ids = components.flat_map { |version| version.repositories.archived }.map(&:id)
Repository.where(:id => ids)
else
repositories
end
end
def repositories_to_publish_ids
composite? ? repositories_to_publish.pluck(&:id) : repository_ids
end
def repos_in_product(env, product)
version = version(env)
if version
......
def publish_content(version, notify = false)
# 1. generate the version repositories
publish_version_content(version)
clone_overrides = self.repositories.select{|r| self.filters.applicable(r).empty?}
version.trigger_contents_changed(:cloned_repo_overrides => clone_overrides, :wait => true)
# 2. generate the library repositories
publish_library_yum_content(version)
......
# prepare the yum repos currently in the library for the publish
async_tasks = []
repos(organization.library).each do |repo|
if repository_ids.include?(repo.library_instance_id)
if repositories_to_publish_ids.include?(repo.library_instance_id)
repo.content_view_version_id = version.id
repo.save!
......
async_tasks = []
repos_to_filter = []
repositories.each do |repo|
repositories_to_publish.each do |repo|
# the repos from the content view are based upon initial synced repos, we need to
# determine if each of those repos has been cloned in library
library_clone = get_repo_clone(organization.library, repo).first
......
end
def publish_version_content(version)
repositories.non_puppet.each do |repo|
repositories_to_publish.each do |repo|
clone = repo.create_clone(:content_view => self, :version => version)
associate_yum_content(clone)
end
......
puppet_env = create_puppet_env(:content_view => self, :version => version)
associate_puppet_content(puppet_env)
end
clone_overrides = repositories_to_publish.select{|r| self.filters.applicable(r).empty?}
version.trigger_contents_changed(:cloned_repo_overrides => clone_overrides, :wait => true)
end
def ready_to_publish?
!has_puppet_repo_conflicts? && !has_repo_conflicts?
end
def duplicate_repositories
counts = repositories_to_publish.each_with_object(Hash.new(0)) do |repo, h|
h[repo.library_instance_id] += 1
end
ids = counts.select { |k, v| v > 1 }.keys
Repository.where(:id => ids)
end
def has_repo_conflicts?
# Check to see if there is a repo conflict in the component views. A
# conflict exists if the same repo exists in more than one of those
# component views.
if self.composite?
repos_hash = self.views_repos
repos_hash.each do |view_id, repo_ids|
repos_hash.each do |other_view_id, other_repo_ids|
return true if (view_id != other_view_id) && !repo_ids.intersection(other_repo_ids).empty?
end
end
self.composite? && duplicate_repositories.any?
end
def check_repo_conflicts
duplicate_repositories.each do |repo|
versions = components.with_library_repo(repo).uniq.map(&:name).join(", ")
msg = _("Repository conflict: '%{repo}' is in %{versions}.") % {repo: repo.name, versions: versions}
errors.add(:base, msg)
end
false
end
def has_puppet_repo_conflicts?
# Check to see if there is a puppet conflict in the component views. A
# conflict exists if more than one view has a puppet repo
if self.composite?
repos = content_view_components.map { |view| view.repos(organization.library) }.flatten
return repos.select(&:puppet?).length > 1
#repos = content_view_components.map { |view| view.repos(organization.library) }.flatten
#return repos.select(&:puppet?).length > 1
end
false
end
app/models/katello/content_view_version.rb
scope :default_view, joins(:content_view).where("#{Katello::ContentView.table_name}.default" => true)
scope :non_default_view, joins(:content_view).where("#{Katello::ContentView.table_name}.default" => false)
def self.with_library_repo(repo)
joins(:repositories).where("#{Katello::Repository.table_name}.library_instance_id" => repo)
end
def to_s
name
end
app/models/katello/repository.rb
scope :puppet_type, where(:content_type => PUPPET_TYPE)
scope :non_puppet, where("content_type != ?", PUPPET_TYPE)
scope :non_archived, where('environment_id is not NULL')
scope :archived, where('environment_id is NULL')
def organization
if self.environment
test/controllers/api/v2/content_views_controller_test.rb
def test_remove_components
version = @content_view.versions.first
composite = ContentView.find(katello_content_views(:composite_view))
composite.components << version
composite.components = [version]
refute_empty composite.components(true)
put :update, :id => composite.id, :component_ids => []
assert_empty composite.components(true)
test/fixtures/models/katello_content_view_environments.yml
cp_id: 4
environment_id: <%= ActiveRecord::Fixtures.identify(:library) %>
content_view_id: <%= ActiveRecord::Fixtures.identify(:library_view) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version_2) %>
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
......
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
dev_component_view_environment:
name: Component Published Dev view environment
label: 'dev/component_view_1'
cp_id: 7
environment_id: <%= ActiveRecord::Fixtures.identify(:dev) %>
content_view_id: <%= ActiveRecord::Fixtures.identify(:component_view_1) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_component_view_1_version) %>
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
candlepin_library_dev_cve:
name: Library and Dev Content View Environment
label: 'candlepin_library_dev_cve'
......
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:candlepin_library_dev_cv_version) %>
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
library_composite_view:
name: Published Library Composite Content View Environment
label: 'library/composite_view'
content_view_id: <%= ActiveRecord::Fixtures.identify(:composite_view) %>
cp_id: 9
environment_id: <%= ActiveRecord::Fixtures.identify(:library) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:composite_view_version_1) %>
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
test/fixtures/models/katello_content_view_repositories.yml
library_view_fedora_17_x86_64:
content_view_id: <%= ActiveRecord::Fixtures.identify(:library_view) %>
repository_id: <%= ActiveRecord::Fixtures.identify(:fedora_17_x86_64) %>
test/fixtures/models/katello_content_view_versions.yml
version: 1
# END TODO: REMOVE THESE TWO
library_view_version:
library_view_version_1:
content_view_id: <%= ActiveRecord::Fixtures.identify(:library_view) %>
version: 1
library_view_version_2:
content_view_id: <%= ActiveRecord::Fixtures.identify(:library_view) %>
version: 2
library_dev_view_version:
content_view_id: <%= ActiveRecord::Fixtures.identify(:library_dev_view) %>
version: 1
library_component_view1_version:
content_view_id: <%= ActiveRecord::Fixtures.identify(:component_view_1) %>
candlepin_library_dev_cv_version:
content_view_id: <%= ActiveRecord::Fixtures.identify(:candlepin_library_dev_cv) %>
version: 1
library_component_view2_version:
content_view_id: <%= ActiveRecord::Fixtures.identify(:component_view_2) %>
composite_view_version_1:
content_view_id: <%= ActiveRecord::Fixtures.identify(:composite_view) %>
version: 1
candlepin_library_dev_cv_version:
content_view_id: <%= ActiveRecord::Fixtures.identify(:candlepin_library_dev_cv) %>
version: 1
test/fixtures/models/katello_content_views.yml
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
organization_id: <%= ActiveRecord::Fixtures.identify(:organization2) %>
component_view_1:
name: Component view 1
label: component_view_1
default: false
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
organization_id: <%= ActiveRecord::Fixtures.identify(:empty_organization) %>
component_view_2:
name: Component view 2
label: component_view_2
default: false
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
organization_id: <%= ActiveRecord::Fixtures.identify(:empty_organization) %>
# end use with glue/candlepin tests
composite_view:
name: Composite view
test/fixtures/models/katello_repositories.yml
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_default_version) %>
fedora_17_x86_64_library_view:
name: Fedora 17 x86_64
pulp_id: 3
content_id: 1
label: fedora_17_x86_64_label
relative_path: '/ACME_Corporation/library/LibraryView/fedora_17_label'
environment_id: <%= ActiveRecord::Fixtures.identify(:library) %>
product_id: <%= ActiveRecord::Fixtures.identify(:fedora) %>
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version) %>
p_forge:
name: P Forge
pulp_id: 4
......
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:dev_default_version) %>
fedora_17_x86_64_library_view_1:
name: Fedora 17 x86_64
pulp_id: 3
content_id: 1
label: fedora_17_x86_64_label
library_instance: fedora_17_x86_64
relative_path: '/ACME_Corporation/library/LibraryView/fedora_17_label'
environment_id:
product_id: <%= ActiveRecord::Fixtures.identify(:fedora) %>
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version_1) %>
fedora_17_x86_64_library_view_2:
name: Fedora 17 x86_64
pulp_id: 3
content_id: 1
label: fedora_17_x86_64_label
library_instance: fedora_17_x86_64
relative_path: '/ACME_Corporation/library/LibraryView/fedora_17_label'
environment_id:
product_id: <%= ActiveRecord::Fixtures.identify(:fedora) %>
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version_2) %>
fedora_17_x86_64_library_view_2_library:
name: Fedora 17 x86_64
pulp_id: 3
content_id: 1
label: fedora_17_x86_64_label
library_instance: fedora_17_x86_64
relative_path: '/ACME_Corporation/library/LibraryView/fedora_17_label'
environment_id: <%= ActiveRecord::Fixtures.identify(:library) %>
product_id: <%= ActiveRecord::Fixtures.identify(:fedora) %>
gpg_key_id: <%= ActiveRecord::Fixtures.identify(:fedora_gpg_key) %>
content_view_version_id: <%= ActiveRecord::Fixtures.identify(:library_view_version_2) %>
fedora_17_unpublished:
name: Fedora 17 x86_64
pulp_id: 6
test/models/authorization/repository_authorization_test.rb
end
def test_deletable?
repository = Repository.find(katello_repositories(:fedora_17_x86_64_library_view))
repository = Repository.find(katello_repositories(:fedora_17_x86_64_library_view_1))
assert repository.deletable?
end
test/models/content_view_test.rb
def test_content_view_components
assert_raises(ActiveRecord::RecordInvalid) do
@library_dev_view.components << @library_view.versions.first
@library_dev_view.update_attributes!(:component_ids => [@library_view.versions.first.id])
end
component = ContentViewComponent.new(:content_view => @library_dev_view,
......
refute component.save
end
def test_repositories_to_publish
composite = ContentView.find(katello_content_views(:composite_view))
v1 = ContentViewVersion.find(katello_content_view_versions(:library_view_version_1))
composite.update_attributes(:component_ids => [v1.id])
repo_ids = composite.repositories_to_publish.map(&:library_instance_id)
assert_equal v1.content_view.repository_ids, repo_ids
repo = Repository.find(katello_repositories(:fedora_17_x86_64))
assert_equal [repo.id], @library_view.repositories_to_publish.map(&:id)
end
def test_repo_conflicts
composite = ContentView.find(katello_content_views(:composite_view))
v1 = ContentViewVersion.find(katello_content_view_versions(:library_view_version_1))
v2 = ContentViewVersion.find(katello_content_view_versions(:library_view_version_2))
refute composite.update_attributes(component_ids: [v1.id, v2.id])
assert_equal 1, composite.errors.count
assert composite.errors.full_messages.first =~ /^Repository conflict/
assert_raises(RuntimeError) do
composite.components << v1
end
end
def test_unique_environments
3.times do |i|
ContentViewVersion.create!(:version => i + 2,
test/models/repository_test.rb
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require File.expand_path("repository_base", File.dirname(__FILE__))
require File.expand_path("authorization/repository_authorization_test", File.dirname(__FILE__))
module Katello
class RepositoryCreateTest < RepositoryTestBase
......
end
def test_clone_repo_path_for_component
skip "TODO: Fix content views"
# validate that clone repo path for a component view does not include the component view label
@content_view_definition = katello_content_view_definition_bases(:composite_def)
dev = KTEnvironment.find(katello_environments(:dev).id)
cv = @content_view_definition.component_content_views.where(:label => "component_view_1").first
cve = ContentViewEnvironment.where(:environment_id => dev,
library = KTEnvironment.find(katello_environments(:library).id)
cv = ContentView.find(katello_content_views(:composite_view))
cve = ContentViewEnvironment.where(:environment_id => library,
:content_view_id => cv).first
relative_path = Repository.clone_repo_path(@fedora_17_x86_64, dev, cv)
relative_path = Repository.clone_repo_path(repository: @fedora_17_x86_64,
environment: library,
content_view: cv)
assert_equal "/#{cve.label}/library/fedora_17_label", relative_path
# archive path
version = stub(:version => 1)
relative_path = Repository.clone_repo_path(repository: @fedora_17_x86_64,
version: version,
content_view: cv)
assert_equal "/content_views/composite_view/1/library/fedora_17_label", relative_path
end
def test_blank_feed_url

Also available in: Unified diff