Skip to content

Commit

Permalink
[CP] - Cherry picks for 4.6rc2 (#10255)
Browse files Browse the repository at this point in the history
* Fixes #35336 - System purpose card should not show when host is unregistered (#10224)

* Fixes #35336 - System purpose card should not show when host is unregistered

* Refs #35336 - fix tests

* Refs #35336 - also hide HW Properties card

(cherry picked from commit 64d5fb7)

* Fixes #35290 - Katello rpm search via nvra also (#10214)

Add scoped_search on nvra. This helps user experience when filename does
not follow NVRA pattern.

Signed-off-by: Pavel Moravec <[email protected]>
(cherry picked from commit d4188e5)

* Fixes #35295 - Details tab cards - Switch to masonry card layout instead of square grid (#10216)

(cherry picked from commit bc1304b)

* Fixes #35367 - Add legacy ch host ui button to new host page (#10235)

(cherry picked from commit dc10b82)

* Fixes #35369 - Moved the syncable repo exports to a different cv (#10237)

Whenever we do an export repository or library we would
1) Find or Create the associated repo/library cv
2) Publish the version
3) Export the published version in a syncable format

With the addition of syncable format we do the same.
This has some unintended consequences
For example
1) Export the repository in an importable format
2) Update the repository contents
3) Now export the same repo in syncable format
4) Finally do an incremental export of the same repo
Notice that it has 0 content to export. That is because it is
incrementally exporting between the repo state in 3 and 4 instead of 1
and 4

This commit fixes this by making the syncable exports happen in an
entirely different content view, so that syncable and non syncable
exports are not mixed.

(cherry picked from commit 7195abf)

* Fixes #35247 - Can Import/Export docker content (#10204)

(cherry picked from commit 877546b)

* Fixes #35368 - Prevent multiple envs in host registration (#10236)

(cherry picked from commit bb5d05d)

* Fixes #35382 - Add rake task to refresh repos on all pulp proxies (#10242)

Co-authored-by: Joniel Pasqualetto [email protected]
(cherry picked from commit 21107ca)

* Fixes #35341 - Unpin faraday (#10226)

This reverts commit 64b10e9. The
individual pulp gems have Faraday pins and makes this redundant. It only
hinders updating to Faraday.

(cherry picked from commit 9558eb9)

* Update release to 4.6.rc2

* Update Changelog

Co-authored-by: Jeremy Lenz <[email protected]>
Co-authored-by: Pavel Moravec <[email protected]>
Co-authored-by: Chris Roberts <[email protected]>
Co-authored-by: Partha Aji <[email protected]>
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
  • Loading branch information
6 people authored Aug 29, 2022
1 parent 447ea2f commit 91030e1
Show file tree
Hide file tree
Showing 26 changed files with 219 additions and 93 deletions.
130 changes: 68 additions & 62 deletions CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def find_content_view_environment

if params.key?(:environment_id)
environment = get_content_view_environment("cp_id", params[:environment_id])
elsif params.key?(:environments)
fail HttpErrors::BadRequest, _('Multiple environments are not supported.') if params['environments'].length > 1
environment = get_content_view_environment("cp_id", params['environments'].first['id'])
elsif params.key?(:organization_id) && !params.key?(:environment_id)
organization = Organization.current
environment = organization.library.content_view_environment
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/katello/api/v2/content_views_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def index

def index_relation
content_views = ContentView.readable
content_views = content_views.not_generated_for_repository unless Foreman::Cast.to_bool(params[:include_generated])
content_views = content_views.ignore_generated unless Foreman::Cast.to_bool(params[:include_generated])
content_views = content_views.where(:organization_id => @organization.id) if @organization
content_views = content_views.in_environment(@environment) if @environment
content_views = ::Foreman::Cast.to_bool(params[:nondefault]) ? content_views.non_default : content_views.default if params[:nondefault]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def plan(organization, destination_server: nil,
format: ::Katello::Pulp3::ContentViewVersion::Export::IMPORTABLE)
action_subject(organization)
validate_repositories_immediate!(organization) if fail_on_missing_content

content_view = ::Katello::Pulp3::ContentViewVersion::Export.find_library_export_view(destination_server: destination_server,
organization: organization,
create_by_default: true)
create_by_default: true,
format: format)
repo_ids_in_library = organization.default_content_view_version.repositories.exportable.immediate_or_none.pluck(:id)
content_view.update!(repository_ids: repo_ids_in_library)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def plan(repository,

content_view = ::Katello::Pulp3::ContentViewVersion::Export.find_repository_export_view(
repository: repository,
create_by_default: true)
create_by_default: true,
format: format)
content_view.update!(repository_ids: [repository.library_instance_or_self.id])

