Beispiel #1
0
    def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists,
                                             mock_pid_exists, mock_pid,
                                             mock_popen):
        # no existing PID file before starting
        mock_stop.side_effect = iter([exception.NoConsolePid('/tmp/blah')])
        mock_popen.return_value.poll.return_value = 0
        mock_pid.return_value = 12345
        mock_pid_exists.return_value = True

        # touch the pid file
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        open(pid_file, 'a').close()
        self.addCleanup(os.remove, pid_file)
        self.assertTrue(os.path.exists(pid_file))

        console_utils.start_shellinabox_console(self.info['uuid'],
                                                self.info['port'], 'ls&')

        mock_stop.assert_called_once_with(self.info['uuid'])
        mock_dir_exists.assert_called_once_with()
        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_pid_exists.assert_called_once_with(12345)
        mock_popen.assert_called_once_with(mock.ANY,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
        mock_popen.return_value.poll.assert_called_once_with()
    def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists,
                                             mock_pid_exists, mock_popen,
                                             mock_path_exists, mock_fcntl):
        # no existing PID file before starting
        mock_stop.side_effect = exception.NoConsolePid('/tmp/blah')
        mock_popen.return_value.poll.return_value = 0

        self.mock_stdout.write(b'0')
        self.mock_stdout.seek(0)
        mock_popen.return_value.stdout = self.mock_stdout

        self.mock_stderr.write(b'1')
        self.mock_stderr.seek(0)
        mock_popen.return_value.stderr = self.mock_stderr

        mock_pid_exists.return_value = True
        mock_path_exists.return_value = True

        console_utils.start_shellinabox_console(self.info['uuid'],
                                                self.info['port'], 'ls&')

        mock_stop.assert_called_once_with(self.info['uuid'])
        mock_dir_exists.assert_called_once_with()
        mock_pid_exists.assert_called_once_with(12345)
        mock_popen.assert_called_once_with(mock.ANY,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
        mock_popen.return_value.poll.assert_called_once_with()
Beispiel #3
0
    def test_stop_ics_console_log_fail_nopid(self, mock_stop):
        self.config(terminal='ironic-console-server', group='console')
        mock_stop.side_effect = iter([exception.NoConsolePid('/tmp/blah')])

        console_utils.stop_ics_console_log(self.info['uuid'])

        mock_stop.assert_called_once_with(self.info['uuid'])
Beispiel #4
0
def _get_console_pid(node_uuid):
    """Get the terminal process id from pid file."""

    pid_path = _get_console_pid_file(node_uuid)
    try:
        with open(pid_path, 'r') as f:
            pid_str = f.readline()
            return int(pid_str)
    except (IOError, ValueError):
        raise exception.NoConsolePid(pid_path=pid_path)
Beispiel #5
0
    def test__stop_console_nopid(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.side_effect = exception.NoConsolePid(pid_path="/tmp/blah")

        self.assertRaises(exception.NoConsolePid, console_utils._stop_console,
                          self.info['uuid'])

        mock_pid.assert_called_once_with(self.info['uuid'])
        self.assertFalse(mock_kill.called)
        mock_unlink.assert_called_once_with(pid_file)
Beispiel #6
0
    def test_stop_ics_console_fail_nopid(self, mock_send_signal):
        self.config(terminal='ironic-console-server', group='console')
        mock_send_signal.side_effect = exception.NoConsolePid(pid_path='/foo')

        # touch the pid file
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        open(pid_file, 'a').close()
        self.addCleanup(os.remove, pid_file)
        self.assertTrue(os.path.exists(pid_file))

        console_utils.stop_ics_console(self.info['uuid'])

        mock_send_signal.assert_called_once_with(mock.ANY, 'USR2')
Beispiel #7
0
    def test_start_socat_console_nopid(self, mock_stop, mock_dir_exists,
                                       mock_get_pid, mock_pid_exists,
                                       mock_popen, mock_path_exists):
        # no existing PID file before starting
        mock_stop.side_effect = exception.NoConsolePid('/tmp/blah')
        mock_popen.return_value.pid = 23456
        mock_popen.return_value.poll.return_value = None
        mock_popen.return_value.communicate.return_value = (None, None)

        mock_get_pid.return_value = 23456
        mock_path_exists.return_value = True

        console_utils.start_socat_console(self.info['uuid'], self.info['port'],
                                          'ls&')

        mock_stop.assert_called_once_with(self.info['uuid'])
        mock_dir_exists.assert_called_once_with()
        mock_get_pid.assert_called_with(self.info['uuid'])
        mock_path_exists.assert_called_with(mock.ANY)
        mock_popen.assert_called_once_with(mock.ANY, stderr=subprocess.PIPE)
Beispiel #8
0
    def test_stop_shellinabox_console_fail_nopid(self, mock_stop):
        mock_stop.side_effect = exception.NoConsolePid('/tmp/blah')

        console_utils.stop_shellinabox_console(self.info['uuid'])

        mock_stop.assert_called_once_with(self.info['uuid'])
Beispiel #9
0
 def test_stop_socat_console_fail_nopid(self, mock_stop, mock_log_warning):
     mock_stop.side_effect = exception.NoConsolePid('/tmp/blah')
     console_utils.stop_socat_console(self.info['uuid'])
     mock_stop.assert_called_once_with(self.info['uuid'])
     # LOG.warning() is called when _stop_console() raises NoConsolePid
     self.assertTrue(mock_log_warning.called)