Merge lp:~soren/nova/libvirt-reconnect into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Eric Day
Approved revision: 259
Merged at revision: 262
Proposed branch: lp:~soren/nova/libvirt-reconnect
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 27 lines (+13/-1)
1 file modified
nova/virt/libvirt_conn.py (+13/-1)
To merge this branch: bzr merge lp:~soren/nova/libvirt-reconnect
Reviewer Review Type Date Requested Status
Eric Day (community) Approve
Jay Pipes (community) Approve
Review via email: mp+34063@code.launchpad.net

Commit message

Reconnect to libvirt on broken connection.

Description of the change

If libvirt is restarted, nova-compute gets very sad. This patch makes it detect the failure and reestablish the connection. This is quite handy if one happens to also develop on libvirt.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Nice.

review: Approve
Revision history for this message
Eric Day (eday) wrote :

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/virt/libvirt_conn.py'
2--- nova/virt/libvirt_conn.py 2010-08-18 21:14:24 +0000
3+++ nova/virt/libvirt_conn.py 2010-08-30 13:06:39 +0000
4@@ -84,10 +84,22 @@
5
6 @property
7 def _conn(self):
8- if not self._wrapped_conn:
9+ if not self._wrapped_conn or not self._test_connection():
10+ logging.debug('Connecting to libvirt: %s' % self.libvirt_uri)
11 self._wrapped_conn = self._connect(self.libvirt_uri, self.read_only)
12 return self._wrapped_conn
13
14+ def _test_connection(self):
15+ try:
16+ self._wrapped_conn.getVersion()
17+ return True
18+ except libvirt.libvirtError as e:
19+ if e.get_error_code() == libvirt.VIR_ERR_SYSTEM_ERROR and \
20+ e.get_error_domain() == libvirt.VIR_FROM_REMOTE:
21+ logging.debug('Connection to libvirt broke')
22+ return False
23+ raise
24+
25 def get_uri_and_template(self):
26 if FLAGS.libvirt_type == 'uml':
27 uri = FLAGS.libvirt_uri or 'uml:///system'