OpenSIPS / opensips-cli

OpenSIPS CLI tool - an interactive command line tool that can be used to control and monitor OpenSIPS servers.
GNU General Public License v3.0
86 stars 48 forks source link

OpenSIPS-CLI missing Python module in Ubuntu #82

Closed Lt-Flash closed 3 years ago

Lt-Flash commented 3 years ago

Hi, After installing OpenSIPS-CLI from APT sources (https://apt.opensips.org/packages.php?v=cli) I tried to migrate database from 2.4 to 3.0 and found that one missing dependancy exists under Ubuntu Linux 18.04.5 LTS (at least): python3-pymysql. When trying to run 'opensips-cli -x database migrate' I was getting:

opensips-cli -x database migrate
Traceback (most recent call last):
  File "/usr/bin/opensips-cli", line 9, in <module>
    run_console()
  File "/usr/bin/opensips-cli", line 6, in run_console
    main.main()
  File "/usr/lib/python3/dist-packages/opensipscli/main.py", line 77, in main
    shell = cli.OpenSIPSCLIShell(args)
  File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 85, in __init__
    self.update_instance(cfg.current_instance)
  File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 155, in update_instance
    excl_mod = mod.__exclude__(mod)
  File "/usr/lib/python3/dist-packages/opensipscli/modules/database.py", line 259, in __exclude__
    return (not osdb.has_dialect(osdb.get_dialect(db_url)), None)
  File "/usr/lib/python3/dist-packages/opensipscli/db.py", line 690, in has_dialect
    sqlalchemy.create_engine('{}://'.format(dialect))
  File "/usr/lib/python3/dist-packages/sqlalchemy/engine/__init__.py", line 387, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 80, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/lib/python3/dist-packages/sqlalchemy/dialects/mysql/pymysql.py", line 62, in dbapi
    return __import__('pymysql')
ModuleNotFoundError: No module named 'pymysql'

After installing apt install python3-pymysql:

opensips-cli -x database migrate
Usage: database migrate <flavour> <old-database> <new-database>

The issue is fixed. I believe that MySQL or PgSQL modules should be added to dependancies of opensips-cli? Or at least some warning should exist saying that you need to install appropriate module yourself instead of just falling to an error. Thanks!

liviuchircu commented 3 years ago

Hey, @Lt-Flash! Thank you for the accurate instructions and apologies for the delay. I reproduced this issue on the spot and I'm looking into ways of fixing it. Most likely, the solution will be to add a python3-pymysql dependency for Debian-like systems -- just want to double-check there are no package naming exceptions to handle before pushing the fix.