Salt: LocalClient should not use print()

Created on 14 Jan 2018  路  13Comments  路  Source: saltstack/salt

Description of Issue/Question

I want to use salt.client.LocalClient() class in a script which iterates over a bunch of registered environemnts and runs commands.
As we have many Saltmaster it happens that a registered environment does not return data as no minion is connected the current Saltmaster.

Unfortunately LocalClient does not raise an exception which I could catch when no minion is connected for an environment but prints a message directly:
https://github.com/saltstack/salt/blob/1c9ebe2005daf9d79a8d70eca9de882d9ffb9128/salt/client/__init__.py#L282

There are other cases where print is used too:

IMHO all those should be changed to either use the 'log'-object or to raise an exception based on the situation.
Examples:

  • L213: should use 'log.error()' as an error happened but the whole process should not be stopped
  • L273: should raise an exception as the call itself did not produce a response but the user should be able to react to this event, which currently is not possible as it's only a message on the stdout

Is there a reason why LocalClient uses print() instead of 'log'-object and exceptions?

Setup

Install salt-master and run with default configuration is sufficient.

Steps to Reproduce Issue

  • run this script:
from salt.client import LocalClient
try:
  LocalClient().cmd('G@Minions:Empty', 'test.ping', tgt_type='compound', expr_form='compound')
except:
  print('error should be exceptable')

Versions Report

All version including 'develop' branch

Bug Core severity-medium team-core

All 13 comments

I have to say I agree with this, an error log would be better imho.

@saltstack/team-core can I get some opinions here?

Thanks!
Daniel

Sounds reasonably. I like that idea.

I'm having the exact same issue, so I'm just leaving a quick comment so the issue doesn't auto close...
Thanks a lot!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Thank you for updating this issue. It is no longer marked as stale.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@gtmanfred As this issue still persists and was accepted by the salt-core team can the stale-bot be deactivated for this issue?
Otherwise I have to add bumping comments every month just to prevent the automatic closure.

Thank you for updating this issue. It is no longer marked as stale.

@sagetherage Could you please add this to your triage list so that the correct lables are applied? Thanks.

@DmitryKuzmenko please put this on your list of tickets to triage this week - looks like it may have been lost in the blocked milestone and never had follow up.

@DmitryKuzmenko can you please triage this ticket, thanks!

@sagetherage done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saurabhnemade picture saurabhnemade  路  3Comments

Arguros picture Arguros  路  3Comments

sagetherage picture sagetherage  路  3Comments

lhost picture lhost  路  3Comments

Inveracity picture Inveracity  路  3Comments