diff options
| author | Michael Still <mikal@stillhq.com> | 2012-11-21 21:43:12 +1100 |
|---|---|---|
| committer | Michael Still <michael.still@canonical.com> | 2012-11-23 07:09:53 +1100 |
| commit | fc4f4bd09a0ef3a65514c5dc733c7b2fd6ac7ead (patch) | |
| tree | 2bded36ce01d5b8a94724f46b113d5f9260e8c4c /nova/virt | |
| parent | 2d6abe49c35ab5c6200164455631a259eefe7457 (diff) | |
Truncate large console logs in libvirt.
Resolves bug 1081436 where they were returning a 5.5gb console log
to the user.
Change-Id: I0d98c83e801f8936d35789b5e8f8283f49483c4e
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/libvirt/driver.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 14e8a75d2..69e4921bc 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -195,6 +195,8 @@ DEFAULT_FIREWALL_DRIVER = "%s.%s" % ( libvirt_firewall.__name__, libvirt_firewall.IptablesFirewallDriver.__name__) +MAX_CONSOLE_BYTES = 102400 + def patch_tpool_proxy(): """eventlet.tpool.Proxy doesn't work with old-style class in __str__() @@ -1145,7 +1147,14 @@ class LibvirtDriver(driver.ComputeDriver): if not path: continue libvirt_utils.chown(path, os.getuid()) - return libvirt_utils.load_file(path) + + with libvirt_utils.file_open(path, 'rb') as fp: + log_data, remaining = utils.last_bytes(fp, + MAX_CONSOLE_BYTES) + if remaining > 0: + LOG.info(_('Truncated console log returned, %d bytes ' + 'ignored'), remaining, instance=instance) + return log_data # Try 'pty' types if console_types.get('pty'): @@ -1166,7 +1175,12 @@ class LibvirtDriver(driver.ComputeDriver): console_log = self._get_console_log_path(instance['name']) fpath = self._append_to_file(data, console_log) - return libvirt_utils.load_file(fpath) + with libvirt_utils.file_open(fpath, 'rb') as fp: + log_data, remaining = utils.last_bytes(fp, MAX_CONSOLE_BYTES) + if remaining > 0: + LOG.info(_('Truncated console log returned, %d bytes ignored'), + remaining, instance=instance) + return log_data @staticmethod def get_host_ip_addr(): |
