Commit afed8dd7 authored by Jérome Perrin's avatar Jérome Perrin

console: support new `slapos console` invocation

To execute a slapconsole script, we could only do:
`slapos console <`
but this does not stop in case of error

 `echo 'execfile("")' | slapos console`
but this is too complicated.

Extend this API so that we can simply use

`slapos console`

inspired by `python`
parent 1c5e918a
......@@ -79,6 +79,9 @@ class ConsoleCommand(ClientConfigCommand):
help='Use plain Python shell')
shell.add_argument('script_file', nargs='?',
help='Script to run')
return ap
def take_action(self, args):
......@@ -86,6 +89,9 @@ class ConsoleCommand(ClientConfigCommand):
conf = ClientConfig(args, configp)
local = init(conf,
if args.script_file:
return execfile(args.script_file, globals(), local)
if not any([args.python, args.ipython, args.bpython]):
args.ipython = True
......@@ -191,3 +191,20 @@ master_url=null
self.mock_request.assert_called_once_with('software_release', 'instance')
self.assertIn('parameter_value', app_stdout.getvalue())
def test_console_script(self):
with tempfile.NamedTemporaryFile() as script:
"""print request('software_release', 'instance').getInstanceParameterDict()['parameter_name']\n""")
app = slapos.cli.entry.SlapOSApp()
saved_stdout = sys.stdout
sys.stdout = app_stdout = StringIO.StringIO()'console', '--cfg',,
sys.stdout = saved_stdout
self.mock_request.assert_called_once_with('software_release', 'instance')
self.assertIn('parameter_value', app_stdout.getvalue())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment