postgresql - 从 travis-ci 迁移后,Nosetests 无法向 postgres 进行身份验证
问题描述
我正在将构建测试从 travis-ci 迁移到 github 操作,但在尝试运行“nosetests”时遇到了障碍。似乎我无法对之前创建的用户和数据库进行身份验证以进行处理。
.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
运行 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"
任何有关进一步故障排除的帮助或指示将不胜感激。我应该补充一点,我是 Github Actions 的新手,到目前为止已经迁移了相对简单的工作流程。这是迄今为止最复杂的。
解决方案
似乎没有为用户设置密码,但您尝试在测试用例中使用密码登录。
[ ENCRYPTED ] PASSWORD 'password'
PASSWORD NULL
设置角色的密码。...如果未指定密码,则密码将设置为空,并且该用户的密码身份验证将始终失败。
我看不出是否POSTGRES_USER
在您的 Travis 配置中分配了 etc.,所以也许在 Travis 中它实际上是以 rootpostgres
用户而不是awips
.
推荐阅读
- javascript - 如何将指令的范围值作为 $scope 传递给控制器
- chart.js - ChartJS 大数据范围
- reactjs - 登录操作成功后重定向
- python - 即使单词前面或后面有一些字母,是否可以检测到特定单词?(PYTHON)
- ios - TileMap 集中的自定义组未选择正确的图块
- security - 如何将 Solr 配置为仅通过发送 keypass/access-token 来接受请求
- linux - AppStream系统缓存已更新,但发现问题:元数据文件有错误:/var/cache/app-info/xmls/fwupd.xml
- java - ArrayList 中的 Java 自定义整数对象排序
- c# - Sitecore - 显示进度框
- json - 如何从量角器中的嵌套 JSON 结构中读取数据