sequence do
Expand Down
12 changes: 9 additions & 3 deletions app/models/katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ class ContentView < Katello::Model
scope :non_composite, -> { where(:composite => [nil, false]) }
scope :generated, -> { where.not(:generated_for => :none) }
scope :generated_for_repository, -> { where(:generated_for => [:repository_export, :repository_import]) }
scope :not_generated_for_repository, -> { where.not(id: generated_for_repository) }

scope :ignore_generated, -> {
where.not(:generated_for => [:repository_export,
:repository_import,
:library_export_syncable,
:repository_export_syncable])
}
scope :generated_for_library, -> { where(:generated_for => [:library_export, :library_import]) }

scoped_search :on => :name, :complete_value => true
Expand All @@ -104,7 +108,9 @@ class ContentView < Katello::Model
library_export: 1,
repository_export: 2,
library_import: 3,
repository_import: 4
repository_import: 4,
library_export_syncable: 5,
repository_export_syncable: 6
}, _prefix: true

set_crud_hooks :content_view
Expand Down
6 changes: 3 additions & 3 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Repository < Katello::Model
ANSIBLE_COLLECTION_TYPE = 'ansible_collection'.freeze
GENERIC_TYPE = 'generic'.freeze

EXPORTABLE_TYPES = [YUM_TYPE, FILE_TYPE, ANSIBLE_COLLECTION_TYPE].freeze
EXPORTABLE_TYPES = [YUM_TYPE, FILE_TYPE, ANSIBLE_COLLECTION_TYPE, DOCKER_TYPE].freeze

define_model_callbacks :sync, :only => :after

Expand Down Expand Up @@ -341,7 +341,7 @@ def content_counts

def published_in_versions
Katello::ContentViewVersion.with_repositories(self.library_instances_inverse)
.where(content_view_id: Katello::ContentView.not_generated_for_repository).distinct
.where(content_view_id: Katello::ContentView.ignore_generated).distinct
end

def self.errata_with_package_counts(repo)
Expand Down Expand Up @@ -668,7 +668,7 @@ def node_syncable?

def self.smart_proxy_syncable
joins(:content_view_version => :content_view).
merge(ContentView.not_generated_for_repository).
merge(ContentView.ignore_generated).
where.not(environment_id: nil)
end

Expand Down
1 change: 1 addition & 0 deletions app/models/katello/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Rpm < Katello::Model
scoped_search :on => :evr, :ext_method => :scoped_search_evr, :only_explicit => true
scoped_search :on => :filename, :complete_value => true
scoped_search :on => :sourcerpm, :complete_value => true
scoped_search :on => :nvra, :complete_value => true
scoped_search :on => :modular, :complete_value => true, :only_explicit => true
scoped_search :on => :checksum

Expand Down
4 changes: 0 additions & 4 deletions app/services/katello/pulp3/api/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def self.api_exception_class
def self.repository_sync_url_class(repository_type)
repository_type.repo_sync_url_class
end

def self.add_remove_content_class
fail NotImplementedError
end
end
end
end
Expand Down
29 changes: 23 additions & 6 deletions app/services/katello/pulp3/content_view_version/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,38 @@ def format

def self.find_library_export_view(create_by_default: false,
destination_server:,
organization:)
organization:,
format: IMPORTABLE)
if format == IMPORTABLE
generated_for = :library_export
name = ::Katello::ContentView::EXPORT_LIBRARY
else
generated_for = :library_export_syncable
name = "#{::Katello::ContentView::EXPORT_LIBRARY}-SYNCABLE"
end

find_generated_export_view(create_by_default: create_by_default,
destination_server: destination_server,
organization: organization,
name: ::Katello::ContentView::EXPORT_LIBRARY,
generated_for: :library_export)
name: name,
generated_for: generated_for)
end

def self.find_repository_export_view(create_by_default: false,
repository:)
repository:,
format: IMPORTABLE)
if format == IMPORTABLE
generated_for = :repository_export
name = "Export-#{repository.label}-#{repository.library_instance_or_self.id}"
else
generated_for = :repository_export_syncable
name = "Export-SYNCABLE-#{repository.label}-#{repository.library_instance_or_self.id}"
end
find_generated_export_view(create_by_default: create_by_default,
destination_server: nil,
organization: repository.organization,
name: "Export-#{repository.label}-#{repository.library_instance_or_self.id}",
generated_for: :repository_export)
name: name,
generated_for: generated_for)
end

