diff --git a/java/code/src/com/redhat/rhn/manager/appstreams/AppStreamsManager.java b/java/code/src/com/redhat/rhn/manager/appstreams/AppStreamsManager.java index ea12c1196942..64ca9c613209 100644 --- a/java/code/src/com/redhat/rhn/manager/appstreams/AppStreamsManager.java +++ b/java/code/src/com/redhat/rhn/manager/appstreams/AppStreamsManager.java @@ -171,7 +171,7 @@ public static AppStream findAppStream(Long channelId, String name, String stream ); criteriaQuery.select(root).where(finalPredicate); - return session.createQuery(criteriaQuery).uniqueResult(); + return session.createQuery(criteriaQuery).stream().findFirst().orElse(null); } /** diff --git a/java/code/webapp/WEB-INF/nav/system_detail.xml b/java/code/webapp/WEB-INF/nav/system_detail.xml index d6144f6a2f84..f93bf5af04e9 100644 --- a/java/code/webapp/WEB-INF/nav/system_detail.xml +++ b/java/code/webapp/WEB-INF/nav/system_detail.xml @@ -69,7 +69,7 @@ - + /rhn/manager/systems/details/ptf/overview diff --git a/java/spacewalk-java.changes.parlt.fix-appstreams-context-selection b/java/spacewalk-java.changes.parlt.fix-appstreams-context-selection new file mode 100644 index 000000000000..ceba5bebccc4 --- /dev/null +++ b/java/spacewalk-java.changes.parlt.fix-appstreams-context-selection @@ -0,0 +1 @@ +- Fix appstream list of packages in stream (bsc#1232515) diff --git a/schema/spacewalk/common/views/suseServerAppStreamHiddenPackagesView.sql b/schema/spacewalk/common/views/suseServerAppStreamHiddenPackagesView.sql index c4032e4efa8a..ed0df359cef5 100644 --- a/schema/spacewalk/common/views/suseServerAppStreamHiddenPackagesView.sql +++ b/schema/spacewalk/common/views/suseServerAppStreamHiddenPackagesView.sql @@ -23,6 +23,7 @@ FROM rhnserverchannel sc INNER JOIN suseappstreampackage sasp ON sasp.module_id = sas.id LEFT JOIN suseserverappstream ssa ON ssa.name = sas.name AND ssa.stream = sas.stream + AND ssa.context = sas.context AND ssa.arch = sas.arch AND ssa.server_id = sc.server_id WHERE ssa.id IS NULL diff --git a/schema/spacewalk/susemanager-schema.changes.parlt.fix-appstreams-context-selection b/schema/spacewalk/susemanager-schema.changes.parlt.fix-appstreams-context-selection new file mode 100644 index 000000000000..390902d990a4 --- /dev/null +++ b/schema/spacewalk/susemanager-schema.changes.parlt.fix-appstreams-context-selection @@ -0,0 +1 @@ +- Improve appstreams context selection (bsc#1231459) diff --git a/schema/spacewalk/upgrade/susemanager-schema-5.1.0-to-susemanager-schema-5.1.1/003-appstream-hidden-packages-view.sql b/schema/spacewalk/upgrade/susemanager-schema-5.1.0-to-susemanager-schema-5.1.1/003-appstream-hidden-packages-view.sql new file mode 100644 index 000000000000..6d0ee8eb809f --- /dev/null +++ b/schema/spacewalk/upgrade/susemanager-schema-5.1.0-to-susemanager-schema-5.1.1/003-appstream-hidden-packages-view.sql @@ -0,0 +1,50 @@ +-- +-- Copyright (c) 2024 SUSE LLC +-- +-- This software is licensed to you under the GNU General Public License, +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +-- along with this software; if not, see +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +-- +-- Red Hat trademarks are not licensed under GPLv2. No permission is +-- granted to use or replicate Red Hat trademarks that are incorporated +-- in this software or its documentation. +-- +CREATE OR REPLACE VIEW suseServerAppStreamHiddenPackagesView AS + +-- If a package is part of any appstream, +-- and this appstream is not enabled in +-- a server, it should appear here. +SELECT DISTINCT sasp.package_id AS pid, sc.server_id AS sid +FROM rhnserverchannel sc + INNER JOIN suseappstream sas ON sas.channel_id = sc.channel_id + INNER JOIN suseappstreampackage sasp ON sasp.module_id = sas.id + LEFT JOIN suseserverappstream ssa ON ssa.name = sas.name + AND ssa.stream = sas.stream + AND ssa.context = sas.context + AND ssa.arch = sas.arch + AND ssa.server_id = sc.server_id +WHERE ssa.id IS NULL + +UNION + +-- If a package is part of an enabled appstream, all the packages +-- whose name matches with appstream api need to be filtered out +-- except the packages that are part of the enabled appstream. +SELECT DISTINCT p.id AS pid, server_stream.server_id AS sid +FROM suseServerAppstream server_stream + INNER JOIN suseAppstream appstream ON appstream.name = server_stream.name + AND appstream.stream = server_stream.stream + AND appstream.arch = server_stream.arch + INNER JOIN suseAppstreamApi api ON api.module_id = appstream.id + inner join rhnPackageName pn ON pn.name = api.rpm + inner join rhnPackage p ON p.name_id = pn.id +WHERE NOT EXISTS ( + SELECT package_id + FROM suseServerAppStreamPackageView + WHERE server_id = server_stream.server_id + AND package_id = p.id +); + diff --git a/susemanager-utils/susemanager-sls/src/modules/appstreams.py b/susemanager-utils/susemanager-sls/src/modules/appstreams.py index c917e37c602f..90969d2f14ee 100644 --- a/susemanager-utils/susemanager-sls/src/modules/appstreams.py +++ b/susemanager-utils/susemanager-sls/src/modules/appstreams.py @@ -83,7 +83,8 @@ def _parse_nsvca(module_info_output): def _get_module_info(module_names): - # Run the DNF command to get module info for all modules + # Run the DNF command to get module info for all active modules + # Parse all modules if no active ones are present command = ["dnf", "module", "info", "--quiet"] + module_names result = subprocess.run(command, capture_output=True, text=True) @@ -91,7 +92,31 @@ def _get_module_info(module_names): log.error(f"Error running DNF command: {result.stderr}") return [] - module_info_output = result.stdout.splitlines() + # Active modules are marked with [a] + # Example output + # Name : perl-IO-Socket-SSL + # Stream : 2.066 [d][e][a] + # Version : 8090020231016070024 + # Context : 88fd4976 + # Architecture : x86_64 + # Profiles : common [d] + # Default profiles : common + # Repo : susemanager:rockylinux8-x86_64-appstream + # Summary : Perl library for transparent TLS + # Description : IO::Socket::SSL is a drop-in replacement for ... + # Requires : perl:[5.26] + # : platform:[el8] + # Artifacts : perl-IO-Socket-SSL-0:2.066-4.module+el8.9.0+1517+e71a7a62.noarch + + module_info_output = [] + + for module in re.findall(r"(Name\s+:.*?)(?=\n\s*\n|$)", result.stdout, re.DOTALL): + if re.search(r"Stream\s+:.*\[a\]", module): + module_info_output += module.splitlines() + + # Parse all modules, if no active ones were found + if not module_info_output: + module_info_output = result.stdout.splitlines() nsvca_info_list = [] current_module_info = [] diff --git a/susemanager-utils/susemanager-sls/susemanager-sls.changes.parlt.fix-appstreams-context-selection b/susemanager-utils/susemanager-sls/susemanager-sls.changes.parlt.fix-appstreams-context-selection new file mode 100644 index 000000000000..390902d990a4 --- /dev/null +++ b/susemanager-utils/susemanager-sls/susemanager-sls.changes.parlt.fix-appstreams-context-selection @@ -0,0 +1 @@ +- Improve appstreams context selection (bsc#1231459)