Merge lp:~blake-rouse/maas/fix-1640300-2.1 into lp:maas/2.1

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5549
Proposed branch: lp:~blake-rouse/maas/fix-1640300-2.1
Merge into: lp:maas/2.1
Diff against target: 70 lines (+47/-2)
2 files modified
src/maasserver/listener.py (+14/-2)
src/maasserver/tests/test_listener.py (+33/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1640300-2.1
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+310894@code.launchpad.net

Commit message

Be defensive in the postgresql listener when a system notification is received for a none existed handler or missing listener channel.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Self-approving backport.

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

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

Hit:1 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:4 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease
Fetched 95.7 kB in 0s (245 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils 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 isc-dhcp-server 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-attr python3-bson python3-convoy 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-netaddr python3-netifaces python3-novaclient 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...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest v...

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

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

Hit:1 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
Get:3 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Hit:4 http://prodstack-zone-1.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease
Fetched 190 kB in 0s (405 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils 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 isc-dhcp-server 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-attr python3-bson python3-convoy 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-netaddr python3-netifaces python3-novaclient 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...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/listener.py'
2--- src/maasserver/listener.py 2016-10-24 14:02:17 +0000
3+++ src/maasserver/listener.py 2016-11-15 15:18:16 +0000
4@@ -160,8 +160,20 @@
5 if self.isSystemChannel(notify.channel):
6 # System level message; pass it to the registered
7 # handler immediately.
8- handler = self.listeners[notify.channel][0]
9- handler(notify.channel, notify.payload)
10+ if notify.channel in self.listeners:
11+ # Be defensive in that if a handler does not exist
12+ # for this channel then the channel should be
13+ # unregisted and removed from listeners.
14+ if len(self.listeners[notify.channel]) > 0:
15+ handler = self.listeners[notify.channel][0]
16+ handler(notify.channel, notify.payload)
17+ else:
18+ self.unregisterChannel(notify.channel)
19+ del self.listeners[notify.channel]
20+ else:
21+ # Unregister the channel since no listener is
22+ # registered for this channel.
23+ self.unregisterChannel(notify.channel)
24 else:
25 # Place non-system messages into the queue to be
26 # processed.
27
28=== modified file 'src/maasserver/tests/test_listener.py'
29--- src/maasserver/tests/test_listener.py 2016-10-24 14:02:17 +0000
30+++ src/maasserver/tests/test_listener.py 2016-11-15 15:18:16 +0000
31@@ -110,6 +110,39 @@
32
33 @wait_for_reactor
34 @inlineCallbacks
35+ def test__handles_missing_system_handler_on_notification(self):
36+ listener = PostgresListenerService()
37+ # Change notifications to a frozenset. This makes sure that
38+ # the system message does not go into the queue. Instead if should
39+ # call the handler directly in `doRead`.
40+ listener.notifications = frozenset()
41+ yield listener.startService()
42+ yield deferToDatabase(listener.registerChannel, "sys_test")
43+ listener.listeners["sys_test"] = []
44+ try:
45+ yield deferToDatabase(self.send_notification, "sys_test", 1)
46+ self.assertFalse("sys_test" in listener.listeners)
47+ finally:
48+ yield listener.stopService()
49+
50+ @wait_for_reactor
51+ @inlineCallbacks
52+ def test__handles_missing_notify_system_listener_on_notification(self):
53+ listener = PostgresListenerService()
54+ # Change notifications to a frozenset. This makes sure that
55+ # the system message does not go into the queue. Instead if should
56+ # call the handler directly in `doRead`.
57+ listener.notifications = frozenset()
58+ yield listener.startService()
59+ yield deferToDatabase(listener.registerChannel, "sys_test")
60+ try:
61+ yield deferToDatabase(self.send_notification, "sys_test", 1)
62+ self.assertFalse("sys_test" in listener.listeners)
63+ finally:
64+ yield listener.stopService()
65+
66+ @wait_for_reactor
67+ @inlineCallbacks
68 def test__calls_handler_on_notification(self):
69 listener = PostgresListenerService()
70 dv = DeferredValue()

Subscribers

People subscribed via source and target branches

to all changes: