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
=== modified file 'src/maasserver/listener.py'
--- src/maasserver/listener.py 2016-10-24 14:02:17 +0000
+++ src/maasserver/listener.py 2016-11-15 15:18:16 +0000
@@ -160,8 +160,20 @@
160 if self.isSystemChannel(notify.channel):160 if self.isSystemChannel(notify.channel):
161 # System level message; pass it to the registered161 # System level message; pass it to the registered
162 # handler immediately.162 # handler immediately.
163 handler = self.listeners[notify.channel][0]163 if notify.channel in self.listeners:
164 handler(notify.channel, notify.payload)164 # Be defensive in that if a handler does not exist
165 # for this channel then the channel should be
166 # unregisted and removed from listeners.
167 if len(self.listeners[notify.channel]) > 0:
168 handler = self.listeners[notify.channel][0]
169 handler(notify.channel, notify.payload)
170 else:
171 self.unregisterChannel(notify.channel)
172 del self.listeners[notify.channel]
173 else:
174 # Unregister the channel since no listener is
175 # registered for this channel.
176 self.unregisterChannel(notify.channel)
165 else:177 else:
166 # Place non-system messages into the queue to be178 # Place non-system messages into the queue to be
167 # processed.179 # processed.
168180
=== modified file 'src/maasserver/tests/test_listener.py'
--- src/maasserver/tests/test_listener.py 2016-10-24 14:02:17 +0000
+++ src/maasserver/tests/test_listener.py 2016-11-15 15:18:16 +0000
@@ -110,6 +110,39 @@
110110
111 @wait_for_reactor111 @wait_for_reactor
112 @inlineCallbacks112 @inlineCallbacks
113 def test__handles_missing_system_handler_on_notification(self):
114 listener = PostgresListenerService()
115 # Change notifications to a frozenset. This makes sure that
116 # the system message does not go into the queue. Instead if should
117 # call the handler directly in `doRead`.
118 listener.notifications = frozenset()
119 yield listener.startService()
120 yield deferToDatabase(listener.registerChannel, "sys_test")
121 listener.listeners["sys_test"] = []
122 try:
123 yield deferToDatabase(self.send_notification, "sys_test", 1)
124 self.assertFalse("sys_test" in listener.listeners)
125 finally:
126 yield listener.stopService()
127
128 @wait_for_reactor
129 @inlineCallbacks
130 def test__handles_missing_notify_system_listener_on_notification(self):
131 listener = PostgresListenerService()
132 # Change notifications to a frozenset. This makes sure that
133 # the system message does not go into the queue. Instead if should
134 # call the handler directly in `doRead`.
135 listener.notifications = frozenset()
136 yield listener.startService()
137 yield deferToDatabase(listener.registerChannel, "sys_test")
138 try:
139 yield deferToDatabase(self.send_notification, "sys_test", 1)
140 self.assertFalse("sys_test" in listener.listeners)
141 finally:
142 yield listener.stopService()
143
144 @wait_for_reactor
145 @inlineCallbacks
113 def test__calls_handler_on_notification(self):146 def test__calls_handler_on_notification(self):
114 listener = PostgresListenerService()147 listener = PostgresListenerService()
115 dv = DeferredValue()148 dv = DeferredValue()

Subscribers

People subscribed via source and target branches

to all changes: