Skip to content

Unable to run CI tests on password-protected DB #3762

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

Closed
ltalirz opened this issue Feb 16, 2020 · 13 comments
Closed

Unable to run CI tests on password-protected DB #3762

ltalirz opened this issue Feb 16, 2020 · 13 comments

Comments

@ltalirz
Copy link
Member

ltalirz commented Feb 16, 2020

It seems something changed in the postgresql configuration on github actions:
https://github.com/aiidateam/aiida-core/pull/3760/checks?check_run_id=448911931#step:8:32

E.g. one might expect something like this, if the configuration in the pg_hba.conf was changed from "trust" to "md5" (see also here ).

@ltalirz
Copy link
Member Author

ltalirz commented Feb 16, 2020

@sphuber One question:

I see that we are using both this;

- uses: harmon758/postgresql-action@v1
with:
postgresql version: '11'
postgresql db: test_${{ matrix.backend }}
postgresql user: 'postgres'
postgresql password: ''

and this

sudo apt install postgresql postgresql-server-dev-all postgresql-client rabbitmq-server graphviz

Is both necessary?

@ltalirz
Copy link
Member Author

ltalirz commented Feb 16, 2020

One simple fix might just be to switch to using a (hardcoded) password here:

postgresql password: ''

Will give this a try

@ltalirz
Copy link
Member Author

ltalirz commented Feb 20, 2020

  • when explicitly setting a password for the test profile, django tests pass
    but sqlalchemy hangs at one particular test
    • The last tests that pass:
      tests/cmdline/commands/test_setup.py::TestVerdiSetup::test_help <- tests/utils/configuration.py PASSED
      tests/cmdline/commands/test_setup.py::TestVerdiSetup::test_quicksetup <- tests/utils/configuration.py PASSED
    • => inside tests/cmdline/commands/test_setup.py but don't know which one
      Tests:
      test_help
      test_quicksetup
      => test_quicksetup_from_config_file
      test_quicksetup_wrong_port
      test_setup
  • when switching to the fixtures to set up a postgresql cluster
  • when I run only the test file tests/cmdline/commands/test_run.py , then the tests for sqlalchemy run fine
    • if the "hang" indeed happens in this file (to be seen), this would seem to suggest that something is being changed in the sqlalchemy codepath that causes a try of accessing the cluster without password

@sphuber
Copy link
Contributor

sphuber commented Feb 20, 2020

Should this have been closed by #3763?

@ltalirz
Copy link
Member Author

ltalirz commented Feb 20, 2020

No, there are a couple of underlying issues we should still investigate & fix:

  • It should be possible to run the test suite on a postgresql installation that requires a password
  • The behavior under django and sqlalchemy should be the same in this respect
  • The daemon tests should not fail when switching to a temporary profile (seen failing on django)

@CasperWA
Copy link
Contributor

* The django tests should not fail when switching to a temporary profile

*SQLAlchemy

@ltalirz
Copy link
Member Author

ltalirz commented Feb 21, 2020

I've updated that point - it was not very clear

@sphuber
Copy link
Contributor

sphuber commented Mar 31, 2020

What is the status of this? Is this still an active problem or can this be closed?

@ltalirz ltalirz changed the title CI tests broken "fe_sendauth: no password supplied" Unable to run CI tests on password-protected DB Mar 31, 2020
@ltalirz
Copy link
Member Author

ltalirz commented Mar 31, 2020

The remaining issues are described here
I've changed the title now and I think we should keep this open.
This should not just be relevant for running on CI but also for running tests locally (e.g. when postgresql is running inside a container).

@CasperWA
Copy link
Contributor

So, I have a feeling we may solve this by moving to GitHub Action's services feature (see here). However, I haven't had time to investigate this in practice.

@ltalirz
Copy link
Member Author

ltalirz commented Nov 17, 2022

I've had another look at setting a password on the database for the aiida test profile in #5776

We're now down to this error:

FAILED tests/manage/configuration/test_config.py::test_delete_profile - Conne...
= 1 failed, 2386 passed, 29 skipped, 147 deselected, 121 warnings in 605.05s (0:10:05) =

which fails at

tests/manage/configuration/test_config.py:417: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
aiida/manage/configuration/config.py:365: in delete_profile
    if postgres.db_exists(profile.storage_config['database_name']):
aiida/manage/external/postgres.py:146: in db_exists
    return bool(self.execute(_CHECK_DB_EXISTS_COMMAND.format(dbname)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <aiida.manage.external.postgres.Postgres object at 0x7f401ba8c220>
command = "SELECT datname FROM pg_database WHERE datname='to-be-deleted'"
kwargs = {}
dsn = {'database': 'template1', 'host': 'localhost', 'password': None, 'port': 5432, ...}

This test already fails at the existence check, which has been noticed in #5592 under different circumstances.
The problem in both cases is that AiiDA tries to log in as the postgres superuser, for which it lacks the credentials.

The existence check could be fixed by switching to the aiida db user credentials here, but deleting the database will inevitably fail [1].

Todo:

  • The verdi profile delete test should be moved to the system tests, since it involves deleting the database. Once this has been done, this issue can be closed.
  • The problem of providing the correct superuser credentials for verdi profile delete can be fixed in Profile deletion fails instead of asking for sudo password #5592

[1] Why does the test work with the current trust settings, then?
Authentication works because with trust, the postgres user can authenticate even if the password is not known.
What I don't quite understand is why the following tests continue to work... somewhere it seems the test_aiida database is magically recreated?

@sphuber
Copy link
Contributor

sphuber commented Dec 8, 2022

What I don't quite understand is why the following tests continue to work... somewhere it seems the test_aiida database is magically recreated?

This is because the test does not operate on the test profile that is being used for the test run, but rather only a completely separate and independent config+profile that is created especially for the test. Maybe this is related to the wrong user being passed and the test failing?

@sphuber
Copy link
Contributor

sphuber commented Sep 14, 2023

If I understand correctly, this issue was related to a change in the CI. But since things have been running fine for a long time (and we have changed the CI setup significantly with regards to PostgreSQL) I am closing this. If it is still a problem, please feel free to reopen and update the problem description.

@sphuber sphuber closed this as completed Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants