Example #1
0
 def detach(retries=10, timeout=1/32):
     def dtch():
         time.sleep(.1)  # HACK, FIXME
         m.console.sendcontrol('p')
         time.sleep(.001)  # HACK
         m.console.sendcontrol('q')
         m.console.expect(pexpect.EOF, timeout=.1)
     repeatedly.keep_trying(dtch, pexpect.exceptions.TIMEOUT,
                            retries=retries, timeout=timeout)
     m.console.wait()
Example #2
0
 def _connect(self, retries=12, timeout=1/32):
     if self._sock is None:
         self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         repeatedly.keep_trying(
             lambda: self._sock.connect(('127.0.0.1', self.port)),
             ConnectionRefusedError, retries=retries, timeout=timeout
         )
         self.vm.log.debug(f'negotiation')
         server_greeting = self._recv()
         assert 'QMP' in server_greeting
         self._execute('qmp_capabilities')
         self._expect({'return': {}})
Example #3
0
 def connect(self, retries=12, timeout=1 / 32):
     if self._sock is None:
         with self._command_execution_lock:
             self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self._sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY,
                                   1)
             self.vm.log.debug(f'QMP connecting...')
             repeatedly.keep_trying(lambda: self._sock.connect(
                 ('127.0.0.1', self.port)),
                                    ConnectionRefusedError,
                                    retries=retries,
                                    timeout=timeout)
             self._execute('qmp_capabilities')
             threading.Thread(target=self._recv_thread, daemon=True).start()
             server_greeting = self._expect()
             assert set(server_greeting.keys()) == {'QMP'}
             self._expect({'return': {}})  # from qmp_capabilities
             self.vm.log.debug(f'QMP is ready')
         threading.Thread(target=self._ballooning_thread,
                          daemon=True).start()
Example #4
0
    def connect(self, force_reconnect=False, retries=12, timeout=1 / 32):
        import paramiko  # ... in parallel with VM spin-up
        if not force_reconnect and self._transport is not None:
            self._transport.send_ignore()
            if self._transport.is_authenticated():
                return  # the transport is already OK
        self._transport = None
        self.m.log.debug('waiting for the VM to spin up and offer SSH...')
        pkey = paramiko.ECDSAKey.from_private_key_file(self.key)

        def connect():
            t = paramiko.Transport((self.host, self.port))
            t.start_client()
            return t

        transport = repeatedly.keep_trying(connect,
                                           paramiko.ssh_exception.SSHException,
                                           retries=retries,
                                           timeout=timeout)
        transport.auth_publickey('root', pkey)
        self._transport = transport