def self.generate_product_repo_strings(repositories:)
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 @@ -299,7 +299,7 @@ def copy_all(source_repository, options = {})
tasks << api.repositories_api.modify(repository_reference.repository_href, remove_content_units: ['*'])
end

if options[:mirror]
if options[:mirror] && api.class.respond_to?(:add_remove_content_class)
data = api.class.add_remove_content_class.new(
base_version: source_repository.version_href)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ child @lifecycle_environments => :lifecycle_environments do
end

node :content_views do |env|
env.content_views.not_generated_for_repository.map do |content_view|
env.content_views.ignore_generated.map do |content_view|
attributes = {
:id => content_view.id,
:label => content_view.label,
Expand Down
2 changes: 1 addition & 1 deletion app/views/katello/api/v2/organizations/show.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ node(:content_view_components_count) do
in_organization(Organization.current)&.
non_composite&.
non_default&.
not_generated_for_repository&.count
ignore_generated&.count
end

node :library_id do |org|
Expand Down
1 change: 0 additions & 1 deletion katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Gem::Specification.new do |gem|
gem.add_dependency "anemone"

#pulp3
gem.add_dependency "faraday", "< 1.9"
gem.add_dependency "pulpcore_client", ">= 3.18.0", "< 3.19.0"
gem.add_dependency "pulp_file_client", ">= 1.10.0", "< 1.11.0"
gem.add_dependency "pulp_ansible_client", ">= 0.13.1", "< 0.14"
Expand Down
8 changes: 8 additions & 0 deletions lib/katello/tasks/refresh_repos.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace :katello do
desc 'Refresh all repositories in all smart proxies and main server'
task :refresh_repos => ["environment", "dynflow:client"] do
User.current = User.anonymous_api_admin
::ForemanTasks.async_task(::Actions::BulkAction, ::Actions::Pulp3::Orchestration::Repository::RefreshRepos, SmartProxy.all)
puts _("Repos are being refreshed in the background.")
end
end
2 changes: 1 addition & 1 deletion lib/katello/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Katello
VERSION = "4.6.0.rc1".freeze
VERSION = "4.6.0.rc2".freeze
end
21 changes: 21 additions & 0 deletions test/controllers/api/rhsm/candlepin_proxies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ module Katello
assert_response :success
end

it "should register with new environments param" do
Resources::Candlepin::Consumer.stubs(:get)

::Katello::RegistrationManager.expects(:process_registration).with({'facts' => @facts }, @content_view_environment).returns(@host)

post(:consumer_create, params: { :organization_id => @content_view_environment.content_view.organization.label, :environments => [{id: @content_view_environment.cp_id}], :facts => @facts })

assert_response :success
end

it "should not register with multiple envs" do
::Katello::RegistrationManager.expects(:process_registration).never

post(:consumer_create, params: { :organization_id => @content_view_environment.content_view.organization.label, :environments => [{id: @content_view_environment.cp_id}, {id: @content_view_environment.cp_id}], :facts => @facts })

body = JSON.parse(response.body)

assert_equal 'Multiple environments are not supported.', body['displayMessage']
assert_response 400
end

it "should not register" do
::Katello::RegistrationManager.expects(:check_registration_services).returns(false)
::Katello::RegistrationManager.expects(:process_registration).never
Expand Down
18 changes: 18 additions & 0 deletions test/lib/tasks/refresh_repos_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'katello_test_helper'
require 'rake'

module Katello
class RefreshReposTest < ActiveSupport::TestCase
def setup
Rake.application.rake_require 'katello/tasks/refresh_repos'
Rake::Task['katello:refresh_repos'].reenable
Rake::Task.define_task(:environment)
Rake::Task.define_task('dynflow:client')
end

def test_refresh_repos_on_smart_proxies
::ForemanTasks.expects(:async_task).with(::Actions::BulkAction, ::Actions::Pulp3::Orchestration::Repository::RefreshRepos, SmartProxy.all)
Rake.application.invoke_task('katello:refresh_repos')
end
end
end
2 changes: 1 addition & 1 deletion test/models/content_view_repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_import_only_non_yum_repos
cv = katello_content_views(:import_only_view)

assert_raises(ActiveRecord::RecordInvalid) do
cv.repositories << katello_repositories(:busybox)
cv.repositories << katello_repositories(:pulp3_ostree_1)
end
end
end
Expand Down
41 changes: 38 additions & 3 deletions test/services/katello/pulp3/content_view_version/export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class ExportTest < ActiveSupport::TestCase
destination_server: destination_server,
from_content_view_version: from_version)
::Katello::Pulp3::ContentViewVersion::Export.any_instance.expects(:validate_repositories_immediate!)
::Katello::Pulp3::ContentViewVersion::Export.any_instance.expects(:version_href_to_repository_href).with(nil).returns(nil).twice
::Katello::Pulp3::ContentViewVersion::Export.any_instance.expects(:version_href_to_repository_href).with("0").returns("0")
::Katello::Pulp3::ContentViewVersion::Export.any_instance.expects(:version_href_to_repository_href).with("1").returns("1")
::Katello::Pulp3::ContentViewVersion::Export.any_instance.expects(:version_href_to_repository_href).with(nil).returns(nil).at_least_once

