Skip to content

Commit 405f543

Browse files
author
Paolo
committed
Merged v0.11 into master
2 parents b0a8737 + 7357ba3 commit 405f543

7 files changed

+209
-104
lines changed

HACKING.md

+108-33
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
**Test Plan**
1+
### Test Plan
22

3-
When you make changes ensure at the very minimum you should test the following:
3+
For any changes that are made, the following should be considered the bare minimum to be tested:
44

5-
```
5+
```sh
66
auter --disable # deletes /var/lib/auter/enabled, prints "auter disabled"
77
auter --status # prints "auter is currently disabled"
88
auter --enable # touches /var/lib/auter/enabled, prints "auter enabled"
@@ -14,14 +14,14 @@ man auter # check the contents of the man page
1414

1515
If you don't have any updates available do this:
1616

17-
```
17+
```sh
1818
yum install zsh
1919
yum downgrade zsh
2020
```
2121

22-
Prepare custom scripts:
22+
Use the following to setup auter's pre/post scripts:
2323

24-
```
24+
```sh
2525
echo 'logger custom pre prep script ran' > /etc/auter/pre-prep.d/pre_prep_script
2626
echo 'logger custom post prep script ran' > /etc/auter/post-prep.d/post_prep_script
2727
echo 'logger custom pre apply script ran' > /etc/auter/pre-apply.d/pre_apply_script
@@ -31,40 +31,115 @@ echo 'logger custom post reboot script ran' > /etc/auter/post-reboot.d/post_rebo
3131
chmod +x /etc/auter/*.d/*script
3232
```
3333

34-
Now there will be at least one update:
34+
#### Basic guidelines for testing:
3535

