Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/12145 )
Change subject: Trap handlers: propagate expected BSC id to command processor ...................................................................... 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 --- M osmopy/trap_helper.py M scripts/ctrl2cgi.py M scripts/soap.py 3 files changed, 8 insertions(+), 8 deletions(-) Approvals: Jenkins Builder: Verified Harald Welte: Looks good to me, approved 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 @@ 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 @@ 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 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 @@ 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 @@ 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() -- To view, visit https://gerrit.osmocom.org/12145 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: I6acdfddb9a1132f978f2b55c769559b0c29eb3e8 Gerrit-Change-Number: 12145 Gerrit-PatchSet: 1 Gerrit-Owner: Max <msur...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: daniel <dwillm...@sysmocom.de>