Bug 1385177

Summary: katello-clean-empty-puppet-environments cron.weekly job needs to hide errors when trying to delete non-existent folders
Product: Red Hat Satellite Reporter: Craig Donnelly <cdonnell>
Component: InfrastructureAssignee: Chris Roberts <chrobert>
Status: CLOSED ERRATA QA Contact: Lukas Pramuk <lpramuk>
Severity: low Docs Contact:
Priority: low    
Version: 6.2.2CC: adprice, bbuckingham, bkearney, chrobert, ehelms, hartsjc, jcallaha, lpramuk, oshtaier
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: x86_64   
OS: Linux   
URL: http://projects.theforeman.org/issues/17047
Whiteboard:
Fixed In Version: katello-3.0.0-15 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1399338 1405485 (view as bug list) Environment:
Last Closed: 2017-01-26 10:43:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1399338, 1405485    

Description Craig Donnelly 2016-10-14 21:37:43 UTC
Description of problem:
The cron.weekly job put in place to clean empty puppet environments will now have situations where there are no KT_* environments to clean up. In this situation, the find command fails and an error is output. We should redirect the errors to null (hide them) or come up with a different command.

Version-Release number of selected component (if applicable):
Satellite 6.2.2.1

How reproducible:
100%

Steps to Reproduce:
1. Install Satellite 6.2
2. Have no publshed puppet environments. (KT_* folders are no longer created for content-views, so on if not modules are published)
3. Run /etc/cron.weekly/katello-clean-empty-puppet-environments

Actual results:
find: ‘/etc/puppet/environments/KT*’: No such file or directory

Expected results:
No errors from script output

Additional info:
Since the only purpose is to clean out unused puppet environments, we could simply add '> /dev/null 2>&1' to the end of the scripts `find` command.

Comment 1 James Hartsock 2016-10-14 21:43:51 UTC
better than ignoring possibly legitimate errors would be to check for the existence of the directory before doing the find.

Comment 2 Craig Donnelly 2016-10-14 23:09:18 UTC
Sure thing,

We can go this route instead:

#!/bin/bash

if [ -d /etc/puppet/environments ];then
  if ls /etc/puppet/environments | grep KT; then
    find /etc/puppet/environments/KT* -maxdepth 0 -type d -empty -delete
  fi
fi

Comment 3 Craig Donnelly 2016-10-14 23:33:24 UTC
This has actually already been taken care of upstream.
The new cron looks like this:

$ cat katello-clean-empty-puppet-environments
#!/bin/bash

# Puppet 4
[ -d /etc/puppetlabs/code/environments ] &&  find /etc/puppetlabs/code/environments/KT* -maxdepth 0 -type d -empty -delete

# Puppet 3
[ -d /etc/puppet/environments ] && find /etc/puppet/environments/KT* -maxdepth 0 -type d -empty -delete

This just needs to be pulled down into Satellite 6.2.

Solved in:

https://github.com/Katello/katello-packaging/commit/f7b70e71ecaf99cd9de375d75d0880d4f3d5c3be

and

https://github.com/Katello/katello-packaging/commit/5846981719e9bd6a5617daf7078b8729dbb1e5f0

Comment 5 Chris Roberts 2016-10-20 14:18:54 UTC
http://projects.theforeman.org/issues/17047

Comment 6 Lukas Pramuk 2017-01-10 11:28:43 UTC
VERIFIED.

@satellite-6.2.7-1.0.el7sat.noarch
katello-common-3.0.0-15.el7sat.noarch

used manual reproducer from comment#0

# ls /etc/puppet/environments/KT*
ls: cannot access /etc/puppet/environments/KT*: No such file or directory

# /etc/cron.weekly/katello-clean-empty-puppet-environments
<empty>

Comment 8 errata-xmlrpc 2017-01-26 10:43:03 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:0197