Merge ~mpontillo/maas:subnet-ip-listing-trigger--bug-1761281 into maas:master

Proposed by Mike Pontillo
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 29375308ee460df55f757d78392ceafcf6b907a3
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:subnet-ip-listing-trigger--bug-1761281
Merge into: maas:master
Diff against target: 150 lines (+107/-3)
3 files modified
src/maasserver/triggers/tests/test_init.py (+2/-0)
src/maasserver/triggers/tests/test_websocket_listener.py (+90/-0)
src/maasserver/triggers/websocket.py (+15/-3)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Approve
Review via email: mp+344212@code.launchpad.net

Commit message

LP: #1761281 - Add triggers to update subnet websocket for IP address insert and delete.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b subnet-ip-listing-trigger--bug-1761281 lp:~mpontillo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/2608/console
COMMIT: 11a634aa02a589047c15ec00a2499a9765b87a57

review: Needs Fixing
2937530... by Mike Pontillo

Fix lint.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b subnet-ip-listing-trigger--bug-1761281 lp:~mpontillo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 29375308ee460df55f757d78392ceafcf6b907a3

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/triggers/tests/test_init.py b/src/maasserver/triggers/tests/test_init.py
index 1079ef6..66b1c9a 100644
--- a/src/maasserver/triggers/tests/test_init.py
+++ b/src/maasserver/triggers/tests/test_init.py
@@ -238,6 +238,8 @@ class TestTriggersUsed(MAASServerTestCase):
238 "staticipaddress_ipaddress_domain_insert_notify",238 "staticipaddress_ipaddress_domain_insert_notify",
239 "staticipaddress_ipaddress_domain_update_notify",239 "staticipaddress_ipaddress_domain_update_notify",
240 "staticipaddress_ipaddress_machine_update_notify",240 "staticipaddress_ipaddress_machine_update_notify",
241 "staticipaddress_ipaddress_subnet_delete_notify",
242 "staticipaddress_ipaddress_subnet_insert_notify",
241 "staticipaddress_ipaddress_subnet_update_notify",243 "staticipaddress_ipaddress_subnet_update_notify",
242 "staticroute_staticroute_create_notify",244 "staticroute_staticroute_create_notify",
243 "staticroute_staticroute_delete_notify",245 "staticroute_staticroute_delete_notify",
diff --git a/src/maasserver/triggers/tests/test_websocket_listener.py b/src/maasserver/triggers/tests/test_websocket_listener.py
index 5e69c2d..f7961a2 100644
--- a/src/maasserver/triggers/tests/test_websocket_listener.py
+++ b/src/maasserver/triggers/tests/test_websocket_listener.py
@@ -2220,6 +2220,96 @@ class TestSubnetListener(
2220 finally:2220 finally:
2221 yield listener.stopService()2221 yield listener.stopService()
22222222
2223 @wait_for_reactor
2224 @inlineCallbacks
2225 def test__calls_handler_with_update_on_ip_address_insert(self):
2226 yield deferToDatabase(register_websocket_triggers)
2227 node = yield deferToDatabase(
2228 self.create_node,
2229 {'node_type': NODE_TYPE.MACHINE, 'interface': True})
2230 interface = yield deferToDatabase(
2231 self.get_node_boot_interface, node.system_id)
2232 subnet = yield deferToDatabase(self.create_subnet)
2233
2234 listener = PostgresListenerService()
2235 dv = DeferredValue()
2236 listener.register('subnet', lambda *args: dv.set(args))
2237 yield listener.startService()
2238 try:
2239 yield deferToDatabase(
2240 self.create_staticipaddress, {
2241 "alloc_type": IPADDRESS_TYPE.AUTO,
2242 "interface": interface,
2243 "subnet": subnet,
2244 "ip": "",
2245 })
2246 yield dv.get(timeout=2)
2247 self.assertEqual(('update', '%s' % subnet.id), dv.value)
2248 finally:
2249 yield listener.stopService()
2250
2251 @wait_for_reactor
2252 @inlineCallbacks
2253 def test__calls_handler_with_update_on_ip_address_update(self):
2254 yield deferToDatabase(register_websocket_triggers)
2255 node = yield deferToDatabase(
2256 self.create_node,
2257 {'node_type': NODE_TYPE.MACHINE, 'interface': True})
2258 interface = yield deferToDatabase(
2259 self.get_node_boot_interface, node.system_id)
2260 subnet = yield deferToDatabase(self.create_subnet)
2261 selected_ip = factory.pick_ip_in_network(subnet.get_ipnetwork())
2262 ipaddress = yield deferToDatabase(
2263 self.create_staticipaddress, {
2264 "alloc_type": IPADDRESS_TYPE.AUTO,
2265 "interface": interface,
2266 "subnet": subnet,
2267 "ip": "",
2268 })
2269
2270 listener = PostgresListenerService()
2271 dv = DeferredValue()
2272 listener.register('subnet', lambda *args: dv.set(args))
2273 yield listener.startService()
2274 try:
2275 yield deferToDatabase(
2276 self.update_staticipaddress, ipaddress.id,
2277 {"ip": selected_ip})
2278 yield dv.get(timeout=2)
2279 self.assertEqual(('update', '%s' % subnet.id), dv.value)
2280 finally:
2281 yield listener.stopService()
2282
2283 @wait_for_reactor
2284 @inlineCallbacks
2285 def test__calls_handler_with_update_on_ip_address_delete(self):
2286 yield deferToDatabase(register_websocket_triggers)
2287 node = yield deferToDatabase(
2288 self.create_node,
2289 {'node_type': NODE_TYPE.MACHINE, 'interface': True})
2290 interface = yield deferToDatabase(
2291 self.get_node_boot_interface, node.system_id)
2292 subnet = yield deferToDatabase(self.create_subnet)
2293 ipaddress = yield deferToDatabase(
2294 self.create_staticipaddress, {
2295 "alloc_type": IPADDRESS_TYPE.AUTO,
2296 "interface": interface,
2297 "subnet": subnet,
2298 "ip": "",
2299 })
2300
2301 listener = PostgresListenerService()
2302 dv = DeferredValue()
2303 listener.register('subnet', lambda *args: dv.set(args))
2304 yield listener.startService()
2305 try:
2306 yield deferToDatabase(
2307 self.delete_staticipaddress, ipaddress.id)
2308 yield dv.get(timeout=2)
2309 self.assertEqual(('update', '%s' % subnet.id), dv.value)
2310 finally:
2311 yield listener.stopService()
2312
22232313
2224class TestSpaceListener(2314class TestSpaceListener(
2225 MAASTransactionServerTestCase, TransactionalHelpersMixin):2315 MAASTransactionServerTestCase, TransactionalHelpersMixin):
diff --git a/src/maasserver/triggers/websocket.py b/src/maasserver/triggers/websocket.py
index ec87ae9..e489202 100644
--- a/src/maasserver/triggers/websocket.py
+++ b/src/maasserver/triggers/websocket.py
@@ -709,6 +709,14 @@ STATIC_IP_ADDRESS_NODE_NOTIFY = dedent("""\
709STATIC_IP_ADDRESS_SUBNET_NOTIFY = dedent("""\709STATIC_IP_ADDRESS_SUBNET_NOTIFY = dedent("""\
710 CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$710 CREATE OR REPLACE FUNCTION %s() RETURNS trigger AS $$
711 BEGIN711 BEGIN
712 IF TG_OP = 'INSERT' THEN
713 PERFORM pg_notify('subnet_update',CAST(NEW.subnet_id AS text));
714 RETURN NEW;
715 END IF;
716 IF TG_OP = 'DELETE' THEN
717 PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text));
718 RETURN OLD;
719 END IF;
712 IF OLD.subnet_id != NEW.subnet_id THEN720 IF OLD.subnet_id != NEW.subnet_id THEN
713 IF OLD.subnet_id IS NOT NULL THEN721 IF OLD.subnet_id IS NOT NULL THEN
714 PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text));722 PERFORM pg_notify('subnet_update',CAST(OLD.subnet_id AS text));
@@ -1416,9 +1424,13 @@ def register_websocket_triggers():
1416 # IP address subnet notifications1424 # IP address subnet notifications
1417 register_procedure(1425 register_procedure(
1418 STATIC_IP_ADDRESS_SUBNET_NOTIFY % 'ipaddress_subnet_update_notify')1426 STATIC_IP_ADDRESS_SUBNET_NOTIFY % 'ipaddress_subnet_update_notify')
1419 register_trigger(1427 register_procedure(
1420 "maasserver_staticipaddress",1428 STATIC_IP_ADDRESS_SUBNET_NOTIFY % 'ipaddress_subnet_insert_notify')
1421 "ipaddress_subnet_update_notify", "update")1429 register_procedure(
1430 STATIC_IP_ADDRESS_SUBNET_NOTIFY % 'ipaddress_subnet_delete_notify')
1431 register_triggers(
1432 "maasserver_staticipaddress", "ipaddress_subnet",
1433 events=EVENTS_IUD)
14221434
1423 # IP address domain notifications1435 # IP address domain notifications
1424 register_procedure(1436 register_procedure(

Subscribers

People subscribed via source and target branches