Skip to content
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

Postgres state doesn't return failure if postgres module returns failure for some states #8778

Closed
dknecht opened this issue Nov 23, 2013 · 5 comments · Fixed by #9026
Closed
Labels
Bug broken, incorrect, or confusing behavior help-wanted Community help is needed to resolve this

Comments

@dknecht
Copy link
Contributor

dknecht commented Nov 23, 2013

An example is if a user is failed to be created the state always returns success.

the module returns an error but doesn't return failture error code to state:

(db)25db2:/home/dane# salt-call postgres.user_create  'dane'
[INFO    ] Executing command 'psql --no-align --no-readline --username postgres --port 5432 --dbname postgres -c \'SELECT setting FROM pg_catalog.pg_settings WHERE name = \'"\'"\'server_version\'"\'"\'\' -t' as user 'postgres' in directory '/home/postgres'
[INFO    ] Executing command 'psql --no-align --no-readline --username postgres --port 5432 --dbname postgres -v datestyle=ISO,MDY -c \'COPY (SELECT rolname as "name", rolsuper as "superuser", rolinherit as "inherits privileges", rolcreaterole as "can create roles", rolcreatedb as "can create databases", rolcatupdate as "can update system catalogs", rolcanlogin as "can login", rolreplication as "replication", rolconnlimit as "connections", rolvaliduntil::timestamp(0) as "expiry time", rolconfig  as "defaults variables" FROM pg_roles) TO STDOUT WITH CSV HEADER\'' as user 'postgres' in directory '/home/postgres'
[INFO    ] Executing command 'psql --no-align --no-readline --username postgres --port 5432 --dbname postgres -c \'CREATE USER "dane"\'' as user 'postgres' in directory '/home/postgres'
local:
    ERROR:  cannot execute CREATE ROLE in a read-only transaction
@basepi
Copy link
Contributor

basepi commented Nov 25, 2013

So you're just talking about the return code? That is by design -- the retcode is designed to just tell whether salt executed successfully, it doesn't have any bearing on whether the states/modules were successful or not.

There are a few open issues for a flag to change this behavior. Also, salt-call has a --retcode-passthrough that might serve your purposes.

@dknecht
Copy link
Contributor Author

dknecht commented Nov 25, 2013

So when this is run via a state:

frank:
postgres_user.present

it would show as successful even though the underlying action failed. I don't believe that is expected behavior. Shouldn't the state fail?

For most of the other postgres calls you return false when the command fails.

@basepi
Copy link
Contributor

basepi commented Nov 25, 2013

Ah, I didn't realize the states were returning False. You only showed a module example (and I missed it in the title.)

Should be easy to fix, thanks for the report.

@basepi
Copy link
Contributor

basepi commented Nov 25, 2013

Can you add sample output of that state you posted above? Exact error messages and so forth help track down the exact location in the code faster.

@dknecht
Copy link
Contributor Author

dknecht commented Nov 26, 2013

It just returns successful.

In the role create you just return regardless...
https://github.com/saltstack/salt/blob/develop/salt/modules/postgres.py#L547

In other posgres commands you check the return value...
https://github.com/saltstack/salt/blob/develop/salt/modules/postgres.py#L368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior help-wanted Community help is needed to resolve this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants