nickvsnetworking / pyhss

Python HSS / Diameter Server
GNU Affero General Public License v3.0
72 stars 60 forks source link

service `hssService.py` not starting #172

Closed hamidrhashmi closed 10 months ago

hamidrhashmi commented 1 year ago

I have been trying to start hssService.py but its giving me the following error

[10/20/2023 06:52:29] [INFO]

 ######            ##   ##   #####    #####
 ##   ##           ##   ##  ##   ##  ##   ##
 ##   ##  ##  ##   ##   ##  ##       ##
 ######   ##  ##   #######   #####    #####
 ##       ##  ##   ##   ##       ##       ##
 ##       ##  ##   ##   ##  ##   ##  ##   ##
 ##        #####   ##   ##   #####    #####
              ##
           ####

                 HSS Service

[10/20/2023 06:52:29] [INFO] Reading IMEI TAC database CSV from /etc/pyhss/tac_database_Nov2022.csv
[10/20/2023 06:52:29] [ERROR] Failed to read CSV file of IMEI TAC database
2023-10-20 06:52:29,657 INFO sqlalchemy.engine.Engine SELECT DATABASE()
2023-10-20 06:52:29,658 INFO sqlalchemy.engine.Engine [raw sql] ()
2023-10-20 06:52:29,660 INFO sqlalchemy.engine.Engine SELECT @@sql_mode
2023-10-20 06:52:29,660 INFO sqlalchemy.engine.Engine [raw sql] ()
2023-10-20 06:52:29,664 INFO sqlalchemy.engine.Engine SELECT @@lower_case_table_names
2023-10-20 06:52:29,665 INFO sqlalchemy.engine.Engine [raw sql] ()
2023-10-20 06:52:29,667 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2023-10-20 06:52:29,667 INFO sqlalchemy.engine.Engine SHOW FULL TABLES FROM `hss2`
2023-10-20 06:52:29,667 INFO sqlalchemy.engine.Engine [raw sql] ()
2023-10-20 06:52:29,672 INFO sqlalchemy.engine.Engine ROLLBACK
2023-10-20 06:52:29,673 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2023-10-20 06:52:29,677 INFO sqlalchemy.engine.Engine
CREATE TABLE operation_log (
        id INTEGER NOT NULL AUTO_INCREMENT,
        item_id INTEGER NOT NULL,
        operation_id VARCHAR(36) NOT NULL,
        operation VARCHAR(10),
        changes TEXT,
        last_modified VARCHAR(100),
        timestamp DATETIME,
        table_name VARCHAR(255),
        apn_id INTEGER,
        subscriber_routing_id INTEGER,
        serving_apn_id INTEGER,
        auc_id INTEGER,
        subscriber_id INTEGER,
        ims_subscriber_id INTEGER,
        charging_rule_id INTEGER,
        tft_id INTEGER,
        eir_id INTEGER,
        imsi_imei_history_id INTEGER,
        subscriber_attributes_id INTEGER,
        PRIMARY KEY (id),
        FOREIGN KEY(apn_id) REFERENCES apn (apn_id),
        FOREIGN KEY(subscriber_routing_id) REFERENCES subscriber_routing (subscriber_routing_id),
        FOREIGN KEY(serving_apn_id) REFERENCES serving_apn (serving_apn_id),
        FOREIGN KEY(auc_id) REFERENCES auc (auc_id),
        FOREIGN KEY(subscriber_id) REFERENCES subscriber (subscriber_id),
        FOREIGN KEY(ims_subscriber_id) REFERENCES ims_subscriber (ims_subscriber_id),
        FOREIGN KEY(charging_rule_id) REFERENCES charging_rule (charging_rule_id),
        FOREIGN KEY(tft_id) REFERENCES tft (tft_id),
        FOREIGN KEY(eir_id) REFERENCES eir (eir_id),
        FOREIGN KEY(imsi_imei_history_id) REFERENCES eir_history (imsi_imei_history_id),
        FOREIGN KEY(subscriber_attributes_id) REFERENCES subscriber_attributes (subscriber_attributes_id)
)

