Skip to content

Commit

Permalink
Merge branch 'Katello:master' into push_repos_to_pulp
Browse files Browse the repository at this point in the history
  • Loading branch information
phess authored Apr 26, 2022
2 parents 8564221 + a26097c commit 479ba5d
Show file tree
Hide file tree
Showing 36 changed files with 623 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def setup_params
end

def check_airgapped
if @organization.cdn_configuration.airgapped?
if @organization.cdn_configuration.export_sync?
fail HttpErrors::BadRequest, _("Repositories are not available for enablement while CDN configuration is set to Air-gapped (disconnected).")
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/katello/cdn_configuration/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Update < Actions::EntryAction
def plan(cdn_configuration, options)
cdn_configuration.update!(options)

if cdn_configuration.upstream_server?
if cdn_configuration.network_sync?
resource = ::Katello::Resources::CDN::CdnResource.create(cdn_configuration: cdn_configuration)
resource.validate!
keypair = resource.debug_certificate
Expand All @@ -20,7 +20,7 @@ def plan(cdn_configuration, options)
roots.each do |root|
full_path = if cdn_configuration.redhat_cdn?
root.product.repo_url(root.library_instance.generate_content_path)
elsif cdn_configuration.upstream_server?
elsif cdn_configuration.network_sync?
resource.repository_url(content_label: root.content.label)
end
plan_action(::Actions::Katello::Repository::Update, root, url: full_path)
Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/candlepin/repository_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_repository
end

def validate!
return if katello_content_type == Repository::OSTREE_TYPE || product.organization.cdn_configuration.airgapped?
return if katello_content_type == Repository::OSTREE_TYPE || product.organization.cdn_configuration.export_sync?
substitutor.validate_substitutions(content, substitutions)
end

Expand Down Expand Up @@ -81,7 +81,7 @@ def prune_substitutions(subs, url)
end

def feed_url
return if product.organization.cdn_configuration.airgapped?
return if product.organization.cdn_configuration.export_sync?
@feed_url ||= if product.cdn_resource&.respond_to?(:repository_url)
product.cdn_resource.repository_url(content_label: content.label, arch: arch, major: version[:major], minor: version[:minor])
else
Expand Down
30 changes: 15 additions & 15 deletions app/models/katello/cdn_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ class CdnConfiguration < Katello::Model
include Encryptable
self.inheritance_column = nil
CDN_TYPE = 'redhat_cdn'.freeze
UPSTREAM_SERVER_TYPE = 'upstream_server'.freeze
AIRGAPPED_TYPE = 'airgapped'.freeze
NETWORK_SYNC = 'network_sync'.freeze
EXPORT_SYNC = 'export_sync'.freeze

TYPES = [CDN_TYPE, UPSTREAM_SERVER_TYPE, AIRGAPPED_TYPE].freeze
TYPES = [CDN_TYPE, NETWORK_SYNC, EXPORT_SYNC].freeze

belongs_to :organization, :inverse_of => :cdn_configuration

belongs_to :ssl_ca_credential, :class_name => "Katello::ContentCredential", :inverse_of => :ssl_ca_cdn_configurations

encrypts :password
validates :password, presence: true, if: :upstream_server?
validates :username, presence: true, if: :upstream_server?
validates :upstream_organization_label, presence: true, if: :upstream_server?
validates :password, presence: true, if: :network_sync?
validates :username, presence: true, if: :network_sync?
validates :upstream_organization_label, presence: true, if: :network_sync?

validates :url, presence: true, unless: :airgapped?
validates_with Validators::KatelloUrlFormatValidator, attributes: :url, unless: :airgapped?
validates :url, presence: true, unless: :export_sync?
validates_with Validators::KatelloUrlFormatValidator, attributes: :url, unless: :export_sync?
validates_with Validators::KatelloLabelFormatValidator, attributes: :upstream_organization_label, if: proc { upstream_organization_label.present? }
validate :non_redhat_configuration, if: :upstream_server?
validate :non_redhat_configuration, if: :network_sync?

before_validation :reset_fields

Expand All @@ -32,20 +32,20 @@ def redhat_cdn?
type == CDN_TYPE
end

def airgapped?
type == AIRGAPPED_TYPE
def export_sync?
type == EXPORT_SYNC
end

