Merge lp:~blake-rouse/maas/fix-1555864 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4956
Proposed branch: lp:~blake-rouse/maas/fix-1555864
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 45 lines (+19/-1)
2 files modified
src/maasserver/utils/mac.py (+4/-1)
src/maasserver/utils/tests/test_mac.py (+15/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1555864
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+292552@code.launchpad.net

Commit message

Catch UnicodeDecodeError from the netaddr library when get_vendor_for_mac is called.

The netaddr library has an issue in python3 when it comes to getting the registration information for a MAC address. This just catches the failure in MAAS so the Web UI does not crash.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.0 MiB)

The attempt to merge lp:~blake-rouse/maas/fix-1555864 into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Hit:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [92.2 kB]
Hit:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:5 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/main Sources [3,416 B]
Get:6 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [5,400 B]
Get:7 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [2,828 B]
Get:8 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [3,316 B]
Get:9 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [2,440 B]
Fetched 202 kB in 0s (446 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt python3-bson python3-convoy python3-coverage python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-mock python3-netaddr python3-netifaces python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.18-2ubuntu3).
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
bash is already the newest version (4.3-14ubuntu1).
bind9 is already the newest version (1:9.10.3.dfsg.P4-8).
bind9utils is already the newest version (1:9.10.3.dfsg.P4-8).
build-essential is already the newest version (12.1ubuntu2).
bzr is already the newest version (2.7.0-2ubuntu1).
curl is already the newest version (7.47.0-1ubuntu2).
debhelper is already the newe...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/utils/mac.py'
2--- src/maasserver/utils/mac.py 2015-12-01 18:12:59 +0000
3+++ src/maasserver/utils/mac.py 2016-04-21 15:33:03 +0000
4@@ -18,5 +18,8 @@
5 data = EUI(mac)
6 try:
7 return data.oui.registration().org
8- except NotRegisteredError:
9+ except (NotRegisteredError, UnicodeDecodeError):
10+ # UnicodeDecodeError can be raised if the name of the vendor cannot
11+ # be decoded from ascii. This is something broken in the netaddr
12+ # library, we are just catching the error here not to break the UI.
13 return 'Unknown Vendor'
14
15=== modified file 'src/maasserver/utils/tests/test_mac.py'
16--- src/maasserver/utils/tests/test_mac.py 2015-12-01 18:12:59 +0000
17+++ src/maasserver/utils/tests/test_mac.py 2016-04-21 15:33:03 +0000
18@@ -6,8 +6,11 @@
19 __all__ = []
20
21
22+from maasserver.testing.factory import factory
23+from maasserver.utils import mac
24 from maasserver.utils.mac import get_vendor_for_mac
25 from maastesting.testcase import MAASTestCase
26+from mock import MagicMock
27
28
29 class TestGetVendorForMac(MAASTestCase):
30@@ -21,3 +24,15 @@
31 self.assertEqual(
32 "Unknown Vendor",
33 get_vendor_for_mac('aa:bb:cc:dd:ee:ff'))
34+
35+ def test_get_vendor_for_mac_handlers_unicode_error(self):
36+ try:
37+ b'\xD3'.decode('ascii')
38+ except UnicodeDecodeError as exc:
39+ error = exc
40+ eui_result = MagicMock()
41+ eui_result.oui.registration.side_effect = error
42+ self.patch(mac, "EUI").return_value = eui_result
43+ self.assertEqual(
44+ "Unknown Vendor",
45+ get_vendor_for_mac(factory.make_mac_address()))