Skip to content

Commit

Permalink
rpms.sh: fix for dnf repoquery
Browse files Browse the repository at this point in the history
Newer systems with dnf won't have standaalone 'repoquery' binary, being
replaced by 'dnf repouery'. To help decide what syntax to use new
internal variable was added __INTERNAL_DNF. It will contain 'dnf' string
when 'which dnf' is successful, empty string when unsuccessful.
It will be used in __INTERNAL_rpmGetPackageInfo() function to construct
command in case of 'repoquery' being used.
  • Loading branch information
hegerj committed Feb 11, 2019
1 parent 614287f commit fa2cc61
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/rpms.sh
Expand Up @@ -51,6 +51,9 @@ Functions in this BeakerLib script are used for RPM manipulation.
# Internal Stuff
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# variable indicates presence of 'dnf' on system
which dnf &>/dev/null && __INTERNAL_DNF="dnf" || __INTERNAL_DNF=""

__INTERNAL_RpmPresent() {
local assert=$1
local name=$2
Expand Down Expand Up @@ -575,10 +578,15 @@ from https://kojipkgs.fedoraproject.org/packages.
__INTERNAL_rpmGetPackageInfo() {
local package_info package_info_raw res=0
rlLogDebug "${FUNCNAME}(): getting package info for '$2'"
package_info_raw="$($1 --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" -q "$2")"

# On newer systems, repoquery is called with 'dnf repoquery' syntax
# instead of just 'repoquery'.
[[ "$1" == "repoquery" ]] && tool="$__INTERNAL_DNF $1" || tool=$1
package_info_raw="$($tool --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" -q "$2")"

This comment has been minimized.

Copy link
@sopos

sopos Feb 11, 2019

Member

parameter -q at the end must not be used in case of dnf repoquery so the tool variable should be like

  1. rpm -q
  2. repoquery -q
  3. dnf repoquery
    So the -q before "$2" should be removed and the line before should be [[ "$1" == "repoquery" && -n "$__INTERNAL_DNF" ]] && tool="dnf $1" || tool="$1 -q"

This comment has been minimized.

Copy link
@hegerj

hegerj Feb 12, 2019

Author Collaborator

As far as I can tell that is not true.
With repoquery -q option seems to not have any effect:

# repoquery --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" bash
bash 4.2.46 31.el7 x86_64 bash-4.2.46-31.el7.src.rpm
# repoquery --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" -q bash
bash 4.2.46 31.el7 x86_64 bash-4.2.46-31.el7.src.rpm

And with dnf repoquery it acts as (undocumented) quiet option:

# dnf repoquery --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" bash
Last metadata expiration check: 0:00:52 ago on Tue 12 Feb 2019 03:27:45 AM EST.
bash 4.4.23 7.fc30 x86_64 bash-4.4.23-7.fc30.src.rpm
# dnf repoquery --qf "%{name} %{version} %{release} %{arch} %{sourcerpm}\n" -q bash
bash 4.4.23 6.fc30 x86_64 bash-4.4.23-6.fc30.src.rpm

In which case it would be actually appropriate to use -q because dnf repoquery may produce some output to stdout that is not meant to be there on RHEL8 (the 'Last metadata expiration check....' is printed to stderr, but different output may appear).
Tested on RHEL6,7,8 and Fedora Rawhide.

This comment has been minimized.

Copy link
@sopos

sopos Feb 12, 2019

Member

I haven't checked this particular combination. I just know that dnf repoquery -q -a is conflicting. This case seems to be ok, than.


[[ $? -ne 0 || -z "$package_info_raw" ]] && {
rlLogDebug "${FUNCNAME}(): package_info_raw: '$package_info_raw'"
rlLogInfo "rpm '$2' not available using '$1' tool"
rlLogInfo "rpm '$2' not available using '$tool' tool"
let res++
}
if [[ $res -eq 0 ]]; then
Expand All @@ -591,7 +599,7 @@ __INTERNAL_rpmGetPackageInfo() {
let res++
}
rlLogDebug "${FUNCNAME}(): package_info: '$package_info'"
rlLogDebug "got rpm info for '$2' via '$1'"
rlLogDebug "got rpm info for '$2' via '$tool'"
echo "$package_info"
fi
rlLogDebug "${FUNCNAME}(): returning $res"
Expand Down

0 comments on commit fa2cc61

Please sign in to comment.