Beispiel #1
0
 def pty_True_uses_paramiko_get_pty(self, remote):
     chan = remote.expect()
     c = _Connection('host')
     r = Remote(context=c)
     r.run(CMD, pty=True)
     cols, rows = pty_size()
     chan.get_pty.assert_called_with(width=cols, height=rows)
Beispiel #2
0
 def uses_export_prefixing_when_inline_env_is_True(self, remote):
     chan = remote.expect(
         cmd="export DEBUG=1 PATH=/opt/bin && {}".format(CMD)
     )
     r = Remote(context=_Connection("host"), inline_env=True)
     r.run(CMD, env={"PATH": "/opt/bin", "DEBUG": "1"})
     assert not chan.update_environment.called
Beispiel #3
0
 def writes_remote_streams_to_local_streams(self, remote):
     remote.expect(out=b"hello yes this is dog")
     c = _Connection('host')
     r = Remote(context=c)
     fakeout = StringIO()
     r.run(CMD, out_stream=fakeout)
     assert fakeout.getvalue() == "hello yes this is dog"
Beispiel #4
0
 def pty_True_uses_paramiko_get_pty(self, remote):
     chan = remote.expect()
     c = _Connection('host')
     r = Remote(context=c)
     r.run(CMD, pty=True)
     cols, rows = pty_size()
     chan.get_pty.assert_called_with(width=cols, height=rows)
Beispiel #5
0
 def writes_remote_streams_to_local_streams(self, remote):
     remote.expect(out=b"hello yes this is dog")
     c = _Connection('host')
     r = Remote(context=c)
     fakeout = StringIO()
     r.run(CMD, out_stream=fakeout)
     assert fakeout.getvalue() == "hello yes this is dog"
Beispiel #6
0
 def calls_expected_paramiko_bits(self, remote):
     # remote mocking makes generic sanity checks like "were
     # get_transport and open_session called", but we also want to make
     # sure that exec_command got run with our arg to run().
     remote.expect(cmd=CMD)
     c = _Connection('host')
     r = Remote(context=c)
     r.run(CMD)
Beispiel #7
0
 def calls_expected_paramiko_bits(self, remote):
     # remote mocking makes generic sanity checks like "were
     # get_transport and open_session called", but we also want to make
     # sure that exec_command got run with our arg to run().
     remote.expect(cmd=CMD)
     c = _Connection('host')
     r = Remote(context=c)
     r.run(CMD)
Beispiel #8
0
 def return_value_is_Result_subclass_exposing_cxn_used(self, remote):
     c = _Connection('host')
     r = Remote(context=c)
     result = r.run(CMD)
     assert isinstance(result, Result)
     # Mild sanity test for other Result superclass bits
     assert result.ok is True
     assert result.exited == 0
     # Test the attr our own subclass adds
     assert result.connection is c
Beispiel #9
0
 def return_value_is_Result_subclass_exposing_cxn_used(self, remote):
     c = _Connection('host')
     r = Remote(context=c)
     result = r.run(CMD)
     assert isinstance(result, Result)
     # Mild sanity test for other Result superclass bits
     assert result.ok is True
     assert result.exited == 0
     # Test the attr our own subclass adds
     assert result.connection is c
Beispiel #10
0
 def channel_close_skipped_when_channel_not_even_made(self):
     # I.e. if obtaining self.channel doesn't even happen (i.e. if
     # Connection.create_session() dies), we need to account for that
     # case...
     class Oops(Exception):
         pass
     def oops():
         raise Oops
     cxn = _Connection('host')
     cxn.create_session = oops
     r = Remote(context=cxn)
     # When bug present, this will result in AttributeError because
     # Remote has no 'channel'
     try:
         r.run(CMD)
     except Oops:
         pass
     else:
         assert False, "Weird, Oops never got raised..."
Beispiel #11
0
        def channel_close_skipped_when_channel_not_even_made(self):
            # I.e. if obtaining self.channel doesn't even happen (i.e. if
            # Connection.create_session() dies), we need to account for that
            # case...
            class Oops(Exception):
                pass

            def oops():
                raise Oops

            cxn = _Connection('host')
            cxn.create_session = oops
            r = Remote(context=cxn)
            # When bug present, this will result in AttributeError because
            # Remote has no 'channel'
            try:
                r.run(CMD)
            except Oops:
                pass
            else:
                assert False, "Weird, Oops never got raised..."
Beispiel #12
0
 def channel_is_closed_normally(self, remote):
     chan = remote.expect()
     # I.e. Remote.stop() closes the channel automatically
     r = Remote(context=_Connection('host'))
     r.run(CMD)
     chan.close.assert_called_once_with()
Beispiel #13
0
 def channel_is_closed_normally(self, remote):
     chan = remote.expect()
     # I.e. Remote.stop() closes the channel automatically
     r = Remote(context=_Connection('host'))
     r.run(CMD)
     chan.close.assert_called_once_with()
Beispiel #14
0
def _runner():
    return Remote(context=_Connection("host"))
Beispiel #15
0
 def start_sends_given_env_to_paramiko_update_environment(self, remote):
     chan = remote.expect()
     c = _Connection("host")
     r = Remote(context=c)
     r.run(CMD, pty=True, env={"FOO": "bar"})
     chan.update_environment.assert_called_once_with({"FOO": "bar"})
Beispiel #16
0
 def needs_handle_on_a_Connection(self):
     c = _Connection("host")
     assert Remote(context=c).context is c
Beispiel #17
0
 def send_start_message_sends_exec_command(self):
     runner = Remote(context=None)
     runner.channel = Mock()
     runner.send_start_message(command="whatever")
     runner.channel.exec_command.assert_called_once_with("whatever")