RHEL/Update: replace wc by yum to check updates

Similar to I8bd89f2b24bafc6c991382b9eb484cfa9a2f8968,
use yum to check if updates are available during RHEL registration and
run upgrades only when there are some.

Change-Id: I42cd699d21cbec7d754edf1b8d83e75de0f2c7d9
This commit is contained in:
Emilien Macchi 2017-11-21 15:00:23 -08:00
parent 35c5e7a122
commit b336b45102

View File

@ -173,18 +173,26 @@ resources:
config: |
#!/bin/bash
set -x
num_updates=$(yum list -q updates | wc -l)
if [ "$num_updates" -eq "0" ]; then
# yum check-update exits 100 if updates are available
set +e
check_update=$(yum check-update 2>&1)
check_update_exit=$?
set -e
if [[ "$check_update_exit" == "100" ]]; then
full_command="yum -q -y update"
echo "Running: $full_command"
result=$($full_command)
return_code=$?
echo "$result"
echo "yum return code: $return_code"
exit $return_code
elif [[ "$check_update_exit" == "1" ]]; then
echo "Failed to check for package updates"
echo "$check_update"
else
echo "No packages require updating"
exit 0
fi
full_command="yum -q -y update"
echo "Running: $full_command"
result=$($full_command)
return_code=$?
echo "$result"
echo "yum return code: $return_code"
exit $return_code
UpdateDeploymentAfterRHELRegistration:
type: OS::Heat::SoftwareDeployment