Skip to content

opensips-cli database create errors with postgres #130

@byoungdale

Description

@byoungdale

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:postgres@172.20.0.10
database_url: postgresql://postgres:postgres@172.20.0.10
#database_url: mysql://opensips:opensipsrw@172.20.0.13
#database_admin_url: mysql://opensips:opensipsrw@172.20.0.13
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions