Using aiida pytests fixtures in Gitlab CI

45 views
Skip to first unread message

Jonathan Chico

unread,
Feb 18, 2021, 2:28:22 AM2/18/21
to aiidausers
Hello everyone!

I have been building some workflows and I was trying to make use of the pytest fixtures provided in aiida-core to run them.

I took a look at how it is done in the aiida-core repo and in the aiida-vasp repo and I basically adapted my tests to follow the same procedure, i.e. import the fixtures, create a mock code to retrieve the reference data and then perform your usual assertion tests in your script.

However, I noticed that for example pgtest does not play nicely with the gitlab docker containers where the CI is ran. In those containers one is technically the root user, which means that when one invokes the pytest fixture to create a temporary db using `create_db_cluster` pgtest will fail as `OSError: b'pg_ctl: cannot be run as root`.

One can get around this by running the pytest command as the prosgres user (not the cleanest solution) like this

su -p -c "pytest -q tests/relaxation/test.py" postgres

However, then the fixture fails when it tries to create the configuration directory

aiida.common.exceptions.ConfigurationError: could not create the '/root/.aiida' configuration directory

So I was wondering if somebody else has had these issues when trying to run tests in Gitlab.

Thank you very much for your help

Cheers

Dominic Kempf

unread,
Feb 18, 2021, 4:09:16 AM2/18/21
to aiida...@googlegroups.com
Hello Jonathan,

Sorry if I am stating the obvious here, but a general solution for this type of problem would be to switch to a user in the Dockerfile of the image (using the USER command).
In fact, this is considered a best practice by Docker themselves: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user

Best,
Dominic

--
AiiDA is supported by the NCCR MARVEL (http://nccr-marvel.ch/), funded by the Swiss National Science Foundation, and by the European H2020 MaX Centre of Excellence (http://www.max-centre.eu/).
 
Before posting your first question, please see the posting guidelines at http://www.aiida.net/?page_id=356 .
---
You received this message because you are subscribed to the Google Groups "aiidausers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/395e341c-6682-4d28-b4db-1b02eb375eb7n%40googlegroups.com.

Jonathan Chico

unread,
Feb 18, 2021, 5:26:22 AM2/18/21
to aiida...@googlegroups.com
Hello @Dominic

Thanks, that is quite useful. I do not have my own docker image, I'm just importing the python3.8 image in my gitlab CI, for what I can see there is no way of changing it easily directly from inside the container https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2750 . But perhaps I'm missing something.

Cheers

You received this message because you are subscribed to a topic in the Google Groups "aiidausers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/aiidausers/ZMc4yD-CHi8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/CA%2BCg7M4RWnSayinJdZ_BL_X7eN%3DyaTvA0N5m5NTbP571c2Oaqg%40mail.gmail.com.


--
Jonathan Chico
Reply all
Reply to author
Forward
0 new messages