Set modification time in tarfile of ramdisk logs
If we do not set this explicitly, tar will warn "journal: implausibly old time stamp" when the user tries to untar the log files. Change-Id: I4a5a1ffd4eeca9697cdcf16e02d3ff3c22d7132c
This commit is contained in:
parent
1121887d19
commit
3f715a20fd
ironic_python_agent
@ -17,6 +17,7 @@ import base64
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import time
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
@ -287,6 +288,7 @@ def collect_logs(data, failures):
|
|||||||
with tarfile.open(fileobj=fp, mode='w:gz') as tar:
|
with tarfile.open(fileobj=fp, mode='w:gz') as tar:
|
||||||
tarinfo = tarfile.TarInfo('journal')
|
tarinfo = tarfile.TarInfo('journal')
|
||||||
tarinfo.size = len(out)
|
tarinfo.size = len(out)
|
||||||
|
tarinfo.mtime = time.time()
|
||||||
tar.addfile(tarinfo, journal)
|
tar.addfile(tarinfo, journal)
|
||||||
|
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
|
@ -386,12 +386,13 @@ class TestCollectLogs(unittest.TestCase):
|
|||||||
mock_execute.return_value = (contents, '')
|
mock_execute.return_value = (contents, '')
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
inspector.collect_logs(data, None)
|
with mock.patch('time.time', return_value=42):
|
||||||
|
inspector.collect_logs(data, None)
|
||||||
res = io.BytesIO(base64.b64decode(data['logs']))
|
res = io.BytesIO(base64.b64decode(data['logs']))
|
||||||
|
|
||||||
with tarfile.open(fileobj=res) as tar:
|
with tarfile.open(fileobj=res) as tar:
|
||||||
members = [(m.name, m.size) for m in tar]
|
members = [(m.name, m.size, m.mtime) for m in tar]
|
||||||
self.assertEqual([('journal', len(contents))], members)
|
self.assertEqual([('journal', len(contents), 42)], members)
|
||||||
|
|
||||||
member = tar.extractfile('journal')
|
member = tar.extractfile('journal')
|
||||||
self.assertEqual(expected_contents, member.read().decode('utf-8'))
|
self.assertEqual(expected_contents, member.read().decode('utf-8'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user