Merge lp:~ursinha/landscape-charm/collect-logs-ignore-file-changed into lp:~landscape/landscape-charm/tools

Proposed by Ursula Junque
Status: Merged
Approved by: Ursula Junque
Approved revision: 29
Merged at revision: 30
Proposed branch: lp:~ursinha/landscape-charm/collect-logs-ignore-file-changed
Merge into: lp:~landscape/landscape-charm/tools
Diff against target: 52 lines (+10/-7)
2 files modified
collect-logs (+8/-5)
test_collect-logs.py (+2/-2)
To merge this branch: bzr merge lp:~ursinha/landscape-charm/collect-logs-ignore-file-changed
Reviewer Review Type Date Requested Status
Andreas Hasenack Approve
Review via email: mp+305766@code.launchpad.net

Commit message

Fixes bug 1623678, by re-adding the mechanism to ignore when tar returns 1 because files changed while tarfile is being created.

Description of the change

This branch fixes bug 1623678, by re-adding the mechanism to ignore when tar returns 1 because files changed while tarfile is being created.

I've done two things:
- Removed the tar --warning=no-file-changed option as that was only masking the output, tar exit code was still 1 causing collect-logs to silently skip tarball creation for such cases. Removing it allows me to check the exception output for that specific message and ignore it.
- Added mechanism to check if tar failure was due to files changing and deliberately proceed, ignoring this error in particular.

These two together restore previous and expected behavior.

To post a comment you must log in.
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

+1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'collect-logs'
2--- collect-logs 2016-08-31 15:32:04 +0000
3+++ collect-logs 2016-09-14 22:10:11 +0000
4@@ -246,11 +246,9 @@
5 log.info("Creating tarball on unit {}".format(unit))
6 exclude = " ".join(["--exclude=%s" % x for x in EXCLUDED])
7 logs = "$(sudo sh -c \"ls -1d %s 2>/dev/null\")" % " ".join(LOGS)
8- # note, tar commands can fail since we are backing up log files
9- # that are actively being written, ignoring errors seems best
10- # for now.
11- # http://serverfault.com/questions/560741/
12- tar_cmd = "sudo tar --ignore-failed-read --warning=no-file-changed"
13+ # --ignore-failed-read avoids failure for unreadable files (not for files
14+ # being written)
15+ tar_cmd = "sudo tar --ignore-failed-read"
16 logsuffix = unit.replace("/", "-")
17 if unit == "0":
18 logsuffix = "bootstrap"
19@@ -263,6 +261,11 @@
20 try:
21 check_output(args, stderr=STDOUT, env=juju.env)
22 except CalledProcessError as e:
23+ # Note: tar commands can fail since we are backing up log files
24+ # that are actively being written, ignoring such errors is what we
25+ # can and should do now. Everything else we might retry as usual.
26+ if e.returncode == 1 and "file changed as we read it" in e.output:
27+ break
28 log.warning(
29 "Failed to archive log files on unit {}".format(unit))
30 log.warning(e.output)
31
32=== modified file 'test_collect-logs.py'
33--- test_collect-logs.py 2016-08-29 18:26:55 +0000
34+++ test_collect-logs.py 2016-09-14 22:10:11 +0000
35@@ -317,7 +317,7 @@
36 tarfile = "/tmp/logs_{}.tar".format(unit.replace("/", "-")
37 if unit != "0"
38 else "bootstrap")
39- cmd = ("sudo tar --ignore-failed-read --warning=no-file-changed"
40+ cmd = ("sudo tar --ignore-failed-read"
41 " --exclude=/var/lib/landscape/client/package/hash-id"
42 " --exclude=/var/lib/juju/containers/juju-*-lxc-template"
43 " -cf {}"
44@@ -388,7 +388,7 @@
45 tarfile = "/tmp/logs_{}.tar".format(unit.replace("/", "-")
46 if unit != "0"
47 else "bootstrap")
48- cmd = ("sudo tar --ignore-failed-read --warning=no-file-changed"
49+ cmd = ("sudo tar --ignore-failed-read"
50 " --exclude=/var/lib/landscape/client/package/hash-id"
51 " --exclude=/var/lib/juju/containers/juju-*-lxc-template"
52 " -cf {}"

Subscribers

People subscribed via source and target branches

to all changes: