From 7f0f786c27204938fea7a744688718d81550e005 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 5 Dec 2018 17:49:36 +0100 Subject: [PATCH] Trap handlers: propagate expected BSC id to command processor When receiving commands for particular BSC, log BSC id known at the time when request was made, not the one which is part of the reply. Change-Id: I6acdfddb9a1132f978f2b55c769559b0c29eb3e8 --- osmopy/trap_helper.py | 4 ++-- scripts/ctrl2cgi.py | 6 +++--- scripts/soap.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osmopy/trap_helper.py b/osmopy/trap_helper.py index 45dc527..b7202ac 100644 --- a/osmopy/trap_helper.py +++ b/osmopy/trap_helper.py @@ -55,12 +55,12 @@ def get_type(v): loc = split_type(v) return loc[-1] -def comm_proc(comm, f, log): +def comm_proc(comm, bid, f, log): """ Command processor: takes function f to run for each command """ bsc_id = comm[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format - log.debug("BSC %s commands: %r" % (bsc_id, comm)) + log.debug("BSC %s commands: %r" % (bid, comm)) for t in comm: (_, m) = Ctrl().cmd(*t.split()) f(m) diff --git a/scripts/ctrl2cgi.py b/scripts/ctrl2cgi.py index cd59209..addca2f 100755 --- a/scripts/ctrl2cgi.py +++ b/scripts/ctrl2cgi.py @@ -40,12 +40,12 @@ from osmopy.osmo_ipa import Ctrl assert V(twisted_ipa_version) > V('0.4') -def handle_reply(f, log, resp): +def handle_reply(bid, f, log, resp): """ Reply handler: process raw CGI server response, function f to run for each command """ decoded = json.loads(resp.decode('utf-8')) - comm_proc(decoded.get('commands'), f, log) + comm_proc(decoded.get('commands'), bid, f, log) def gen_hash(params, skey): inp = '' @@ -62,7 +62,7 @@ def gen_hash(params, skey): def make_async_req(dst, par, f_write, f_log): d = post(dst, par) - d.addCallback(collect, partial(handle_reply, f_write, f_log)) # treq's collect helper is handy to get all reply content at once + d.addCallback(collect, partial(handle_reply, par['bsc_id'], f_write, f_log)) # treq's collect helper is handy to get all reply content at once d.addErrback(lambda e: f_log.critical("HTTP POST error %s while trying to register BSC %s on %s" % (e, par['bsc_id'], dst))) # handle HTTP errors return d diff --git a/scripts/soap.py b/scripts/soap.py index 0534000..f771530 100755 --- a/scripts/soap.py +++ b/scripts/soap.py @@ -38,12 +38,12 @@ from osmopy.osmo_ipa import Ctrl assert V(twisted_ipa_version) > V('0.4') -def handle_reply(p, f, log, r): +def handle_reply(p, bid, f, log, r): """ Reply handler: takes function p to process raw SOAP server reply r, function f to run for each command """ repl = p(r) # result is expected to have both commands[] array and error string (could be None) - bsc_id = comm_proc(repl.commands, f, log) + bsc_id = comm_proc(repl.commands, bid, f, log) log.info("Received SOAP response for BSC %s with %d commands, error status: %s" % (bsc_id, len(repl.commands), repl.error)) @@ -89,7 +89,7 @@ class Trap(CTRL): self.factory.log.debug('location-state@%s.%s.%s.%s (%s) => %s' % (net, bsc, bts, trx, params['time_stamp'], data)) ctx = self.factory.client.registerSiteLocation(bsc, float(params['lon']), float(params['lat']), params['position_validity'], params['time_stamp'], params['oper_status'], params['admin_status'], params['policy_status']) d = post(self.factory.location, ctx.envelope) - d.addCallback(collect, partial(handle_reply, ctx.process_reply, self.transport.write, self.factory.log)) # treq's collect helper is handy to get all reply content at once using closure on ctx + d.addCallback(collect, partial(handle_reply, ctx.process_reply, params['bsc_id'], self.transport.write, self.factory.log)) # treq's collect helper is handy to get all reply content at once using closure on ctx d.addErrback(lambda e, bsc: self.factory.log.critical("HTTP POST error %s while trying to register BSC %s on %s" % (e, bsc, self.factory.location)), bsc) # handle HTTP errors # Ensure that we run only limited number of requests in parallel: yield self.factory.semaphore.acquire()