summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-08-23 17:02:38 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2017-08-23 17:02:38 +0200
commit6610dfe0f58aea6301fa702e7cfd1ae02ba9d4dd (patch)
tree93af7318cb2a7c5ec764789a118cdfed6ece26ff
parente1a26224e7ee2d7223aa1ff10070d49c1caf8600 (diff)
hlr: Use python module instead of cmdline to modify sqlite db
-rwxr-xr-xcheck_dependencies.py1
-rw-r--r--src/osmo_gsm_tester/osmo_hlr.py27
2 files changed, 12 insertions, 16 deletions
diff --git a/check_dependencies.py b/check_dependencies.py
index 2c9e5c3..d9b857c 100755
--- a/check_dependencies.py
+++ b/check_dependencies.py
@@ -23,5 +23,6 @@ import time
import traceback
import yaml
import pydbus
+import sqlite3
print('dependencies ok')
diff --git a/src/osmo_gsm_tester/osmo_hlr.py b/src/osmo_gsm_tester/osmo_hlr.py
index fbcd43e..16548ad 100644
--- a/src/osmo_gsm_tester/osmo_hlr.py
+++ b/src/osmo_gsm_tester/osmo_hlr.py
@@ -20,6 +20,7 @@
import os
import re
import pprint
+import sqlite3
from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
@@ -107,16 +108,6 @@ class OsmoHlr(log.Origin):
log.ctx(proc)
raise log.Error('Exited in error')
- def run_sql_file(self, name, sql_file):
- self.run_local(name, ('/bin/sh', '-c', 'sqlite3 %r < %r' % (self.db_file, sql_file)))
-
- def run_sql(self, name, sql):
- self.dbg('SQL:', repr(sql))
- sql_file = self.run_dir.new_file(name + '.sql')
- with open(sql_file, 'w') as f:
- f.write(sql)
- self.run_sql_file(name, sql_file)
-
def subscriber_add(self, modem, msisdn=None, algo=None):
if msisdn is None:
msisdn = self.suite_run.resources_pool.next_msisdn(modem)
@@ -126,12 +117,16 @@ class OsmoHlr(log.Origin):
if not algo:
algo = self.AUTH_ALGO_COMP128v1 if modem.ki() else self.AUTH_ALGO_NONE
self.log('Add subscriber', msisdn=msisdn, imsi=modem.imsi(), subscriber_id=subscriber_id, algo=algo)
- self.run_sql('add_subscriber',
- 'insert into subscriber (id, imsi, msisdn) values (%r, %r, %r);'
- % (subscriber_id, modem.imsi(), modem.msisdn))
- self.run_sql('add_subscriber',
- 'insert into auc_2g (subscriber_id, algo_id_2g, ki) values (%r, %r, %r);'
- % (subscriber_id, algo, modem.ki()))
+ conn = sqlite3.connect(self.db_file)
+ try:
+ c = conn.cursor()
+ c.execute('insert into subscriber (id, imsi, msisdn) values (?, ?, ?)',
+ (subscriber_id, modem.imsi(), modem.msisdn,))
+ c.execute('insert into auc_2g (subscriber_id, algo_id_2g, ki) values (?, ?, ?)',
+ (subscriber_id, algo, modem.ki(),))
+ conn.commit()
+ finally:
+ conn.close()
return subscriber_id
def conf_for_msc(self):