Merge lp:~nuclearbob/utah/no-virbr0-postinst-fix into lp:utah

Proposed by Max Brustkern
Status: Merged
Approved by: Javier Collado
Approved revision: 722
Merged at revision: 735
Proposed branch: lp:~nuclearbob/utah/no-virbr0-postinst-fix
Merge into: lp:utah
Diff against target: 22 lines (+10/-2)
1 file modified
debian/utah.postinst (+10/-2)
To merge this branch: bzr merge lp:~nuclearbob/utah/no-virbr0-postinst-fix
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Needs Resubmitting
Review via email: mp+131211@code.launchpad.net

Description of the change

If we install the utah package on a machine that has virbr0 configured as TAPBR by libvirt, but virbr0 is not actually up, the postinst will give a ValueError when trying to get through address through netifaces. This change wraps that in a try block and prints False in the case of a value error.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

What about checking the interface before trying to access its data with something like:
if $TAPBR in netifaces.interfaces():
    print netifaces.AF_INET in netifaces.ifaddresses('$TAPBR')
else:
    print False

I don't like much catching exceptions for conditions that can be checked before accessing
some invalid value.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

That seems reasonable to me. I'll update that and resubmit when it's ready.

721. By Nuclear Bob <max@daedelus>

Changed iface check based on Javier's suggestion

Revision history for this message
Max Brustkern (nuclearbob) wrote :

Updated the iface check.

review: Needs Resubmitting
722. By Nuclear Bob <max@daedelus>

Quoted $TAPBR properly

Revision history for this message
Javier Collado (javier.collado) wrote :

Looks nice now. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/utah.postinst'
--- debian/utah.postinst 2012-10-04 11:45:00 +0000
+++ debian/utah.postinst 2012-10-31 15:59:21 +0000
@@ -15,8 +15,16 @@
15 function dnssetup15 function dnssetup
16 {16 {
17 # Check that interface is up and has address assigned to it17 # Check that interface is up and has address assigned to it
18 interface_up=$(python -c "import netifaces; \18 interface_up=$(python<<EOD
19 print netifaces.AF_INET in netifaces.ifaddresses('${TAPBR}')")19import netifaces
20
21if '$TAPBR' in netifaces.interfaces():
22 print netifaces.AF_INET in netifaces.ifaddresses('$TAPBR')
23else:
24 print False
25
26EOD
27)
20 if [ "${interface_up}" == "True" ]28 if [ "${interface_up}" == "True" ]
21 then29 then
22 # Get address assigned to the interface30 # Get address assigned to the interface

Subscribers

People subscribed via source and target branches