Don't load the grains again when printing them via salt-call -g

The BaseCaller instance already has an SMinion stored in self.minion,
and that SMinion instance compiles grains in its dunder init. This
commit uses the SMinion's grains if it can find them, and only compiles
fresh grains as a last resort. Even that seems to be erring on the side
of caution, since the SMinion should always have grains.

This prevents salt-call from compiling grains twice in a single run,
resulting in a 40-50% speed reduction when running `salt-call -g`.
This commit is contained in:
Erik Johnson 2018-06-24 15:41:27 -05:00
parent 09b036c26e
commit caa62c051f
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -120,7 +120,7 @@ class BaseCaller(object):
'''
Print out the grains
'''
grains = salt.loader.grains(self.opts)
grains = self.minion.opts.get('grains') or salt.loader.grains(self.opts)
salt.output.display_output({'local': grains}, 'grains', self.opts)
def run(self):