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
This commit is contained in:
Max 2018-12-05 17:49:36 +01:00
parent 7a04bbca59
commit 7f0f786c27
3 changed files with 8 additions and 8 deletions

View File

@ -55,12 +55,12 @@ def get_type(v):
loc = split_type(v) loc = split_type(v)
return loc[-1] 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 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 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: for t in comm:
(_, m) = Ctrl().cmd(*t.split()) (_, m) = Ctrl().cmd(*t.split())
f(m) f(m)

View File

@ -40,12 +40,12 @@ from osmopy.osmo_ipa import Ctrl
assert V(twisted_ipa_version) > V('0.4') 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 Reply handler: process raw CGI server response, function f to run for each command
""" """
decoded = json.loads(resp.decode('utf-8')) 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): def gen_hash(params, skey):
inp = '' inp = ''
@ -62,7 +62,7 @@ def gen_hash(params, skey):
def make_async_req(dst, par, f_write, f_log): def make_async_req(dst, par, f_write, f_log):
d = post(dst, par) 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 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 return d

View File

@ -38,12 +38,12 @@ from osmopy.osmo_ipa import Ctrl
assert V(twisted_ipa_version) > V('0.4') 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 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) 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)) 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)) 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']) 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 = 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 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: # Ensure that we run only limited number of requests in parallel:
yield self.factory.semaphore.acquire() yield self.factory.semaphore.acquire()