36-
```
37-
auter --prep
38-
prints "INFO: Running with: ./auter --prep Updates downloaded", /var/lib/auter/last-prep-auter
39-
/var/lib/auter/last-prep-default contains update info
40-
41-
auter --apply
42-
prints "INFO: Running with: /usr/bin/auter --apply; Applying updates; Updates complete, you may need to reboot for some updates to take effect
43-
Run 'yum history info' or 'dnf history info' and verify that update was applied
44-
/var/lib/auter/last-update-default contains update info
45-
46-
auter --reboot
47-
prints "INFO: Running with: ./auter --reboot; Rebooting server" followed by shutdown message
48-
tail /var/log/messages should include text "root: custom pre reboot script ran"
49-
cat /etc/cron.d/auter-postreboot-auter should show "@reboot root /usr/bin/auter --postreboot --config auter"
50-
5 mins after the reboot, tail /var/log/messages should include text "root: custom post reboot script ran"
36+
1. Test the commands manually in a normal shell session.
37+
2. Test for both positive and negative outcomes.
38+
3. Test the effects of the change in the function. Again, if possible, test success and failure conditions
39+
4. Test the all functionality in auter that is affected by they code changes.
40+
41+
##### Testing template
42+
43+
This should be completed in all pull requests before being merged.
44+
45+
```md
46+
### Config settings
47+
48+
AUTOREBOOT="no"
49+
ONLYINSTALLFROMPREP="yes"
50+
PREDOWNLOADUPDATES=yes
51+
52+
### <OS test version>
53+
54+
#### auter status
55+
56+
[ pass/fail ] auter --status
57+
- Check: /var/lib/auter/enabled exists
58+
59+
[ pass/fail ] auter --disable
60+
- Check: /var/lib/auter/enabled does not exist
61+
62+
[ pass/fail ] auter --enable
63+
- Check: /var/lib/auter/enabled exists
64+
65+
[ pass/fail ] auter --help
66+
- Check: same output when running 'auter' without arguments
67+
68+
[ pass/fail ] auter --version
69+
- Check: prints 'auter VERSION'
70+
71+
#### update manually
72+
73+
[ pass/fail ] auter --prep
74+
- Check: prints "INFO: Running with: ./auter --prep Updates downloaded" to stdout
75+
- Check: /var/lib/auter/last-prep-default contains update info
76+
- Check: updates downloaded to /var/cache/auter/default
77+
- Check: pre/post prep scripts ran successfully with messages logged to syslog
78+
79+
[ pass/fail ] auter --apply
80+
- Check: prints "INFO: Running with: /usr/bin/auter --apply; Applying updates; Updates complete, you may need to reboot for some updates to take effect" to stdout
81+
- Check: expected updates were applied using 'yum history info' or 'dnf history info'
82+
- Check: /var/lib/auter/last-update-default contains update info
83+
- Check: no upates available after running
84+
- Check: pre/post apply scripts ran successfully, messages logged to syslog
85+
- Check: no mail is sent to the root user with the stdout from auter
86+
87+
[ pass/fail ] auter --reboot
88+
- Check: reboot scheduled in 2 minutes time
89+
- Check: prints "INFO: Running with: ./auter --reboot; Rebooting server" followed by shutdown message to stdout
90+
- Check: 5 minutes after reboot is complete pre/post reboot scripts ran successfully with messages logged to syslog
91+
92+
#### updates via cron
93+
94+
[ pass/fail ] auter --prep --stdout
95+
- Check: updates downloaded to /var/cache/auter/default
96+
- Check: pre/post prep scripts ran successfully, messages logged to syslog
97+
- Check: output from auter also mailed to root user on CentOS boxes, output logged to syslog on Fedora systems
98+
99+
[ pass/fail ] auter --apply --stdout
100+
- Check: no updates available after running
101+
- Check: pre/post scripts ran successfully with messages logged to syslog
102+
- Check: output from auter also mailed to root user on CentOS boxes, output logged to syslog on Fedora systems
103+
104+
[ pass/fail ] auter --reboot --stdout
105+
- Check: server rebooted after 2 minutes
106+
- Check: pre/post scripts ran successfully
107+
- Check: output from auter also mailed to the root user on CentOS, output logged to syslog on Fedora
108+
109+
#### new functionality testing
110+
111+
[ pass/fail ] <test new functionality added>
112+
- Check:
51113
```
52114

53-
**Documentation**
115+
#### Documentation
54116

55-
When making any changes to code, make sure documentation (--help, man page) has been updated to reflect any changes
117+
When making any changes to code, make sure documentation (--help, man page) has been updated with the new functionality.
56118

57-
**Release Process**
119+
#### Pull Request Rules
58120

59-
1. Ensure that all files are updated to the version of the release number you're about to tag. This includes:
60-
- auter
61-
- NEWS
62-
- auter.spec
121+
- All pull requests should be made against the develop branch
122+
- All pull requests MUST be reviewed and approved before merging
123+
- Pull request reviews and merges MUST be completed by another maintainer
124+
- Always squash and merge commits prior to submitting a pull request
125+
- All travis-ci tests should pass before merging
126+
- If the spellcheck test fails, adding the problematic words to the dictionary is a valid option
127+
- If the shellcheck test fails, you should fix the issues mentioned or add a shellcheck ignore directive to the previous line along with a comment on why it is being ignored
63128

64-
2. Add notes to auter.spec and NEWS with a list of the changes for this release
129+
#### Release Process
65130

66-
3. Push to github
131+
1. A new issue should be raised with the title of "Prep for <VERSION> Release"
132+
2. Ensure all required PRs for the new release have been merged to the develop branch
133+
3. A maintainer with admin rights to the master branch in rackerlabs/auter should create a new branch based from the develop branch:
67134

68-
4. Tag a release through github
135+
```sh
136+
git clone --branch=develop https://github.com/rackerlabs/auter.git rackerlabs/auter
137+
cd rackerlabs/auter
138+
git checkout -b Release-<NEW_VERSION>
139+
git push origin Release-<NEW_VERSION>
140+
```
69141

70-
5. Engage with the RPM building process to get RPMs built based on the new tag, and attach those to the github release.
142+
4. Any new PRs should be made to the develop branch. The only changes to the Release-<NEW_VERSION> should be fixing of any review issues for that branch.
143+
5. Full testing for all supported OSs should be carried out and tracked in a github project created for the release. Example: https://github.com/rackerlabs/auter/projects/1
144+
6. Once all testing has been completed for Release-<NEW_VERSION>, the reviewer should merge the Release-<NEW_VERSION> branch to both master and develop branches.
145+
7. Tag a new release named <NEW_VERSION> using template <major ver>.<minor ver> (Eg: Release 0.11)

NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Auter NEWS
55
* Removed debugging message that was printed during apt update
66
* Added "Valid Options" in auter.conf
77
* Added the pre/post prep directories in auter.conf
8+
* Added retention and rotation for last-prep-output and last-apply-output files in /var/lib/auter
9+
* Corrected file permissions for the auter-postreboot cron file
10+
* Added --stdout option to force output to stdout even if there is no active tty
11+
* Added a package manager lock file check before prep and apply functions call the package manager
12+
* Improved checks to confirm prepared patches are still required
813

914
0.10
1015
* Added pre and post prep script hooks

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Automatic updates for RHEL, CentOS, Fedora, Ubuntu and Debian Linux servers, with the ability to run pre/post hooks, pre-download packages and reboot after the updates.
44

5+
**Note about contributions**
6+
Auter is an open source project and we welcome users to send in feature requests and report any bugs in our issues page. We also welcome any help with maintaining the application and any code contributions.
7+
8+
**What does auter mean?**
9+
Automatic Update Transaction Execution by Rackspace.
10+
511
**When to use Auter?**
612

713
Updates should be applied regularly to Linux systems in order to apply security and bug fixes. For some of those updates, for example the kernel, or a shared library, a system restart is required for those updates to take effect. Whether you apply those updates manually, or automatically will depend on your requirements.

auter

+33-26
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ declare -r -x PIDFILE="/var/run/auter/auter.pid"
2727

2828
# Set default options - these can be overridden in the config file or with a command line argument
2929
declare -x -l AUTOREBOOT="no"
30-
declare -x PACKAGEMANAGEROPTIONS=""
30+
declare -x -a PACKAGEMANAGEROPTIONS
3131
declare -x -l PREDOWNLOADUPDATES="yes"
3232
declare -x -l ONLYINSTALLFROMPREP="no"
3333
declare -x CONFIGFILE="/etc/auter/auter.conf"
3434
declare -x DOWNLOADDIR="/var/cache/auter"
3535
declare -x -i MAXDELAY=3600
3636
declare -x CONFIGSET="default"
3737
declare -x ROTATE="5"
38-
PREPREPSCRIPTDIR="${SCRIPTDIR}/pre-prep.d"
39-
POSTPREPSCRIPTDIR="${SCRIPTDIR}/post-prep.d"
40-
PREAPPLYSCRIPTDIR="${SCRIPTDIR}/pre-apply.d"
41-
POSTAPPLYSCRIPTDIR="${SCRIPTDIR}/post-apply.d"
42-
PREREBOOTSCRIPTDIR="${SCRIPTDIR}/pre-reboot.d"
43-
POSTREBOOTSCRIPTDIR="${SCRIPTDIR}/post-reboot.d"
38+
declare -x PREPREPSCRIPTDIR="${SCRIPTDIR}/pre-prep.d"
39+
declare -x POSTPREPSCRIPTDIR="${SCRIPTDIR}/post-prep.d"
40+
declare -x PREAPPLYSCRIPTDIR="${SCRIPTDIR}/pre-apply.d"
41+
declare -x POSTAPPLYSCRIPTDIR="${SCRIPTDIR}/post-apply.d"
42+
declare -x PREREBOOTSCRIPTDIR="${SCRIPTDIR}/pre-reboot.d"
43+
declare -x POSTREBOOTSCRIPTDIR="${SCRIPTDIR}/post-reboot.d"
4444

4545
function default_signal_handling() {
4646
trap 'rm -f "${PIDFILE}"' SIGINT SIGTERM
@@ -75,11 +75,26 @@ function logit() {
7575
logger -p info -t auter "$1"
7676
}
7777

78+
function read_config() {
79+
if [[ -f "${CONFIGFILE}" ]]; then
80+
source "${CONFIGFILE}"
81+
elif [[ "${CUSTOMCONFIG}" ]]; then
82+
logit "ERROR: Custom config file ${CONFIGFILE} does not exist"
83+
quit 5
84+
else
85+
logit "WARNING: Using default config values."
86+
fi
87+
88+
# Convert space separated list from the config file to an indexed array
89+
# https://github.com/koalaman/shellcheck/wiki/SC2086
90+
IFS=' ' read -r -a PACKAGEMANAGEROPTIONS <<< "$PACKAGEMANAGEROPTIONS"
91+
}
92+
7893
function rotate_file {
7994
#Rotate old file
8095
OUTPUT_FILE=$1
81-
for i in `seq $(($ROTATE-1)) -1 1`; do
82-
[[ -e "${OUTPUT_FILE}.$i" ]] && mv -f "${OUTPUT_FILE}.$i" "${OUTPUT_FILE}.$(($i+1))"
96+
for i in $(seq $((ROTATE-1)) -1 1); do
97+
[[ -e "${OUTPUT_FILE}.$i" ]] && mv -f "${OUTPUT_FILE}.$i" "${OUTPUT_FILE}.$((i+1))"
8398
done
8499

85100
# Move base files to basefile.1
@@ -138,7 +153,7 @@ function reboot_server() {
138153
function post_reboot() {
139154
logit "INFO: Removed post-reboot hook: /etc/cron.d/auter-postreboot-${CONFIGSET}"
140155
rm -f "/etc/cron.d/auter-postreboot-${CONFIGSET}"
141-
$(tty -s) || sleep 300
156+
tty -s || sleep 300
142157

143158
for SCRIPT in "${POSTREBOOTSCRIPTDIR}"/*; do
144159
run_script "${SCRIPT}" "Post-Reboot"
@@ -147,7 +162,7 @@ function post_reboot() {
147162

148163
function print_status() {
149164
if [[ -f "${LOCKFILE}" ]] && [[ -f "${PIDFILE}" ]]; then
150-
if kill -0 $(cat ${PIDFILE}) &>/dev/null; then
165+
if kill -0 "$(cat ${PIDFILE})" &>/dev/null; then
151166
echo "auter is currently enabled and running"
152167
else
153168
echo "auter is currently enabled and pid file exists but process is dead"
@@ -164,12 +179,11 @@ function quit() {
164179
if [[ -f "${PIDFILE}" ]]; then
165180
rm -f "${PIDFILE}"
166181
fi
167-
exit $1
182+
exit "$1"
168183
}
169184

170185
function log_last_run() {
171-
local LASTRUNTIME=$(date -Iseconds)
172-
logit "INFO: Auter successfully ran at ${LASTRUNTIME}"
186+
logit "INFO: Auter successfully ran at $(date -Iseconds)"
173187
}
174188

175189

@@ -229,7 +243,7 @@ fi
229243

230244
if [[ "${DISABLE}" ]] ; then
231245
rm -f "${LOCKFILE}"
232-
if [[ -f "${PIDFILE}" ]] && ! kill -0 $(cat ${PIDFILE}) &>/dev/null; then
246+
if [[ -f "${PIDFILE}" ]] && ! kill -0 "$(cat ${PIDFILE})" &>/dev/null; then
233247
rm -f "${PIDFILE}"
234248
logit "INFO: auter disabled and cleared pid file"
235249
else
@@ -257,14 +271,7 @@ else
257271
echo "$$" > "${PIDFILE}"
258272
fi
259273

260-
if [[ -f "${CONFIGFILE}" ]]; then
261-
source "${CONFIGFILE}"
262-
elif [[ "${CUSTOMCONFIG}" ]]; then
263-
logit "ERROR: Custom config file ${CONFIGFILE} does not exist"
264-
quit 5
265-
else
266-
logit "WARNING: Using default config values."
267-
fi
274+
read_config
268275

269276
# CONFIGSET needs to be set if we're using a custom configuration file.
270277
if [[ -z "${CONFIGSET}" ]]; then
@@ -284,7 +291,7 @@ fi
284291
logit "INFO: Running with: $0 ${ARGS}"
285292

286293
[[ "${MAXDELAY}" -lt 1 ]] && MAXDELAY=1
287-
$(tty -s) && MAXDELAY=1 && logit "INFO: Running in an interactive shell, disabling all random sleeps"
294+
tty -s && MAXDELAY=1 && logit "INFO: Running in an interactive shell, disabling all random sleeps"
288295

289296
# There is an explicit quit here to avoid auter automatically running any
290297
# other unexpected functions.
@@ -295,8 +302,8 @@ $(tty -s) && MAXDELAY=1 && logit "INFO: Running in an interactive shell, disabli
295302

296303
# The following 3 functions are provided by the previously sourced /usr/lib/auter/auter.module
297304
# Run the package manager specific check for locks
298-
[[ "${PREP}" ]] && check_package_manager_lock && prepare_updates
299-
[[ "${APPLY}" ]] && check_package_manager_lock && apply_updates
305+
[[ "${PREP}" ]] && prepare_updates
306+
[[ "${APPLY}" ]] && apply_updates
300307

301308
[[ "${REBOOTCALL}" ]] && reboot_server
302309

0 commit comments

Comments
 (0)