从 travis-ci 迁移后,Nosetests 无法向 postgres 进行身份验证

Nosetests cannot authenticate to postgres after migration from travis-ci

我正在将构建测试从 travis-ci 迁移到 github 操作,但是在尝试 运行 时遇到了障碍 运行 “鼻子测试”。我似乎无法对之前创建的用户和数据库进行身份验证以进行处理。

.travis.yml 文件中的相关逻辑如下所示:

services:
  - postgresql

before_script:
  - psql -c 'create role awips superuser createdb createrole inherit login;' -U postgres
  - psql -c 'create database metadata;' -U postgres
  - psql -c 'grant all privileges on database metadata to awips;' -U postgres

# command to run tests
script:
  - nosetests -a UNIT --with-coverage --cover-package=mi

我尝试将以上内容翻译成与 github 操作一起使用,如下所示:

      services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_DB: postgres
          POSTGRES_HOST: postgres
          POSTGRES_PORT: 5432
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

      - name: Install PostgreSQL client
        run: |
          sudo apt-get update
          sudo apt-get install --yes postgresql-client
      - run: psql -c 'create role awips superuser createdb createrole inherit login;' -h localhost -U postgres postgres
        env: 
          PGPASSWORD: postgres
      - name create metadata database and awips role
        run: psql -c 'create database metadata;' -h localhost -U postgres postgres
        env: 
          PGPASSWORD: postgres
      - run: psql -c 'grant all privileges on database metadata to awips;' -h localhost -U postgres postgres
        env: 
          PGPASSWORD: postgres

      - name: Run tests
        run: nosetests -a UNIT --with-coverage --cover-package=mi
        env: 
          POSTGRES_DB: metadata
          POSTGRES_USER: awips
          POSTGRES_PASSWORD: awips
          POSTGRES_HOST: localhost
          POSTGRES_PORT: 5432

在 运行ning 大约 15 分钟后,nosetests 命令失败并出现许多错误,其中大部分如下所示:

======================================================================
ERROR: test_createRecords_fail_badItemType (mi.core.test.test_persistent_store.TestPersistentStoreDict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/mi-instrument/mi-instrument/mi/core/test/test_persistent_store.py", line 38, in setUp
    self.persistentStoreDict = PersistentStoreDict("unit_test", "GI01SUMO-00001")
  File "/home/runner/work/mi-instrument/mi-instrument/mi/core/persistent_store.py", line 68, in __init__
    self.__setupDatabase()
  File "/home/runner/work/mi-instrument/mi-instrument/mi/core/persistent_store.py", line 132, in __setupDatabase
    with self.databaseSession as cur:
  File "/home/runner/work/mi-instrument/mi-instrument/mi/core/persistent_store.py", line 31, in __enter__
    self.conn = psycopg2.connect(database = self.database, user = self.user, password = self.password, host = self.host, port = self.port)
  File "/usr/share/miniconda/envs/test/lib/python2.7/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
OperationalError: FATAL:  password authentication failed for user "awips"

如能提供进一步故障排除的任何帮助或指示,我们将不胜感激ci。我应该补充一点,我是 Github Actions 的新手,到目前为止已经迁移了相对简单的工作流程。这是迄今为止最复杂的。

似乎没有为用户设置密码,但您正尝试在测试用例中使用密码登录。

CREATE ROLL:

[ ENCRYPTED ] PASSWORD 'password'
PASSWORD NULL
Sets the role's password. ... If no password is specified, the password will be set to null and password authentication will always fail for that user.

我没有看到是否在您的 Travis 配置中分配了 POSTGRES_USER 等,所以也许在 Travis 中它真的是以根 postgres 用户而不是 awips.