Max has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/12421 )

Change subject: ctrl2cgi: explicitly ignore unrelated TRAPs
......................................................................

ctrl2cgi: explicitly ignore unrelated TRAPs

Previously we've tried to determine the type of TRAP and handle as many
as possible via generic method dispatcher similar to parent class. Let's
make code simpler by explicitly ignoring all but 'location-state'
TRAPs. This should also reduce debug log output because we'll only log
the TRAP variable for ignored messages instead of entire content.

Change-Id: I42b715cb82eb309950ff387649726504b6c7cf61
Related: SYS#4399
---
M scripts/ctrl2cgi.py
1 file changed, 6 insertions(+), 12 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/scripts/ctrl2cgi.py b/scripts/ctrl2cgi.py
index 2cf386c..bb5c93e 100755
--- a/scripts/ctrl2cgi.py
+++ b/scripts/ctrl2cgi.py
@@ -22,7 +22,7 @@
  */
 """

-__version__ = "0.0.9" # bump this on every non-trivial change
+__version__ = "0.1.0" # bump this on every non-trivial change

 import argparse, os, logging, logging.handlers, datetime
 import hashlib
@@ -89,11 +89,11 @@
         """
         Parse CTRL TRAP and dispatch to appropriate handler after normalization
         """
-        self.factory.log.debug('TRAP %s' % v)
-        t_type = get_type(v)
-        p = p_h(v)
-        method = getattr(self, 'handle_' + t_type.replace('-', ''), lambda *_: 
"Unhandled %s trap" % t_type)
-        method(p(1), p(3), p(5), p(7), get_r(v))
+        if get_type(v) == 'location-state':
+            p = p_h(v)
+            self.handle_locationstate(p(1), p(3), p(5), p(7), get_r(v))
+        else:
+            self.factory.log.debug('Ignoring TRAP %s' % (v.split()[0]))

     def ctrl_SET_REPLY(self, data, _, v):
         """
@@ -126,12 +126,6 @@
         # Ensure that we run only limited number of requests in parallel:
         self.factory.semaphore.run(make_async_req, t, self.factory.location, 
params, self.transport.write, self.factory.log, self.factory.timeout)

-    def handle_notificationrejectionv1(self, net, bsc, bts, trx, data):
-        """
-        Handle notification-rejection-v1 TRAP: just an example to show how 
more message types can be handled
-        """
-        self.factory.log.debug('notification-rejection-v1@bsc-id %s => %s' % 
(bsc, data))
-

 class TrapFactory(IPAFactory):
     """

--
To view, visit https://gerrit.osmocom.org/12421
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I42b715cb82eb309950ff387649726504b6c7cf61
Gerrit-Change-Number: 12421
Gerrit-PatchSet: 3
Gerrit-Owner: Max <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <[email protected]>
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>

Reply via email to