92
92
self.output.getvalue())
95
def test_passthrough_args(self):
96
"""Verify that args are passed through to the underlying ssh command.
98
For example, something like the following command should be valid::
100
$ juju ssh -L8080:localhost:8080 -o "ConnectTimeout 60" mysql/0 ls /
102
mock_environment = self.mocker.patch(Environment)
103
mock_environment.get_machine_provider()
104
self.mocker.result(self.provider)
106
mock_exec = self.mocker.replace(os.execvp)
110
"ControlPath " + self.tmp_home + "/.juju/ssh/master-%r@%h:%p",
111
"-o", "ControlMaster no",
112
"-L8080:localhost:8080", "-o", "ConnectTimeout 60",
113
"ubuntu@mysql-0.example.com", "ls *"])
115
# Track unwanted calls:
117
mock_exec(ARGS, KWARGS)
118
self.mocker.count(0, None)
119
self.mocker.call(lambda *args, **kwargs: calls.append((args, kwargs)))
121
finished = self.setup_cli_reactor()
123
yield self.unit.connect_agent()
125
main(["ssh", "-L8080:localhost:8080", "-o", "ConnectTimeout 60",
126
self.unit.unit_name, "ls *"])
129
self.assertEquals(calls, [])
131
"Connecting to unit mysql/0 at mysql-0.example.com",
132
self.output.getvalue())
95
135
def test_shell_with_unit_and_unconnected_unit_agent(self):
96
136
"""If a unit doesn't have a connected unit agent,
97
137
the ssh command will wait till one exists before connecting.
270
310
def test_shell_with_machine_id(self):
272
'juju shell <machine_id>' will execute ssh against the machine
312
'juju ssh <machine_id>' will execute ssh against the machine
273
313
with the corresponding id.
275
315
mock_environment = self.mocker.patch(Environment)
340
380
self.assertIn("Machine 1 was not found", self.stderr.getvalue())
383
class ParseErrorsTest(ServiceStateManagerTestBase, ControlToolTest):
387
yield super(ParseErrorsTest, self).setUp()
389
"environments": {"firstenv": {"type": "dummy"}}}
391
self.write_config(dump(config))
393
self.stderr = self.capture_stream("stderr")
395
def test_passthrough_args_parse_error(self):
396
"""Verify that bad passthrough args will get an argparse error."""
397
e = self.assertRaises(
398
SystemExit, main, ["ssh", "-L", "mysql/0"])
399
self.assertEqual(e.code, 2)
400
self.assertIn("juju ssh: error: too few arguments",
401
self.stderr.getvalue())