def upstream_server?
type == UPSTREAM_SERVER_TYPE
def network_sync?
type == NETWORK_SYNC
end

private

def reset_fields
return if upstream_server?
return if network_sync?

self.url = nil if airgapped?
self.url = nil if export_sync?
self.url ||= SETTINGS[:katello][:redhat_repository_url] if redhat_cdn?
self.username = nil
self.password = nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/purpose_sla_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Katello
class PurposeSlaStatus < HostStatus::Status
UNKNOWN = Katello::PurposeStatus::UNKNOWN
def self.status_name
N_('Service Level')
N_('Service level')
end

def self.humanized_name
Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/purpose_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.status_map
end

def self.status_name
N_('System Purpose')
N_('System purpose')
end

def self.humanized_name
Expand All @@ -31,7 +31,7 @@ def self.to_label(status)
when MISMATCHED
N_('Mismatched')
when NOT_SPECIFIED
N_('Not Specified')
N_('Not specified')
else
N_('Unknown')
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/root_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RootRepository < Katello::Model
validates_with Validators::KatelloLabelFormatValidator, :attributes => :label
validates_with Validators::KatelloNameFormatValidator, :attributes => :name
validates_with Validators::KatelloUrlFormatValidator, :attributes => :url,
:nil_allowed => proc { |repo| repo.custom? || repo.organization.cdn_configuration.airgapped? },
:nil_allowed => proc { |repo| repo.custom? || repo.organization.cdn_configuration.export_sync? },
:field_name => :url
validates_with Validators::RootRepositoryUniqueAttributeValidator, :attributes => :name
validates_with Validators::RootRepositoryUniqueAttributeValidator, :attributes => :label
Expand Down
2 changes: 1 addition & 1 deletion app/services/katello/pulp3/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def ssl_remote_options
client_key: root.product.key,
ca_cert: Katello::Repository.feed_ca_cert(root.url)
}
elsif root.redhat? && root.cdn_configuration.upstream_server?
elsif root.redhat? && root.cdn_configuration.network_sync?
{
client_cert: root.cdn_configuration.ssl_cert,
client_key: root.cdn_configuration.ssl_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ attributes :upgradable? => :upgradable
attributes :install_status => :install_status

glue(@object.available_module_stream) do
attributes :name, :stream, :module_spec
attributes :id, :name, :stream, :module_spec
end
13 changes: 9 additions & 4 deletions db/migrate/20220124191056_add_type_to_cdn_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
class AddTypeToCdnConfiguration < ActiveRecord::Migration[6.0]
class FakeCdnConfiguration < Katello::Model
self.table_name = 'katello_cdn_configurations'
self.inheritance_column = nil
end

def change
add_index :katello_cdn_configurations, :organization_id, unique: true
add_column :katello_cdn_configurations, :type, :string, default: ::Katello::CdnConfiguration::CDN_TYPE
add_column :katello_cdn_configurations, :type, :string, default: 'redhat_cdn'

::Katello::CdnConfiguration.reset_column_information
::Katello::CdnConfiguration.all.each do |config|
FakeCdnConfiguration.reset_column_information
FakeCdnConfiguration.all.each do |config|
unless config.username.blank? ||
config.password.blank? ||
config.upstream_organization_label.blank? ||
config.ssl_ca_credential_id.blank?
config.update!(type: ::Katello::CdnConfiguration::UPSTREAM_SERVER_TYPE)
config.update!(type: 'upstream_server')
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion db/migrate/20220303160220_remove_duplicate_errata.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class RemoveDuplicateErrata < ActiveRecord::Migration[6.0]
def up
def up # rubocop:disable Metrics/MethodLength
#Update all unique errata records to have pulp_id = errata_id
::Katello::Erratum.group(:errata_id).having("count(errata_id) = 1").pluck(:errata_id).each do |original_errata_id|
erratum = ::Katello::Erratum.find_by(errata_id: original_errata_id)
Expand All @@ -24,6 +24,13 @@ def up
repo_erratum.update(erratum_id: errata_to_keep.id)
end
end
::Katello::ContentFacetErratum.where(erratum_id: dup_errata&.map(&:id)).each do |host_erratum|
if ::Katello::ContentFacetErratum.find_by(content_facet_id: host_erratum.content_facet_id, erratum_id: errata_to_keep.id)
host_erratum.delete
else
host_erratum.update(erratum_id: errata_to_keep.id)
end
end
dup_errata_ids = dup_errata&.pluck(:id)
if dup_errata_ids&.present?
::Katello::ErratumPackage.where(:erratum_id => dup_errata_ids).delete_all
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20220405220616_update_cdn_configuration_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class UpdateCdnConfigurationType < ActiveRecord::Migration[6.0]
class FakeCdnConfiguration < Katello::Model
self.table_name = 'katello_cdn_configurations'
self.inheritance_column = nil
end

def change
FakeCdnConfiguration.where(type: 'upstream_server').update_all(type: 'network_sync')
FakeCdnConfiguration.where(type: 'airgapped').update_all(type: 'export_sync')
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h4 translate>Sync Settings</h4>
</span>

<span ng-if="repository.content_type == 'deb'">
<dt translate>Releases</dt>
<dt translate>Releases/Distributions</dt>
<dd bst-edit-text="repository.deb_releases"
on-save="save(repository)"
readonly="denied('edit_products', product)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ angular.module('Bastion.repositories').controller('NewRepositoryController',

$scope.debURLPopover = $sce.trustAsHtml("For standard Debian repos, this is the folder that contains the \"dists/\" and the \"pool/\" subfolders.");

$scope.distPopover = $sce.trustAsHtml("A \"distribution\" provides the path from the repository root to the \"Release\" file <br/>" +
"you want to access. Each distribution in the list should use /etc/apt/sources.list<br/>" +
"syntax. For most official Debian and Ubuntu repositories, the distribution is equal<br/>" +
"to either the codename or the suite. When syncing a repo using flat repository format<br/>" +
"specify exactly one distribution, which must end with a \"/\".");
$scope.distPopover = $sce.trustAsHtml("A \"distribution\" provides the path from the repository root to the \"Release\" file you want to access. Each<br/>" +
"distribution in the list should use /etc/apt/sources.list syntax. For most official Debian and Ubuntu repositories,<br/>" +
"the distribution is equal to either the codename or the suite. Upstream repos that do not contain a \"dists/\" <br>" +
"folder may be using the deprecated \"flat repository format\".<br>" +
"(See: https://wiki.debian.org/DebianRepository/Format#Flat_Repository_Format).<br>" +
"When syncing a repo using flat repository format specify exactly one distribution, which must end with a \"/\". When<br>" +
"syncing repositories that do not use \"flat repository format\" you must not use a trailing \"/\" for your distributions! <br>");

$scope.componentPopover = $sce.trustAsHtml("Requesting a component that does not exist in the upstream repo, will result in <br/>" +
"a Pulp warning, but no error. A typo can therefore result in missing content.");
Expand Down
8 changes: 4 additions & 4 deletions test/actions/katello/cdn_configuration/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def keypair

def test_plans_katello_cdn
attrs = {
type: Katello::CdnConfiguration::UPSTREAM_SERVER_TYPE,
type: Katello::CdnConfiguration::NETWORK_SYNC,
url: 'http://newcdn.example.com',
ssl_ca_credential_id: @credential.id,
username: 'test_username',
Expand Down Expand Up @@ -87,15 +87,15 @@ def test_plans_redhat_cdn

def test_plans_airgapped
attrs = {
type: ::Katello::CdnConfiguration::AIRGAPPED_TYPE
type: ::Katello::CdnConfiguration::EXPORT_SYNC
}
refute @cdn_configuration.airgapped?
refute @cdn_configuration.export_sync?
refute_nil @cdn_configuration.url

plan_action(@action, @cdn_configuration, attrs)
@cdn_configuration.reload

assert @cdn_configuration.airgapped?
assert @cdn_configuration.export_sync?
assert_nil @cdn_configuration.url
assert_nil @cdn_configuration.ssl_cert
assert_nil @cdn_configuration.ssl_key
Expand Down
4 changes: 2 additions & 2 deletions test/factories/cdn_configuration_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
factory :katello_cdn_configuration, :class => Katello::CdnConfiguration do
url { Katello::Resources::CDN::CdnResource.redhat_cdn_url }
trait :upstream_server do
type { ::Katello::CdnConfiguration::UPSTREAM_SERVER_TYPE }
type { ::Katello::CdnConfiguration::NETWORK_SYNC }
end

trait :airgapped do
type { ::Katello::CdnConfiguration::AIRGAPPED_TYPE }
type { ::Katello::CdnConfiguration::EXPORT_SYNC }
end

trait :redhat_cdn do
Expand Down
2 changes: 1 addition & 1 deletion test/models/candlepin/repository_mapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_unprotected_suse
end

def test_airgapped_no_http
@product_content.product.organization.cdn_configuration.update!(type: ::Katello::CdnConfiguration::AIRGAPPED_TYPE)
@product_content.product.organization.cdn_configuration.update!(type: ::Katello::CdnConfiguration::EXPORT_SYNC)
mapper = Candlepin::RepositoryMapper.new(@product_content.product, @product_content.content, {})
mapper.expects(:substitutor).never
mapper.validate!
Expand Down
8 changes: 4 additions & 4 deletions test/models/cdn_configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def test_types_updated_correctly
config = org.cdn_configuration
assert config.redhat_cdn?

config.update!(type: ::Katello::CdnConfiguration::UPSTREAM_SERVER_TYPE,
config.update!(type: ::Katello::CdnConfiguration::NETWORK_SYNC,
username: 'Foo',
password: 'great',
upstream_organization_label: 'GreatOrg',
url: 'http://foo.com',
ssl_ca_credential_id: content_credential.id)

assert config.upstream_server?
assert config.network_sync?

# Now update back to airgapped
config.update!(type: ::Katello::CdnConfiguration::AIRGAPPED_TYPE)
assert config.airgapped?
config.update!(type: ::Katello::CdnConfiguration::EXPORT_SYNC)
assert config.export_sync?
assert_empty config.url
assert_empty config.username
assert_empty config.password
Expand Down
2 changes: 1 addition & 1 deletion test/models/purpose_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_status_not_specified
status.status = status.to_status

assert_equal Katello::PurposeStatus::NOT_SPECIFIED, status.status
assert_equal 'Not Specified', status.to_label
assert_equal 'Not specified', status.to_label
end

def test_status_matched
Expand Down
2 changes: 1 addition & 1 deletion test/models/root_repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def test_nil_rhel_url

def test_nil_rhel_url_on_airgapped
rhel = katello_root_repositories(:rhel_6_x86_64_root)
rhel.organization.cdn_configuration.update!(type: :airgapped)
rhel.organization.cdn_configuration.update!(type: :export_sync)
rhel.url = nil
assert rhel.valid?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function HostInstallableErrata({
<GridItem rowSpan={1} md={6} lg={4} xl2={3} >
<Card isHoverable>
<CardHeader>
<CardTitle>{__('Installable Errata')}</CardTitle>
<CardTitle>{__('Installable errata')}</CardTitle>
</CardHeader>
<CardBody>
<Flex direction="column">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import { List, ListItem } from '@patternfly/react-core';
import CardTemplate from 'foremanReact/components/HostDetails/Templates/CardItem/CardTemplate';

const InstalledProductsCard = ({ isExpandedGlobal, hostDetails }) => {
const installedProducts = hostDetails?.subscription_facet_attributes?.installed_products;
if (!installedProducts?.length) return null;
return (
<CardTemplate
overrideGridProps={{ rowSpan: 2 }}
header={__('Installed products')}
expandable
isExpandedGlobal={isExpandedGlobal}
>
<List isPlain>
{installedProducts.map(product => (
<ListItem key={product.productId}>
{product.productName}
</ListItem>
))}
</List>
</CardTemplate>
);
};

InstalledProductsCard.propTypes = {
isExpandedGlobal: PropTypes.bool,
hostDetails: PropTypes.shape({
subscription_facet_attributes: PropTypes.shape({
installed_products: PropTypes.arrayOf(PropTypes.shape({
productId: PropTypes.string,
productName: PropTypes.string,
})),
}),
}),
};

InstalledProductsCard.defaultProps = {
isExpandedGlobal: false,
hostDetails: {},
};

export default InstalledProductsCard;
Loading

0 comments on commit 479ba5d

Please sign in to comment.