Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Fix SLES, openSUSE, Ubuntu #46

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pevik
Copy link
Collaborator

@pevik pevik commented Nov 23, 2021

2 fixes for 22db0cd e572aa5:

Previously these 3 commands didn't print anything:

./install_pkg.pm --distro opensuse --run --cmd
./install_pkg.pm --distro sles --run --cmd
./install_pkg.pm --distro ubuntu --run --cmd

@pevik pevik requested a review from metan-ucw November 23, 2021 17:25
@pevik
Copy link
Collaborator Author

pevik commented Nov 26, 2021

Ah, bug, it needs to be fixed.

@pevik pevik force-pushed the fix/cmd-opensuse-sles-ubuntu branch 3 times, most recently from 57e6a96 to a8748c7 Compare November 29, 2021 10:40
Copy link
Owner

@metan-ucw metan-ucw left a comment

Choose a reason for hiding this comment

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

It says "Remove Ubuntu" but leap is removed as well. If that was intentional it should be at least mentioned in the commit message.

while dpkg --print-architecture works only for Debian, not for Ubuntu.
Thus use uname -r.

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
@pevik pevik force-pushed the fix/cmd-opensuse-sles-ubuntu branch from a8748c7 to d9f60f6 Compare November 29, 2021 12:37
@pevik
Copy link
Collaborator Author

pevik commented Nov 29, 2021

It says "Remove Ubuntu" but leap is removed as well. If that was intentional it should be at least mentioned in the commit message.

Thanks! Unintentional, Leap put back. Added your review-by to that commit.

install_pkg.pm Outdated
@@ -76,6 +76,17 @@ sub foo_to_pkg
'libnuma-devel-opensuse' => 'libnuma-devel',
);

my $pkg = $pkg_map{"$foo-$distro"};
$pkg = $pkg_map{"$foo-" . get_distro_alias($distro)} unless defined $pkg;
Copy link
Owner

Choose a reason for hiding this comment

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

I do not like the unless part here that much. Maybe we should just do:

my $pkg;

pkg = $pkg_map{"$foo-$distro");

return $pkg if defined;

$pkg = $pkg_map{"$foo-" . get_distro_alias($distro)};

return $pkg if defined $pkg;

return $pkg_map{"$foo");

@@ -189,7 +194,7 @@ sub update_pkg_db
return "yum update -y";
}

if ($distro eq "suse") {
if ($distro eq "opensuse") {
return "zypper --non-interactive ref";
}

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, maybe we should just do the get_distro_alias() once in the distro detection code and return the alias if defined, then we can forget about aliases in the rest of the code right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is, that for packages we don't want to use alias, but for others we do want (installing pkg, updating package database, 32bit).

Also, some methods (at least install_ltp_pkgs()) are used from runltp-ng, but we don't export functions with @EXPORT, so I'm not sure what is the interface outside of the module, thus I wanted any method worked called from outside (not expecting to get correct distro from outside).

But sure, I'm open to rewrite code if we agree what's the clearest way.

Copy link
Owner

Choose a reason for hiding this comment

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

So we have to pass the distro to the package mapping since debian and ubuntu have different packages while the rest of the operations are the same for the families of distributions.

Maybe it would be cleaner to have a function to map the distribution name into the package management so that we would map anything debian-like to apt, SUSE to zypper, anything from redhat to yum and alpine to apk.

That would allow us to choose the action based on the tool we are going to use rather than on some distribution name aliases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, I'll add something like distro_to_pkg_tool() method.

Also I was thinking that having @build_pkgs, @devel_libs and @mkfs as global arrays defined on the top would be more readable than having them hidden in the functions. We also add distro versions in of these arrays in foo_to_pkg(), which is a different method. But this can wait after this fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe it would be cleaner to have a function to map the distribution name into the package management so that we would map anything debian-like to apt, SUSE to zypper, anything from redhat to yum and alpine to apk.

Sounds good, I'll add something like distro_to_pkg_tool() method.

Well, we need that distro alias function in foo_to_pkg() function as well, thus not sure about distro_to_pkg_tool() name. You're right, it's only the case for Ubuntu (currently). I suppose we don't want to specifically check for Ubuntu there.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually the only function used from the library at the moment is isntall_ltp_pkgs() that does everything including the call to the backend. I guess that it should be the other way the module should export the functions that generate the list of packages and the commandlines and that should be used. Generally the code should be cleaned up a bit, I guess that the detect_distro() function and install_ltp_pkgs() conceptually belongs somewhere else and that the interface to the module should really be the get_build_pkgs() get_runtime_pkgs() and get_install_cmds() functions. And I would declare the rest of the functions internal. Also we would need to add architecture parameter to the get_install_cmds() to properly support m32 on Debian.

Also I would add distro_to_pkg_too() function that would simply map distribution to the tool. As for the pkg_map we should do it so that we would try the distribution name first and if that fails we would use a distribution alias, so for ubuntu we would check if there is package foo-ubuntu mapping, if not we would look up an distro alias hash that would return debian, so we would try foo-debian and if that fails we would try looking up just foo. Does that sound reasonable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the interface to the module should really be the get_build_pkgs() get_runtime_pkgs() and get_install_cmds() functions.

Sure, agree.

I guess that it should be the other way the module should export the functions that generate the list of packages and the commandlines and that should be used.

FYI although I agree exported functions I meant internal arrays. As the code is IMHO a bit too complicated for just a simple thing (given how simple and thus readable are scripts in https://github.com/linux-test-project/ltp/tree/master/ci, although it cannot print things obviously and I don't mean to use bash).

I also don't like that we apped distro to the package "key" with and distro separator is the same (-) as what is used in package key (i.e. 'libaio-devel' vs. 'libaio-devel-opensuse'), sure it's obvious that it's a distro, but it's not that readable.
Also having default which can be overwritten is just strange (which distro is a default?). I'd prefer hashes of hashes array:
({runtime or build}{distro{ => (array of package)) and specify everything (no "default)

Also we should think about other scenarios when some package is not supported on particular distro, should it be empty? Or there are 2 packages needed. This feature is not needed now, but might be for runtime packages (e.g. for networking).

Problem affect SLES and Ubuntu, but visible only on Ubuntu.

Fixes: e572aa5 ("install_pkg: Introduce Ubuntu")

Signed-off-by: Petr Vorel <[email protected]>
These commands prints nothing:
./install_pkg.pm --build --run --distro sles --cmd
./install_pkg.pm --build --run --distro opensuse --cmd
./install_pkg.pm --build --run --distro ubuntu --cmd

Fixes: 22db0cd ("install_pkg: Introduce openSUSE, SLES instead of suse")
Fixes: e572aa5 ("install_pkg: Introduce Ubuntu")

Signed-off-by: Petr Vorel <[email protected]>
Groovy and Xenial are EOL now. impish does not have linux-headers
package. But update releases does not help because Focal (LTS, it'd be a
candidate to test) and Hirsute have problems to install
linux-headers-5.11.0-1021-azure (some strange timeout).

This means that 6999232 ("install_pkg: Fix kernel headers for Ubuntu")
was tested only locally.

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
@pevik pevik force-pushed the fix/cmd-opensuse-sles-ubuntu branch from d9f60f6 to 5cad4ee Compare November 29, 2021 15:50
@pevik pevik marked this pull request as draft November 29, 2021 16:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants