Skip to content

Add test for availability of sudo in quicksetup#2333

Merged
sphuber merged 2 commits into
aiidateam:provenance_redesignfrom
ConradJohnston:fix_2004_quicksetup_assumes_presence_of_sudo
Dec 11, 2018
Merged

Add test for availability of sudo in quicksetup#2333
sphuber merged 2 commits into
aiidateam:provenance_redesignfrom
ConradJohnston:fix_2004_quicksetup_assumes_presence_of_sudo

Conversation

@ConradJohnston
Copy link
Copy Markdown
Contributor

@ConradJohnston ConradJohnston commented Dec 10, 2018

Partially addresses #1382

Quicksetup needs to access the Postgres database, but does not know anything about the system setup. It initially tries to see if it is the postgres superuser, but if it is not, it tries to become the Postgres superuser via sudo. This is the "backstop" position and relies on the user having a modern Linux-like system.
If, however, the sudo command is not available to this user at all (for example, perhaps the user is on an HPC cluser with command hidden), a system error will be raised and quicksetup will fail ungracefully.

This commit adds a test to see if sudo can be found before attempting to use it, prints a warning, and then falls back to the 'Postgres not detected' behaviour.

Quicksetup needs to access the Postgres database, but does not
know anything about the system setup. It initially tries to
see if it is the postgres superuser, but if it is not, it tries
to become the postgres superuser via sudo. This is the backstop
position and relies on the user having a modern Linux-like system.
If, however, the sudo command is not available to this user at all
(for example, perhaps on an HPC cluser), an error will be raised and
quicksetup will fail ungracefully. This commits add a test to see
if sudo can be found before attempting to use it. If it is not, no
attempt is made, and the final manual setup message is printed.

- Add simple check of the availability of the sudo command to
  the user.
- Add warning message if sudo cannot be found.
- Update click.echo calls to the AiiDA echo function.
- Update selected messages to 'warning' type messages.
@ConradJohnston ConradJohnston force-pushed the fix_2004_quicksetup_assumes_presence_of_sudo branch from 09e56dd to 7549fd5 Compare December 10, 2018 16:23
@coveralls
Copy link
Copy Markdown

coveralls commented Dec 10, 2018

Coverage Status

Coverage decreased (-0.007%) to 68.967% when pulling b5bf6de on ConradJohnston:fix_2004_quicksetup_assumes_presence_of_sudo into 64bf428 on aiidateam:provenance_redesign.

@sphuber
Copy link
Copy Markdown
Contributor

sphuber commented Dec 11, 2018

@yakutovicha will this solve the original issue you had? If I understand correctly it was trying to use sudo to connect to postgres, but the machine on which you were running this didn't have sudo, is that right? If that was the problem, although better, this will not solve the actual problem? Is there a fallback option for the quicksetup in this situation?

@ConradJohnston
Copy link
Copy Markdown
Contributor Author

Hi @sphuber , this is an interesting part of the issue. I spent some time looking at how we can connect to the database, but the long and short of it is that without being the postgres user, or another user with superuser permissions for postgres, one needs sudo to create a new database. In normal setup, the user must have created the database already, but in quicksetup it is done automatically. However, in both situations the same constraints are there.

@ConradJohnston
Copy link
Copy Markdown
Contributor Author

Actually I've found one can start a new instance of Postgres in their user space and connect with their user as a superuser, provided that it's configured to use a port that isn't in use by the system postgres. Should we support this as an option after failing to find sudo?

@sphuber
Copy link
Copy Markdown
Contributor

sphuber commented Dec 11, 2018

After discussion with @ltalirz we are going to merge this PR in, but we are keeping issue #1382 open. It looks like there is a bug in the postgres control module that was not properly detecting when a user has postgres rights and so was always defaulting to trying sudo which is what the source of the issue. Apparently, this particular origin has been fixed in develop. Issue #1382 should remain open to backport this fix onto 0.12.3.

@sphuber sphuber merged commit 454bfc3 into aiidateam:provenance_redesign Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants