1
From 742e5512dbee26080f14490292d50278d59f10ac Mon Sep 17 00:00:00 2001
2
From: Chuck Short <chuck.short@canonical.com>
3
Date: Thu, 29 Mar 2012 13:10:22 -0400
4
Subject: [PATCH] Monitor console.log for indefinite growth
6
Using the libvirt serial console, everything
7
that is dumped into a console.log file, this file can
8
keep on growing depending on what the user is doing in the console.
10
This patch adds add a new flag called "use_console_monitor",
11
the console monitor will check the instance's console.log size.
12
If it goes past a certain amount it will warn in the nova-compute.log
13
file that it is growing and when was the file last modified.
15
This bug does not entirely fix bug 832507, but it is a stop
16
gap measure until we can resolve it properly in libvirt
19
Change-Id: I00ebc716dccbe9fb97e2b8a3cb5d5e496bc7719b
20
Signed-off-by: Chuck Short <chuck.short@canonical.com>
22
nova/compute/manager.py | 24 +++++++++++++++++++++++-
23
nova/tests/test_compute.py | 9 +++++++++
24
nova/virt/driver.py | 11 +++++++++++
25
nova/virt/libvirt/connection.py | 13 +++++++++++++
26
4 files changed, 56 insertions(+), 1 deletions(-)
28
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
29
index 48e135b..c5a4bb3 100644
30
--- a/nova/compute/manager.py
31
+++ b/nova/compute/manager.py
32
@@ -118,7 +118,13 @@ compute_opts = [
33
cfg.IntOpt("heal_instance_info_cache_interval",
35
help="Number of seconds between instance info_cache self "
38
+ cfg.BoolOpt("use_console_monitor",
40
+ help="Use scheduler to monitor the console.log."),
41
+ cfg.IntOpt("console_threshold_size",
43
+ help="Max console.log size.")
47
@@ -2393,6 +2399,22 @@ class ComputeManager(manager.SchedulerDependentManager):
48
self._delete_instance(context, instance)
50
@manager.periodic_task
51
+ def run_console_monitor(self, context):
52
+ """Monitor the console.log size for a given instance."""
53
+ if not FLAGS.use_console_monitor:
57
+ LOG.info(_('Running console monitor'))
58
+ instances = self.db.instance_get_all_by_host(context, self.host)
59
+ for instance in instances:
60
+ drv_state = self._get_power_state(context, instance)
61
+ if drv_state == power_state.RUNNING:
62
+ self.driver.monitor_console_log(instance)
63
+ except NotImplementedError:
66
+ @manager.periodic_task
67
def update_available_resource(self, context):
68
"""See driver.update_available_resource()
70
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
71
index 305282c..53dd08f 100644
72
--- a/nova/tests/test_compute.py
73
+++ b/nova/tests/test_compute.py
74
@@ -744,6 +744,15 @@ class ComputeTestCase(BaseTestCase):
75
self.assertEqual(output, 'ANOTHER\nLAST LINE')
76
self.compute.terminate_instance(self.context, instance['uuid'])
78
+ def test_console_monitor(self):
79
+ """Make sure we can montior console from instance"""
80
+ self.flags(use_console_monitor=True)
81
+ context = self.context.elevated()
82
+ instance = self._create_fake_instance()
83
+ self.compute.run_instance(context, instance['uuid'])
84
+ self.compute.run_console_monitor(context)
85
+ self.compute.terminate_instance(self.context, instance['uuid'])
87
def test_novnc_vnc_console(self):
88
"""Make sure we can a vnc console for an instance."""
89
instance = self._create_fake_instance()
90
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
91
index 9658273..e0a0ca1 100644
92
--- a/nova/virt/driver.py
93
+++ b/nova/virt/driver.py
94
@@ -663,6 +663,17 @@ class ComputeDriver(object):
95
related to other calls into the driver. The prime example is to clean
96
the cache and remove images which are no longer of interest.
100
+ def monitor_console_log(self, instance):
102
+ Manage the drivers console.log
104
+ Some drives just dump the serial console to a file. This method
105
+ monitors the console.log, so the console.log file can remain
110
def add_to_aggregate(self, context, aggregate, host, **kwargs):
111
"""Add a compute host to an aggregate."""
112
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
113
index 3c4bbb0..10e4cf1 100644
114
--- a/nova/virt/libvirt/connection.py
115
+++ b/nova/virt/libvirt/connection.py
116
@@ -2434,6 +2434,19 @@ class LibvirtConnection(driver.ComputeDriver):
117
"""Manage the local cache of images."""
118
self.image_cache_manager.verify_base_images(context)
120
+ def monitor_console_log(self, instance):
121
+ console_log_file = os.path.join(FLAGS.instances_path,
124
+ if os.path.exists(console_log_file):
125
+ stat = os.stat(console_log_file)
126
+ if stat.st_size >= FLAGS.console_threshold_size:
127
+ size = stat.st_size
128
+ file_acess_time = stat.st_mtime
129
+ LOG.warn(_('console.log size: %(size)s bytes, '
130
+ 'last accessed: %(file_acess_time)s.')
131
+ % locals(), instance=instance)
133
@exception.wrap_exception()
134
def migrate_disk_and_power_off(self, context, instance, dest,
135
instance_type, network_info):