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

Improve appstreams context selection #9372

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix appstream list of packages in stream (bsc#1232515)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improve appstreams context selection (bsc#1231459)
Original file line number Diff line number Diff line change
@@ -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
);

20 changes: 20 additions & 0 deletions susemanager-utils/susemanager-sls/src/modules/appstreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ def _get_module_info(module_names):
return []

module_info_output = result.stdout.splitlines()
active_modules = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also change this: https://github.com/uyuni-project/uyuni/pull/9372/files#diff-0afe89c35f776dab892a3a79e2f20c5db733ec5c7c2002251a6b205145e7bf43L86 as now the function get the info for active modules only.

Also, before starting parsing the output, I would add an example output to understand better what the loop is trying parse/achieve.

while True:
start = next(
(i for i, e in enumerate(module_info_output)
if "[a]" in e), -1
)
if start != -1 and module_info_output[start].startswith("Stream"):
end = next(
(i for i, e in enumerate(module_info_output[start:-1])
if e.startswith("Name")), -1
)
if end != -1:
active_modules+=module_info_output[start-1:end+start]
module_info_output = module_info_output[end+start:-1]
else:
active_modules+=module_info_output[start-1:end]
module_info_output=active_modules
Comment on lines +103 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styling nitpick:

Suggested change
(i for i, e in enumerate(module_info_output[start:-1])
if e.startswith("Name")), -1
)
if end != -1:
active_modules+=module_info_output[start-1:end+start]
module_info_output = module_info_output[end+start:-1]
else:
active_modules+=module_info_output[start-1:end]
module_info_output=active_modules
(i for i, e in enumerate(module_info_output[start : -1])
if e.startswith("Name")), -1
)
if end != -1:
active_modules += module_info_output[start - 1 : end + start]
module_info_output = module_info_output[end + start : -1]
else:
active_modules += module_info_output[start - 1 : end]
module_info_output = active_modules

break
else:
break
Comment on lines +96 to +114
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably rather prefer to iterate module_info_output outside of a while True loop, for example, iterating module_info_output line-by-line (if that makes sense), and then filtering and collecting only the content of active modules we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean here. Could you give me an example snippet? I wouldn't know how to do this without a loop since there can be multiple active modules.


nsvca_info_list = []
current_module_info = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improve appstreams context selection (bsc#1231459)
Loading