Merge lp:~niedbalski/uvtool/fixes-lp-1428674 into lp:~uvtool-dev/uvtool/trunk

Proposed by Jorge Niedbalski
Status: Rejected
Rejected by: Robie Basak
Proposed branch: lp:~niedbalski/uvtool/fixes-lp-1428674
Merge into: lp:~uvtool-dev/uvtool/trunk
Diff against target: 36 lines (+16/-5)
1 file modified
uvtool/libvirt/__init__.py (+16/-5)
To merge this branch: bzr merge lp:~niedbalski/uvtool/fixes-lp-1428674
Reviewer Review Type Date Requested Status
Robie Basak Needs Fixing
uvtool development Pending
Review via email: mp+251969@code.launchpad.net

Description of the change

Proposed fix for #1428674

To post a comment you must log in.
94. By Jorge Niedbalski

Fixed file size

Revision history for this message
Robie Basak (racb) wrote :

This doesn't fix "uvt-kvm wait", which runs inotify on the default.leases file. Commented in the bug, as I think that we need to discuss the general approach.

A couple of comments on this MP specifically:

Why 1 instead of 0 for the file size? I presume you need it because you added another commit changing it, but I'd like to see a comment in the code explaining why.

1, 2, 3 and 0 as arguments to _filter_mac should be named constants or carry an explanation of what they are some other way.

review: Needs Fixing
Revision history for this message
Robie Basak (racb) wrote :

I think this has since been resolved in a different way.

Unmerged revisions

94. By Jorge Niedbalski

Fixed file size

93. By Jorge Niedbalski

[niedbalski, r=] Fixes bugs LP #1428674 and LP #1420142
 - Since libvirt v1.2.11 though, libvirt adds --leasefile-ro which stops it
   updating the dnsmasq lease file and makes libvirt store the leases itself.
 - This patch uses /proc/net/arp as a fallback in case no leasefile exist.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'uvtool/libvirt/__init__.py'
2--- uvtool/libvirt/__init__.py 2014-01-23 17:21:41 +0000
3+++ uvtool/libvirt/__init__.py 2015-03-05 16:25:47 +0000
4@@ -31,6 +31,7 @@
5 from lxml.builder import E
6
7 LIBVIRT_DNSMASQ_LEASE_FILE = '/var/lib/libvirt/dnsmasq/default.leases'
8+PROCFS_ARP = '/proc/net/arp'
9
10
11 def get_libvirt_pool_object(libvirt_conn, pool_name):
12@@ -238,9 +239,19 @@
13
14 def mac_to_ip(mac):
15 canonical_mac = mac.lower()
16- with codecs.open(LIBVIRT_DNSMASQ_LEASE_FILE, 'r') as f:
17- for line in f:
18- fields = line.split()
19- if len(fields) > 1 and fields[1].lower() == canonical_mac:
20- return fields[2]
21+
22+ def _filter_mac(path, mac, mac_f, ip_f):
23+ with codecs.open(path, 'r') as ff:
24+ for line in ff:
25+ fields = line.split()
26+ if len(fields) > 1 and fields[mac_f].lower() == mac:
27+ return fields[ip_f]
28 return None
29+
30+ if os.path.exists(LIBVIRT_DNSMASQ_LEASE_FILE) and \
31+ os.path.getsize(LIBVIRT_DNSMASQ_LEASE_FILE) > 1:
32+ return _filter_mac(LIBVIRT_DNSMASQ_LEASE_FILE, canonical_mac, 1, 2)
33+ elif os.path.exists(PROCFS_ARP):
34+ return _filter_mac(PROCFS_ARP, canonical_mac, 3, 0)
35+
36+ return None

Subscribers

People subscribed via source and target branches