Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opensips-cli database create errors with postgres #130

Open
byoungdale opened this issue Aug 28, 2024 · 0 comments
Open

opensips-cli database create errors with postgres #130

byoungdale opened this issue Aug 28, 2024 · 0 comments

Comments

@byoungdale
Copy link

I am getting an error when trying to use opensips-cli to create the database tables on a postgres database. When I use the mysql config, it connects and creates the database and adds the tables with no problems. But, when I try with postgres, I get the error below.

Here is my opensips-cli.cfg with both options.

database_admin_url: postgresql://postgres:[email protected]
database_url: postgresql://postgres:[email protected]
#database_url: mysql://opensips:[email protected]
#database_admin_url: mysql://opensips:[email protected]
root@006fddf43be7:/# opensips-cli -x database create
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.OpenSIPSCLI(args)
File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 90, in __init__
self.update_instance(cfg.current_instance)
File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 166, in update_instance
excl_mod = mod.__exclude__(mod)
File "/usr/lib/python3/dist-packages/opensipscli/modules/database.py", line 469, in __exclude__
return (not osdb.has_dialect(osdb.get_dialect(db_url)), None)
File "/usr/lib/python3/dist-packages/opensipscli/db.py", line 767, in has_dialect
sqlalchemy.create_engine('{}://'.format(dialect))
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/__init__.py", line 520, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/lib/python3/dist-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 778, in dbapi
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

I have confirmed that connecting with postgres via psql works just fine. I'm not super familiar with the opensips-cli python code to know where to go next.

Here is a way to recreate the issue exactly like I am if that helps:

docker compose.yml:

version: "3.9"

networks:
  net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16

services:
  postgres:
    image: postgres:16.4
    ports:
      - 5432:5432
    volumes:
      - ./docker/docker-postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - DB_ANON_ROLE=${DB_ANON_ROLE}
      - DB_SCHEMA=${DB_SCHEMA}
    restart: always
    networks:
      net:
        ipv4_address: 172.20.0.10
  mysql:
    image:
      mysql:8.0
      # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
      # (this is just an example, not intended to be a production configuration)
    command: --default-authentication-plugin mysql_native_password
    volumes:
      - ./docker/docker-mysql/.db_data:/var/lib/mysql
      - ./docker/docker-mysql/initdb/:/docker-entrypoint-initdb.d/
    restart: always
    stdin_open: true
    tty: true
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: opensips
      MYSQL_USER: opensips
      MYSQL_PASSWORD: opensipsrw
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10
    networks:
      net:
        ipv4_address: 172.20.0.13
POSTGRES_USER=postgres POSTGRES_DB=postgres DB_ANON_ROLE=web_anon DB_SCHEMA=postgres POSTGRES_PASSWORD=postgres docker compose up

Run opensips:

docker run -it \
  --network test_net \
  --ip 172.20.0.11 \
  -v ${PWD}/opensips/:/etc/opensips \
  --entrypoint /bin/bash \
  opensips/opensips:latest
(DOCKERSHELL)# opensips-cli -x database create

I am using postgres 16, so maybe something changed. I can try tomorrow on an older version of postgres, and see if that makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant