From c512fd826427e508a8735a9b54cc770fa09a5368 Mon Sep 17 00:00:00 2001 From: Alton MacDonald Date: Wed, 11 Dec 2013 11:52:28 +0100 Subject: added error exceptions for DB locking and added third state to BTS notification --- hlr_mgmt/RegisterIMEI.py | 2 +- hlr_mgmt/SubscriberMonitor.py | 42 +++++++++++++++++++++++++++-------------- hlr_mgmt/__init__.py | 2 +- hlr_mgmt/templates/bts.mako | 20 ++++++++++++++------ hlr_mgmt/templates/layout.mako | 2 +- hlr_mgmt/templates/scripts.mako | 20 ++++++++------------ hlr_mgmt/views.py | 14 +++++++++----- 7 files changed, 62 insertions(+), 40 deletions(-) diff --git a/hlr_mgmt/RegisterIMEI.py b/hlr_mgmt/RegisterIMEI.py index 3df58a4..6dad6aa 100644 --- a/hlr_mgmt/RegisterIMEI.py +++ b/hlr_mgmt/RegisterIMEI.py @@ -116,7 +116,7 @@ class RegisterIMEI(threading.Thread): def run(self): log.debug("starting RegisterIMEI deamon") - self.sqlconn = sqlite3.connect(self.HLR_DB) + self.sqlconn = sqlite3.connect(self.HLR_DB,60) self.cursor = self.sqlconn.cursor() return self.authorize_imei(self.imei) diff --git a/hlr_mgmt/SubscriberMonitor.py b/hlr_mgmt/SubscriberMonitor.py index 50a4704..e4632d3 100644 --- a/hlr_mgmt/SubscriberMonitor.py +++ b/hlr_mgmt/SubscriberMonitor.py @@ -39,25 +39,39 @@ class SubscriberMonitor(threading.Thread): self.bsc_conn = telnet_backend(ip, port) self.active_subscribers = collections.defaultdict() self.active = True - + + def is_running(self): + return self.active + + def connect_to_db(self): self.sqlconn = sqlite3.connect(self.HLR_DB, check_same_thread = False) self.cursor = self.sqlconn.cursor() + def disconnect_from_db(self): + try: + self.sqlconn.close() + except: + pass + def run(self): - self.get_active_subs() - while(self.active): - self.check_new_subs() - self.get_active_subs() - time.sleep(60) - def stop(self): - self.active = False + self.connect_to_db() + self.get_active_subs() + while(self.active): + try: + self.check_new_subs() + self.get_active_subs() + except sqlite3.OperationalError: + pass + time.sleep(60) + def stop(self): + self.active = False + self.disconnect_from_db() - def restart(self): - self.active_subscribers = collections.defaultdict() - self.active = True - - def is_running(self): - return self.active + def restart(self): + self.active_subscribers = collections.defaultdict() + self.active = True + self.disconnect_from_db() + self.connect_to_db() def get_active_subs(self): # query active subscribers diff --git a/hlr_mgmt/__init__.py b/hlr_mgmt/__init__.py index c5b6350..2b257f8 100644 --- a/hlr_mgmt/__init__.py +++ b/hlr_mgmt/__init__.py @@ -91,7 +91,7 @@ def load_settings(): # mcc_mnc was obtained manually from http://mobile-network-codes.com/mobile-network-codes-country-codes.asp # initiates SubscriberMonitor - subMonitor = SubscriberMonitor(settings['provider'], settings['db'], ip=settings['bsc_ip'] port=settings['bsc_port']) + subMonitor = SubscriberMonitor(settings['provider'], settings['db'], ip=settings['bsc_ip'], port=settings['bsc_port']) subMonitor.setDaemon(True) subMonitor.start() settings['subMonitor'] = subMonitor diff --git a/hlr_mgmt/templates/bts.mako b/hlr_mgmt/templates/bts.mako index 0f7a08b..04159b7 100644 --- a/hlr_mgmt/templates/bts.mako +++ b/hlr_mgmt/templates/bts.mako @@ -12,10 +12,14 @@ % if bts and phys_cfg: @@ -27,10 +31,14 @@
% endif

BTS ${i} - % if bts[i].has_key('ip'): - (${bts[i]['ip']}) + % if bts[i]['oml_state']: + % if bts[i].has_key('ip'): + (${bts[i]['ip']}) + % else: + (OML connected without IP address) + % endif % else: - (not connected) + (OML disconnected) % endif
${bts[i]['description']}

diff --git a/hlr_mgmt/templates/layout.mako b/hlr_mgmt/templates/layout.mako index dabffe5..b259009 100644 --- a/hlr_mgmt/templates/layout.mako +++ b/hlr_mgmt/templates/layout.mako @@ -36,7 +36,7 @@
- +