Esempio n. 1
0
 def test_boot_runcommand_delete_command_timeouts(self):
     self.scenario._run_command.side_effect = exceptions.SSHTimeout()
     self.assertRaises(exceptions.SSHTimeout,
                       self.scenario.boot_runcommand_delete, "foo_image",
                       "foo_flavor", "foo_interpreter", "foo_script",
                       "foo_username")
     self.scenario._delete_server_with_fip.assert_called_once_with(
         "foo_server", self.ip, force_delete=False)
    def test_boot_runcommand_delete_command_timeouts(self):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))

        scenario._run_command.side_effect = exceptions.SSHTimeout()
        self.assertRaises(exceptions.SSHTimeout, scenario.run, "foo_flavor",
                          "foo_image", "foo_interpreter", "foo_script",
                          "foo_username")
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
        self.assertFalse(scenario.add_output.called)
Esempio n. 3
0
 def wait(self, timeout=120, interval=1):
     """Wait for the host will be available via ssh."""
     start_time = time.time()
     while True:
         try:
             return self.execute("uname")
         except (socket.error, exceptions.SSHError) as e:
             LOG.debug("Ssh is still unavailable: %r" % e)
             time.sleep(interval)
         if time.time() > (start_time + timeout):
             raise exceptions.SSHTimeout("Timeout waiting for '%s'" %
                                         self.host)
    def test_test_existing_designate_from_vm_command_timeout(
            self, mock_rally_task_utils_wait_for_status,
            mock_rally_task_utils_get_from_manager):
        scenario, _ = self.create_env_for_designate()

        scenario._run_command.side_effect = exceptions.SSHTimeout()
        self.assertRaises(exceptions.SSHTimeout, scenario.run, "foo_flavor",
                          "foo_image", "foo_interpreter", "foo_script",
                          "foo_username")
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
        self.assertFalse(scenario.add_output.called)
Esempio n. 5
0
    def test_create_share_and_access_from_vm_command_timeout(
            self, params, mock_rally_task_utils_wait_for_status,
            mock_rally_task_utils_get_from_manager):
        scenario, fake_share = self.create_env(
            shares.CreateShareAndAccessFromVM(self.context))

        scenario._run_command.side_effect = exceptions.SSHTimeout()
        self.assertRaises(exceptions.SSHTimeout, scenario.run, "foo_flavor",
                          "foo_image", "foo_interpreter", "foo_script",
                          "foo_username")
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
        self.assertFalse(scenario.add_output.called)
        scenario._delete_share.assert_called_once_with(fake_share)
Esempio n. 6
0
    def _run(self,
             client,
             cmd,
             stdin=None,
             stdout=None,
             stderr=None,
             raise_on_error=True,
             timeout=3600):

        if isinstance(cmd, (list, tuple)):
            cmd = " ".join(six.moves.shlex_quote(str(p)) for p in cmd)

        transport = client.get_transport()
        session = transport.open_session()
        session.exec_command(cmd)
        start_time = time.time()

        data_to_send = ""
        stderr_data = None

        # If we have data to be sent to stdin then `select' should also
        # check for stdin availability.
        if stdin and not stdin.closed:
            writes = [session]
        else:
            writes = []

        data = None
        while True:
            # Block until data can be read/write.
            r, w, e = select.select([session], writes, [session], 1)

            if session.recv_ready():
                data = session.recv(4096)
                LOG.debug("stdout: %r" % data)
                if stdout is not None:
                    stdout.write(data.decode("utf8"))
                continue

            if session.recv_stderr_ready():
                stderr_data = session.recv_stderr(4096)
                LOG.debug("stderr: %r" % stderr_data)
                if stderr is not None:
                    stderr.write(stderr_data.decode("utf8"))
                continue

            if session.send_ready():
                if stdin is not None and not stdin.closed:
                    if not data_to_send:
                        data_to_send = stdin.read(4096)
                        if not data_to_send:
                            stdin.close()
                            session.shutdown_write()
                            writes = []
                            continue
                    sent_bytes = session.send(data_to_send)
                    LOG.debug("sent: %s" % data_to_send[:sent_bytes])
                    data_to_send = data_to_send[sent_bytes:]

            if session.exit_status_ready():
                break

            if timeout and (time.time() - timeout) > start_time:
                args = {"cmd": cmd, "host": self.host}
                raise exceptions.SSHTimeout("Timeout executing command "
                                            "'%(cmd)s' on host %(host)s" %
                                            args)
            if e:
                raise exceptions.SSHError("Socket error.")

        exit_status = session.recv_exit_status()
        if 0 != exit_status and raise_on_error:
            fmt = "Command '%(cmd)s' failed with exit_status %(status)d."
            details = fmt % {"cmd": cmd, "status": exit_status}
            if stderr_data:
                details += " Last stderr data: '%s'." % stderr_data
            raise exceptions.SSHError(details)
        return exit_status, data