Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37144 - Use OS family for host details page packages tab #10881

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/views/katello/api/v2/hosts/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ object @resource
@facet = @resource.content_facet

attributes :id, :name, :description

node :operatingsystem_family do |resource|
resource.operatingsystem.family
end

node :operatingsystem_major do |resource|
resource.operatingsystem.major
end

if @facet
node :content_view do
content_view = @facet&.single_content_view
Expand Down
1 change: 1 addition & 0 deletions lib/katello/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@

extend_rabl_template 'api/v2/smart_proxies/main', 'katello/api/v2/smart_proxies/pulp_info'
extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/host_collections'
extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/show'

# Katello variables for Host Registration
extend_allowed_registration_vars :activation_keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Api::V2::HostSubscriptionsControllerBase < ActionController::TestCase
tests Katello::Api::V2::HostSubscriptionsController

def models
@host = FactoryBot.create(:host, :with_subscription)
@host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem)
users(:restricted).update_attribute(:organizations, [@host.organization])
users(:restricted).update_attribute(:locations, [@host.location])
@pool = katello_pools(:pool_one)
Expand Down
16 changes: 8 additions & 8 deletions test/controllers/api/v2/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def models
@environment = katello_environments(:library)
@dev = katello_environments(:dev)
@cv2 = katello_content_views(:library_view_no_version)
@host = FactoryBot.create(:host)
@host = FactoryBot.create(:host, :with_operatingsystem)
end

def host_index_and_show(host)
Expand All @@ -32,26 +32,26 @@ def host_show(host, smart_proxy)
end

def test_content_and_subscriptions
host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem, :content_view => @content_view,
:lifecycle_environment => @environment)
host_index_and_show(host)
end

def test_with_content
host = FactoryBot.create(:host, :with_content, :content_view => @content_view,
host = FactoryBot.create(:host, :with_content, :with_operatingsystem, :content_view => @content_view,
:lifecycle_environment => @environment)
host_index_and_show(host)
end

def test_no_content_view_environments
host = FactoryBot.create(:host, :with_content, :with_subscription)
host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem)
assert_empty host.content_facet.content_view_environments

host_index_and_show(host)
end

def test_content_facet_attributes_assigned_as_cve
host = FactoryBot.create(:host, :with_content, :with_subscription,
host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem,
:content_view => @content_view, :lifecycle_environment => @environment)
Katello::Host::SubscriptionFacet.any_instance.expects(:backend_update_needed?).returns(false)
orig_cves = host.content_facet.content_view_environment_ids.to_a
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_host_update_with_invalid_env
end

def test_with_subscriptions
host = FactoryBot.create(:host, :with_subscription)
host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem)
host_index_and_show(host)
end

Expand All @@ -122,7 +122,7 @@ def test_update_subscription_facet
Katello::Candlepin::Consumer.any_instance.stubs(:virtual_guests).returns([])
Katello::Candlepin::Consumer.any_instance.stubs(:installed_products).returns([])

host = FactoryBot.create(:host, :with_subscription)
host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem)
host.subscription_facet.update!(:autoheal => true,
:installed_products_attributes => [{:product_name => 'foo', :version => '6', :product_id => '69'}])

Expand All @@ -136,7 +136,7 @@ def test_update_subscription_facet

def test_with_smartproxy
smart_proxy = FactoryBot.create(:smart_proxy, :features => [FactoryBot.create(:feature, name: 'Pulp')])
host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem, :content_view => @content_view,
:lifecycle_environment => @environment, :content_source => smart_proxy)
host_show(host, smart_proxy)
end
Expand Down
4 changes: 4 additions & 0 deletions test/factories/host_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
content_source { nil }
end

trait :with_operatingsystem do
operatingsystem
end

trait :with_content do
association :content_facet, :factory => :content_facet, :strategy => :build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ import { hasRequiredPermissions as can,
import SortableColumnHeaders from '../../../../Table/components/SortableColumnHeaders';
import { useRexJobPolling } from '../RemoteExecutionHooks';

export const hideDebsTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/);
if (!osMatch) return false;
const [, os] = osMatch;
return !(osMatch && os.match(/Debian|Ubuntu/i));
};
export const hideDebsTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family === 'Debian');

const invokeRexJobs = ['create_job_invocations'];
const createBookmarks = ['create_bookmarks'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ import {
userPermissionsFromHostDetails,
} from '../../hostDetailsHelpers';

const moduleStreamSupported = ({ os, version }) =>
os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Oracle Linux/i) && Number(version) > 7;
export const hideModuleStreamsTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+)/);
if (!osMatch) return false;
const [, os, version] = osMatch;
return !(osMatch && moduleStreamSupported({ os, version }));
};
export const hideModuleStreamsTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family === 'Redhat' && Number(hostDetails?.operatingsystem_major > 7));

const EnabledIcon = ({ streamText, streamInstallStatus, upgradable }) => {
switch (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ import { runSubmanRepos } from '../../Cards/ContentViewDetailsCard/HostContentVi
const invokeRexJobs = ['create_job_invocations'];
const createBookmarks = ['create_bookmarks'];

export const hidePackagesTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/);
if (!osMatch) return false;
const [, os] = osMatch;
return !(osMatch && os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Alma|Oracle Linux|Oracle|Suse Linux Enterprise Server|SLES/i));
};
export const hidePackagesTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family?.match(/RedHat|SUSE/i));

const UpdateVersionsSelect = ({
packageName,
Expand Down
Loading