2023-10-20 06:52:29,678 INFO sqlalchemy.engine.Engine [no key 0.00172s] ()
2023-10-20 06:52:29,682 INFO sqlalchemy.engine.Engine ROLLBACK
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 748, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb.OperationalError: (1824, "Failed to open the referenced table 'apn'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/etc/pyhss/services/hssService.py", line 100, in <module>
    hssService = HssService()
  File "/etc/pyhss/services/hssService.py", line 31, in __init__
    self.diameterLibrary = Diameter(logTool=self.logTool, originHost=self.originHost, originRealm=self.originRealm, productName=self.productName, mcc=self.mcc, mnc=self.mnc)
  File "/etc/pyhss/lib/diameter.py", line 39, in __init__
    self.database = Database(logTool=logTool)
  File "/etc/pyhss/lib/database.py", line 310, in __init__
    Base.metadata.tables[table_name].create(bind=self.engine)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/schema.py", line 1149, in create
    bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 3226, in _run_ddl_visitor
    conn._run_ddl_visitor(visitorcallable, element, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2430, in _run_ddl_visitor
    visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/visitors.py", line 670, in traverse_single
    return meth(obj, **kw)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/ddl.py", line 963, in visit_table
    )._invoke_with(self.connection)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/ddl.py", line 315, in _invoke_with
    return bind.execute(self)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1414, in execute
    return meth(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/ddl.py", line 181, in _execute_on_connection
    return connection._execute_ddl(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1526, in _execute_ddl
    ret = self._execute_context(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context
    return self._exec_single_context(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2326, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 748, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.10/dist-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1824, "Failed to open the referenced table 'apn'")
[SQL:
CREATE TABLE operation_log (
        id INTEGER NOT NULL AUTO_INCREMENT,
        item_id INTEGER NOT NULL,
        operation_id VARCHAR(36) NOT NULL,
        operation VARCHAR(10),
        changes TEXT,
        last_modified VARCHAR(100),
        timestamp DATETIME,
        table_name VARCHAR(255),
        apn_id INTEGER,
        subscriber_routing_id INTEGER,
        serving_apn_id INTEGER,
        auc_id INTEGER,
        subscriber_id INTEGER,
        ims_subscriber_id INTEGER,
        charging_rule_id INTEGER,
        tft_id INTEGER,
        eir_id INTEGER,
        imsi_imei_history_id INTEGER,
        subscriber_attributes_id INTEGER,
        PRIMARY KEY (id),
        FOREIGN KEY(apn_id) REFERENCES apn (apn_id),
        FOREIGN KEY(subscriber_routing_id) REFERENCES subscriber_routing (subscriber_routing_id),
        FOREIGN KEY(serving_apn_id) REFERENCES serving_apn (serving_apn_id),
        FOREIGN KEY(auc_id) REFERENCES auc (auc_id),
        FOREIGN KEY(subscriber_id) REFERENCES subscriber (subscriber_id),
        FOREIGN KEY(ims_subscriber_id) REFERENCES ims_subscriber (ims_subscriber_id),
        FOREIGN KEY(charging_rule_id) REFERENCES charging_rule (charging_rule_id),
        FOREIGN KEY(tft_id) REFERENCES tft (tft_id),
        FOREIGN KEY(eir_id) REFERENCES eir (eir_id),
        FOREIGN KEY(imsi_imei_history_id) REFERENCES eir_history (imsi_imei_history_id),
        FOREIGN KEY(subscriber_attributes_id) REFERENCES subscriber_attributes (subscriber_attributes_id)
)

]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

where i can find the file /etc/pyhss/tac_database_Nov2022.csv and the database schema to create tables?

davidkneipp commented 10 months ago

Hi hamidrhashmi, this has been fixed in https://github.com/nickvsnetworking/pyhss/releases/tag/1.0.1