Add a log extension

The log extension is responsible for retrieving logs from the system,
if journalctl is present the logs will come from it, otherwise we
fallback to getting the logs from the /var/log directory + dmesg logs.

In the coreos ramdisk, we need to bind mount /run/log in the container
so the IPA service can have access to the journal.

For the tinyIPA ramdisk, the logs from IPA are now being redirected to
/var/logs/ironic-python-agent.log instead of only going to the default
stdout.

Inspector now shares the same method of collecting logs, extending its
capabilities for non-systemd systems.

Partial-Bug: #1587143
Change-Id: Ie507e2e5c58cffa255bbfb2fa5ffb95cb98ed8c4
This commit is contained in:
Lucas Alvares Gomes
2016-05-30 17:39:13 +01:00
parent 0ba66c27ea
commit af81914ce7
10 changed files with 353 additions and 54 deletions
imagebuild
coreos
tinyipa
build_files
ironic_python_agent
releasenotes/notes
setup.cfg

@ -13,11 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import io
import json
import os
import tarfile
import time
import netaddr
@ -319,7 +316,7 @@ def collect_default(data, failures):
def collect_logs(data, failures):
"""Collect journald logs from the ramdisk.
"""Collect system logs from the ramdisk.
As inspection runs before any nodes details are known, it's handy to have
logs returned with data. This collector sends logs to inspector in format
@ -334,24 +331,11 @@ def collect_logs(data, failures):
:param failures: AccumulatedFailures object
"""
try:
out, _e = utils.execute('journalctl', '--full', '--no-pager', '-b',
'-n', '10000', binary=True,
log_stdout=False)
except (processutils.ProcessExecutionError, OSError):
data['logs'] = utils.collect_system_logs(journald_max_lines=10000)
except errors.CommandExecutionError:
LOG.warning('failed to get system journal')
return
journal = io.BytesIO(bytes(out))
with io.BytesIO() as fp:
with tarfile.open(fileobj=fp, mode='w:gz') as tar:
tarinfo = tarfile.TarInfo('journal')
tarinfo.size = len(out)
tarinfo.mtime = time.time()
tar.addfile(tarinfo, journal)
fp.seek(0)
data['logs'] = base64.b64encode(fp.getvalue())
def collect_extra_hardware(data, failures):
"""Collect detailed inventory using 'hardware-detect' utility.