Home > Software engineering >  Nosetests cannot authenticate to postgres after migration from travis-ci
Nosetests cannot authenticate to postgres after migration from travis-ci

Time:10-10

I am in the process of migrating build tests from travis-ci to github actions, but have run into a road block when trying to run “nosetests”. It seems that I am unable to authenticate to a user and database created earlier in to process.

The relevant logic from .travis.yml file looks like this:

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

My attempt to translate the above for use with github actions looks like this:

      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

After running for 15 minutes or so, the nosetests command fails with many errors, most of which look like this:

======================================================================
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"

Any help or pointers for further troubleshooting would be greatly appreciated. I should add that I’m brand new to Github Actions and so far have migrated relatively simple workflows. This is by far the most complex.

CodePudding user response:

No password appears to be set for the user, but you are trying to log in with a password in your test cases.

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.

I don't see whether POSTGRES_USER etc. are assigned in your Travis config, so perhaps in Travis it was really logging in as the root postgres user and not as awips.

  • Related