Bug 736694

Summary: 'yum install non-existent-package -y' returns zero
Product: Red Hat Enterprise Linux 5 Reporter: Šimon Lukašík <slukasik>
Component: yumAssignee: James Antill <james.antill>
Status: CLOSED NOTABUG QA Contact: Red Hat Satellite QA List <satqe-list>
Severity: high Docs Contact:
Priority: high    
Version: 5.7CC: pknirsch, psklenar
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-09-16 07:13:29 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Šimon Lukašík 2011-09-08 12:40:20 UTC
Description of problem:
When installing a non-existent package, the yum tool emits the error
message. However, it does not return non zero value.

Version-Release number of selected component (if applicable):
yum-3.2.22-37.el5

How reproducible:
deterministic

Steps to Reproduce:
1. yum install blablabumbac -y
2. echo $?
3.
  
Actual results:
# yum install blablabumbac -y
Loaded plugins: rhnplugin, security
Setting up Install Process
No package blablabumbac available.
Nothing to do
# echo $?
0

Expected results:
# yum install blablabumbac -y
Loaded plugins: rhnplugin, security
Setting up Install Process
No package blablabumbac available.
Nothing to do
# echo $?
1

Additional info:

Comment 1 Phil Knirsch 2011-09-14 11:50:18 UTC
This is working as intended. Having no packages to update is not considered an error in yum, nor is not finding any packages to update via the glob given on the commandline.

If you want to check if there are any updates available generally or for the given globs you can always run:

  yum check-update [globs]

and check the return value of that:

       check-update
              Implemented so you could know if your machine had any updates that needed to be applied without running it interactively. Returns exit value of 100 if there are packages available for an  update.
              Also returns a list of the packages to be updated in list format. Returns 0 if no packages are available for update. Returns 1 if an error occurred.  Running in verbose mode also shows obsoletes.

If you do that for a non existing package you will get 0 as a return value, but again that would be the same as no updates available.

If you want to check if a package exists you can use

  yum info blablabumbac

where you will get a 1 as a return value if the package doesn't exist.

The reason for this is that the update operation itself is not considered to be failing if no packages are updated. That just means that your system is as current as possible. On the other hand for info you directly specify that you want information about a specific package, and when that doesn't exist it will be an error.

Hope that helps,

Thanks & regards, Phil

Comment 2 Šimon Lukašík 2011-09-14 12:25:33 UTC
(In reply to comment #1)
> This is working as intended. Having no packages to update is not considered an
> error in yum, nor is not finding any packages to update via the glob given on
> the commandline.
Right.

> 
> If you want to check if there are any updates available generally or for the
> given globs you can always run:
> 
>   yum check-update [globs]
> 
> and check the return value of that:
> 
>        check-update
>               Implemented so you could know if your machine had any updates
> that needed to be applied without running it interactively. Returns exit value
> of 100 if there are packages available for an  update.
>               Also returns a list of the packages to be updated in list format.
> Returns 0 if no packages are available for update. Returns 1 if an error
> occurred.  Running in verbose mode also shows obsoletes.
> 
> If you do that for a non existing package you will get 0 as a return value, but
> again that would be the same as no updates available.
> 
Right.

> If you want to check if a package exists you can use
> 
>   yum info blablabumbac
> 
> where you will get a 1 as a return value if the package doesn't exist.
> 
Right.

> The reason for this is that the update operation itself is not considered to be
> failing if no packages are updated. That just means that your system is as
> current as possible. On the other hand for info you directly specify that you
> want information about a specific package, and when that doesn't exist it will
> be an error.
This is all correct.

But the description (in comment 0) of this bugzilla is not about
the 'yum update' nor the 'yum check-update' operations. This bugzilla
is about 'yum install' operation.

Even though the above said, We still hope that 'yum install' operation
is similar to 'yum info' operation in the way it should assert for
non-existent packages.

Reopening.

Comment 3 Petr Sklenar 2011-09-15 09:05:23 UTC
see also to another releases:

F15:
[root@freelab ~]# yum install blaublevolebum -y
Loaded plugins: langpacks, presto, refresh-packagekit
Setting up Install Process
No package blaublevolebum available.
Error: Nothing to do
[root@freelab ~]# echo $?
1
[root@freelab ~]# rpm -q yum
yum-3.2.29-8.fc15.noarch
--
RHEL6:
[root@dhcp-25-114 ~]# yum install asas -y
Loaded plugins: product-id, refresh-packagekit, rhnplugin, subscription-manager
Updating Red Hat repositories.
Setting up Install Process
No package asas available.
Error: Nothing to do
[root@dhcp-25-114 ~]# echo $?
1
[root@dhcp-25-114 ~]# rpm -q yum
yum-3.2.29-17.el6.noarch
========

its 2:1 for returning 1.
I guess it should be same on rhel5 or is there REGRESSION on rhel6 compare to rhel5?

Comment 4 James Antill 2011-09-15 19:57:58 UTC
 Yeh, we did fix this for RHEL-6 ... so now both "yum list" and "yum install" will exit 1 if all their arguments don't exist. But it was decided that'd be too big of a change for RHEL-5 ... Eg. some customer has:

#! /bin/bash -e

# Get random stuff from channels.
yum install foo
yum install bar
yum install baz

...where bar is in a channel that might not be enabled.

Comment 5 Petr Sklenar 2011-09-16 07:13:29 UTC
I see, Thanks much for the explanation. 
closing for rhel5