~juju/ubuntu/precise/juju/0.5

« back to all changes in this revision

Viewing changes to juju/control/tests/test_ssh.py

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-12-01 13:15:51 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20111201131551-by7xfvgv16rdkmtl
Tags: 0.5+bzr424-0ubuntu1
* New upstream snapshot.
* d/control: No longer build-dep or depend on python-argparse, as
  it seems to cause fits with pkg_resources.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    @inlineCallbacks
59
59
    def test_shell_with_unit(self):
60
60
        """
61
 
        'juju shell mysql/0' will execute ssh against the machine
 
61
        'juju ssh mysql/0' will execute ssh against the machine
62
62
        hosting the unit.
63
63
        """
64
64
        mock_environment = self.mocker.patch(Environment)
92
92
            self.output.getvalue())
93
93
 
94
94
    @inlineCallbacks
 
95
    def test_passthrough_args(self):
 
96
        """Verify that args are passed through to the underlying ssh command.
 
97
 
 
98
        For example, something like the following command should be valid::
 
99
 
 
100
          $ juju ssh -L8080:localhost:8080 -o "ConnectTimeout 60" mysql/0 ls /
 
101
        """
 
102
        mock_environment = self.mocker.patch(Environment)
 
103
        mock_environment.get_machine_provider()
 
104
        self.mocker.result(self.provider)
 
105
 
 
106
        mock_exec = self.mocker.replace(os.execvp)
 
107
        mock_exec("ssh", [
 
108
            "ssh",
 
109
            "-o",
 
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 *"])
 
114
 
 
115
        # Track unwanted calls:
 
116
        calls = []
 
117
        mock_exec(ARGS, KWARGS)
 
118
        self.mocker.count(0, None)
 
119
        self.mocker.call(lambda *args, **kwargs: calls.append((args, kwargs)))
 
120
 
 
121
        finished = self.setup_cli_reactor()
 
122
        self.mocker.replay()
 
123
        yield self.unit.connect_agent()
 
124
 
 
125
        main(["ssh", "-L8080:localhost:8080", "-o", "ConnectTimeout 60",
 
126
              self.unit.unit_name, "ls *"])
 
127
        yield finished
 
128
 
 
129
        self.assertEquals(calls, [])
 
130
        self.assertIn(
 
131
            "Connecting to unit mysql/0 at mysql-0.example.com",
 
132
            self.output.getvalue())
 
133
 
 
134
    @inlineCallbacks
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.
269
309
    @inlineCallbacks
270
310
    def test_shell_with_machine_id(self):
271
311
        """
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.
274
314
        """
275
315
        mock_environment = self.mocker.patch(Environment)
338
378
        yield finished
339
379
 
340
380
        self.assertIn("Machine 1 was not found", self.stderr.getvalue())
 
381
 
 
382
 
 
383
class ParseErrorsTest(ServiceStateManagerTestBase, ControlToolTest):
 
384
 
 
385
    @inlineCallbacks
 
386
    def setUp(self):
 
387
        yield super(ParseErrorsTest, self).setUp()
 
388
        config = {
 
389
            "environments": {"firstenv": {"type": "dummy"}}}
 
390
 
 
391
        self.write_config(dump(config))
 
392
        self.config.load()
 
393
        self.stderr = self.capture_stream("stderr")
 
394
 
 
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())
 
402