exception = assert_raises(RuntimeError) do
export.validate!(fail_on_missing_content: true, validate_incremental: true)
Expand All @@ -88,18 +88,53 @@ class ExportTest < ActiveSupport::TestCase
end

it 'finds the library export view correctly' do
format = ::Katello::Pulp3::ContentViewVersion::Export::IMPORTABLE
org = get_organization
assert_nil ::Katello::Pulp3::ContentViewVersion::Export.find_library_export_view(organization: org,
create_by_default: false,
destination_server: nil)
destination_server: nil,
format: format)
# now create it
destination_server = "example.com"
cv = ::Katello::Pulp3::ContentViewVersion::Export.find_library_export_view(organization: org,
create_by_default: true,
destination_server: destination_server)
destination_server: destination_server,
format: format)
assert cv.generated_for_library_export?
assert_equal cv.name, "Export-Library-#{destination_server}"
end

it 'finds the library export view correctly for syncable' do
format = ::Katello::Pulp3::ContentViewVersion::Export::SYNCABLE
org = get_organization
assert_nil ::Katello::Pulp3::ContentViewVersion::Export.find_library_export_view(organization: org,
create_by_default: false,
destination_server: nil,
format: format)
# now create it
destination_server = "example.com"
cv = ::Katello::Pulp3::ContentViewVersion::Export.find_library_export_view(organization: org,
create_by_default: true,
destination_server: destination_server,
format: format)
assert cv.generated_for_library_export_syncable?
assert_equal cv.name, "Export-Library-SYNCABLE-#{destination_server}"
end

it 'finds the repository export view correctly for syncable' do
repo = katello_repositories(:rhel_6_x86_64)
format = ::Katello::Pulp3::ContentViewVersion::Export::SYNCABLE
assert_nil ::Katello::Pulp3::ContentViewVersion::Export.find_repository_export_view(repository: repo,
create_by_default: false,
format: format)
# now create it
cv = ::Katello::Pulp3::ContentViewVersion::Export.find_repository_export_view(repository: repo,
create_by_default: true,
format: format)
assert cv.generated_for_repository_export_syncable?
assert_match(/^Export-SYNCABLE-#{repo.label}/, cv.name)
end

it "does not fail on validate! if chunk_size is not specified" do
export = setup_environment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { DropdownItem } from '@patternfly/react-core';
import { CubeIcon } from '@patternfly/react-icons';
import { CubeIcon, UndoIcon } from '@patternfly/react-icons';

import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
Expand All @@ -13,6 +13,13 @@ const HostActionsBar = () => {

return (
<>
<DropdownItem
key="katello-legacy-contenthost-ui"
href={foremanUrl(`/content_hosts/${hostDetails?.id}`)}
icon={<UndoIcon />}
>
{__('Legacy content host UI')}
</DropdownItem>
<DropdownItem
key="katello-change-host-content-source"
href={foremanUrl(`/change_host_content_source?host_id=${hostDetails?.id}`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { propsToCamelCase } from 'foremanReact/common/helpers';
import './SystemPurposeCard.scss';
import SystemPurposeEditModal from './SystemPurposeEditModal';
import { selectHostDetailsStatus } from '../../HostDetailsSelectors';
import { hasRequiredPermissions } from '../../hostDetailsHelpers';
import { hasRequiredPermissions, hostIsNotRegistered } from '../../hostDetailsHelpers';

const SystemPurposeCard = ({ hostDetails }) => {
const showEditButton = hasRequiredPermissions(['edit_hosts'], hostDetails?.permissions);
Expand Down Expand Up @@ -57,6 +57,8 @@ const SystemPurposeCard = ({ hostDetails }) => {
);
}

if (hostIsNotRegistered({ hostDetails })) return null;

return (
<GridItem rowSpan={1} md={6} lg={4} xl2={3}>
<Card isHoverable ouiaId="system-purpose-card">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const baseHostDetails = {
purpose_usage: 'Production',
service_level: 'Premium',
release_version: '8',
uuid: '12345',
},
};

Expand Down
Loading

0 comments on commit 91030e1

Please sign in to comment.