salt/tests/wheeltest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.5 KiB
Python
Raw Normal View History

2012-10-29 17:59:12 -06:00
#!/usr/bin/env python
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
Test interacting with the wheel system. This script is useful when testing
wheel modules
2020-04-02 20:10:20 -05:00
"""
import optparse # pylint: disable=deprecated-module
import pprint
2012-10-29 17:59:12 -06:00
import salt.auth
import salt.config
import salt.wheel
def parse():
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
Parse the command line options
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
parser = optparse.OptionParser()
parser.add_option(
"-f", "--fun", "--function", dest="fun", help="The wheel function to execute"
)
2012-10-29 22:55:22 -06:00
parser.add_option(
"-a",
"--auth",
2012-10-29 17:59:12 -06:00
dest="eauth",
help="The external authentication mechanism to use",
)
2012-10-29 22:55:22 -06:00
options, args = parser.parse_args()
2012-10-29 17:59:12 -06:00
2012-10-29 22:55:22 -06:00
cli = options.__dict__
2012-10-29 17:59:12 -06:00
2012-10-29 22:22:19 -06:00
for arg in args:
if "=" in arg:
comps = arg.split("=")
cli[comps[0]] = comps[1]
return cli
2012-10-29 17:59:12 -06:00
2021-04-01 16:29:01 -07:00
class Wheeler:
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
Set up communication with the wheel interface
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
def __init__(self, cli):
self.opts = salt.config.master_config("/etc/salt")
2012-10-29 22:55:22 -06:00
self.opts.update(cli)
self.__eauth()
2012-10-29 17:59:12 -06:00
self.wheel = salt.wheel.Wheel(self.opts)
2012-10-29 22:55:22 -06:00
def __eauth(self):
2020-04-02 20:10:20 -05:00
"""
2012-10-29 17:59:12 -06:00
Fill in the blanks for the eauth system
2020-04-02 20:10:20 -05:00
"""
2012-10-29 22:55:22 -06:00
if self.opts["eauth"]:
resolver = salt.auth.Resolver(self.opts)
res = resolver.cli(self.opts["eauth"])
self.opts.update(res)
2012-10-29 22:22:19 -06:00
def run(self):
2020-04-02 20:10:20 -05:00
"""
2012-10-29 22:22:19 -06:00
Execute the wheel call
2020-04-02 20:10:20 -05:00
"""
return self.wheel.master_call(**self.opts)
2012-10-29 17:59:12 -06:00
2012-10-29 22:22:19 -06:00
if __name__ == "__main__":
wheeler = Wheeler(parse())
pprint.pprint(wheeler.run())