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
1=== modified file 'debian/utah.postinst'
2--- debian/utah.postinst 2012-10-04 11:45:00 +0000
3+++ debian/utah.postinst 2012-10-31 15:59:21 +0000
4@@ -15,8 +15,16 @@
5 function dnssetup
6 {
7 # Check that interface is up and has address assigned to it
8- interface_up=$(python -c "import netifaces; \
9- print netifaces.AF_INET in netifaces.ifaddresses('${TAPBR}')")
10+ interface_up=$(python<<EOD
11+import netifaces
12+
13+if '$TAPBR' in netifaces.interfaces():
14+ print netifaces.AF_INET in netifaces.ifaddresses('$TAPBR')
15+else:
16+ print False
17+
18+EOD
19+)
20 if [ "${interface_up}" == "True" ]
21 then
22 # Get address assigned to the interface

Subscribers

People subscribed via source and target branches