|
16 | 16 | import subprocess |
17 | 17 | import sys |
18 | 18 | import syslog |
| 19 | + |
19 | 20 | import sonic_device_util |
20 | 21 | from swsscommon import swsscommon |
21 | 22 | from swsssdk import SonicDBConfig, ConfigDBConnector |
@@ -448,28 +449,41 @@ class ControlPlaneAclManager(object): |
448 | 449 | def run(self): |
449 | 450 | # Select Time-out for 10 Seconds |
450 | 451 | SELECT_TIMEOUT_MS = 1000 * 10 |
| 452 | + # Initlaize Global config that loads all database*.json |
451 | 453 | swsscommon.SonicDBConfig.initializeGlobalConfig() |
| 454 | + # Create the Select object |
452 | 455 | sel = swsscommon.Select() |
| 456 | + # Map of Namespace <--> susbcriber table's object |
453 | 457 | config_db_subscriber_table_map = {} |
| 458 | + # Loop through all asic namespaces (if present) and host (namespace='') |
454 | 459 | for namespace in self.config_db_map.keys(): |
455 | | - # Unconditionally update control plane ACLs once at start |
| 460 | + # Unconditionally update control plane ACLs once at start on given namespace |
456 | 461 | self.update_control_plane_acls(namespace) |
457 | | - |
| 462 | + # Connect to Config DB of given namespace |
458 | 463 | acl_db_connector = swsscommon.DBConnector("CONFIG_DB", 0, False, namespace) |
| 464 | + # Subscribe to notifications when ACL tables changes |
459 | 465 | subscribe_acl_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_TABLE_TABLE_NAME) |
| 466 | + # Subscribe to notifications when ACL rule tables changes |
460 | 467 | subscribe_acl_rule_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_RULE_TABLE_NAME) |
| 468 | + # Add both tables to the selectable object |
461 | 469 | sel.addSelectable(subscribe_acl_table) |
462 | 470 | sel.addSelectable(subscribe_acl_rule_table) |
| 471 | + # Update the map |
463 | 472 | config_db_subscriber_table_map[namespace] = [] |
464 | 473 | config_db_subscriber_table_map[namespace].append(subscribe_acl_table) |
465 | 474 | config_db_subscriber_table_map[namespace].append(subscribe_acl_rule_table) |
| 475 | + #Loop on select to see if any event happen on config db of any namespace |
466 | 476 | while True: |
467 | 477 | (state, c) = sel.select(SELECT_TIMEOUT_MS) |
| 478 | + # Continue if select is timeout or selectable object is not return |
468 | 479 | if state != swsscommon.Select.OBJECT: |
469 | 480 | continue |
| 481 | + # Get the corresponding namespace from selectable object |
470 | 482 | namespace = c.getDbNamespace() |
| 483 | + # Pop data of both Subscriber Table object of namespace that got config db acl table event |
471 | 484 | for table in config_db_subscriber_table_map[namespace]: |
472 | 485 | table.pop() |
| 486 | + # Update the Control Plane ACL of the namespace that got config db acl table event |
473 | 487 | self.update_control_plane_acls(namespace) |
474 | 488 |
|
475 | 489 | # ============================= Functions ============================= |
|
0 commit comments