コード例 #1
0
    def test_start_shellinabox_console(self, mock_stop,
                                       mock_dir_exists,
                                       mock_pid_exists,
                                       mock_pid,
                                       mock_popen):
        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()
コード例 #2
0
    def test_start_shellinabox_console_fail_no_pid(self, mock_stop,
                                                   mock_dir_exists,
                                                   mock_pid_exists,
                                                   mock_pid,
                                                   mock_popen):
        mock_popen.return_value.poll.return_value = 0
        mock_pid.return_value = 12345
        mock_pid_exists.return_value = False
        mock_popen.return_value.communicate.return_value = ('output', 'error')

        # 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))

        self.assertRaises(exception.ConsoleSubprocessFailed,
                          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()
コード例 #3
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()
コード例 #4
0
    def test_start_shellinabox_console_fail_no_pid(self, mock_stop,
                                                   mock_dir_exists,
                                                   mock_pid_exists, mock_pid,
                                                   mock_popen):
        mock_popen.return_value.poll.return_value = 0
        mock_pid.return_value = 12345
        mock_pid_exists.return_value = False
        mock_popen.return_value.communicate.return_value = ('output', 'error')

        # 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))

        self.assertRaises(exception.ConsoleSubprocessFailed,
                          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()
コード例 #5
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()
コード例 #6
0
 def test__get_console_pid_file(self):
     tempdir = tempfile.gettempdir()
     self.config(terminal_pid_dir=tempdir, group='console')
     path = console_utils._get_console_pid_file(self.info['uuid'])
     self.assertEqual(path,
                      '%(tempdir)s/%(uuid)s.pid'
                              % {'tempdir': tempdir,
                                 'uuid': self.info.get('uuid')})
コード例 #7
0
ファイル: test_console_utils.py プロジェクト: hanlind/ironic
 def test__get_console_pid_file(self, mock_dir):
     mock_dir.return_value = tempfile.gettempdir()
     expected_path = '%(tempdir)s/%(uuid)s.pid' % {
                         'tempdir': mock_dir.return_value,
                         'uuid': self.info.get('uuid')}
     path = console_utils._get_console_pid_file(self.info['uuid'])
     self.assertEqual(expected_path, path)
     mock_dir.assert_called_once_with()
コード例 #8
0
ファイル: test_console_utils.py プロジェクト: Tehsmash/ironic
 def test__get_console_pid_file(self, mock_dir):
     mock_dir.return_value = tempfile.gettempdir()
     expected_path = '%(tempdir)s/%(uuid)s.pid' % {
         'tempdir': mock_dir.return_value,
         'uuid': self.info['uuid']}
     path = console_utils._get_console_pid_file(self.info['uuid'])
     self.assertEqual(expected_path, path)
     mock_dir.assert_called_once_with()
コード例 #9
0
    def test_stop_shellinabox_console(self):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        open(pid_file, 'a').close()
        self.assertTrue(os.path.exists(pid_file))

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

        self.assertFalse(os.path.exists(pid_file))
コード例 #10
0
    def test_stop_shellinabox_console(self):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        open(pid_file, 'a').close()
        self.assertTrue(os.path.exists(pid_file))

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

        self.assertFalse(os.path.exists(pid_file))
コード例 #11
0
 def test__get_console_pid_file(self):
     tempdir = tempfile.gettempdir()
     self.config(terminal_pid_dir=tempdir, group='console')
     path = console_utils._get_console_pid_file(self.info['uuid'])
     self.assertEqual(
         path, '%(tempdir)s/%(uuid)s.pid' % {
             'tempdir': tempdir,
             'uuid': self.info.get('uuid')
         })
コード例 #12
0
ファイル: test_console_utils.py プロジェクト: younkun/ironic
    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)
コード例 #13
0
ファイル: test_console_utils.py プロジェクト: hanlind/ironic
    def test__stop_console(self, mock_pid, mock_execute, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = '12345'

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_execute.assert_called_once_with('kill', mock_pid.return_value,
                                             check_exit_code=[0, 99])
        mock_unlink.assert_called_once_with(pid_file)
コード例 #14
0
    def test__stop_console(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #15
0
ファイル: test_console_utils.py プロジェクト: Tehsmash/ironic
    def test__stop_console(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #16
0
ファイル: test_console_utils.py プロジェクト: Tehsmash/ironic
    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)
コード例 #17
0
    def test_stop_ics_console(self, mock_send_signal):
        self.config(terminal='ironic-console-server', group='console')

        # 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')
コード例 #18
0
    def test_stop_ics_console(self, mock_send_signal):
        self.config(terminal='ironic-console-server', group='console')

        # 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')
コード例 #19
0
ファイル: test_console_utils.py プロジェクト: Tehsmash/ironic
    def test__stop_console_shellinabox_not_running(self, mock_pid,
                                                   mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345
        mock_kill.side_effect = OSError(errno.ESRCH, 'message')

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #20
0
    def test__stop_console_exception(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345
        mock_kill.side_effect = OSError(2, 'message')

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #21
0
    def test__stop_console_forced_kill(self, mock_pid, mock_psutil, mock_kill,
                                       mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])

        # Make sure console process receives hard SIGKILL
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIGKILL)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #22
0
ファイル: test_console_utils.py プロジェクト: younkun/ironic
    def test__stop_console_forced_kill(self, mock_pid, mock_psutil, mock_kill,
                                       mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])

        # Make sure console process receives hard SIGKILL
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIGKILL)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #23
0
    def test__stop_console_shellinabox_not_running(self, mock_pid,
                                                   mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345
        mock_kill.side_effect = OSError(errno.ESRCH, 'message')

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #24
0
    def test_start_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.start_ics_console(self.info['uuid'])

        mock_send_signal.assert_called_once_with(mock.ANY, 'USR1')
コード例 #25
0
ファイル: test_console_utils.py プロジェクト: hanlind/ironic
    def test__stop_console_nokill(self, mock_pid, mock_execute, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = '12345'
        mock_execute.side_effect = processutils.ProcessExecutionError()

        self.assertRaises(processutils.ProcessExecutionError,
                          console_utils._stop_console,
                          self.info['uuid'])

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_execute.assert_called_once_with('kill', mock_pid.return_value,
                                             check_exit_code=[0, 99])
        mock_unlink.assert_called_once_with(pid_file)
コード例 #26
0
ファイル: test_console_utils.py プロジェクト: younkun/ironic
    def test__stop_console(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])

        # a check if process still exist (signal 0) in a loop
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIG_DFL)
        # and that it receives the SIGTERM
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #27
0
    def test_get_ics_console_log(self, mock_execute):
        self.config(terminal='ironic-console-server', group='console')
        mock_execute.return_value = ('output', '')

        # 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.get_ics_console_log(self.info['uuid'])

        mock_execute.assert_called_once_with('tail', '-n', '100', mock.ANY)
コード例 #28
0
    def test_start_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.start_ics_console(self.info['uuid'])

        mock_send_signal.assert_called_once_with(mock.ANY, 'USR1')
コード例 #29
0
    def test__stop_console(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345

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

        mock_pid.assert_called_once_with(self.info['uuid'])

        # a check if process still exist (signal 0) in a loop
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIG_DFL)
        # and that it receives the SIGTERM
        mock_kill.assert_any_call(mock_pid.return_value, signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #30
0
    def test_get_ics_console_log(self, mock_execute):
        self.config(terminal='ironic-console-server', group='console')
        mock_execute.return_value = ('output', '')

        # 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.get_ics_console_log(self.info['uuid'])

        mock_execute.assert_called_once_with('tail', '-n', '100', mock.ANY)
コード例 #31
0
ファイル: test_console_utils.py プロジェクト: Tehsmash/ironic
    def test__stop_console_exception(self, mock_pid, mock_kill, mock_unlink):
        pid_file = console_utils._get_console_pid_file(self.info['uuid'])
        mock_pid.return_value = 12345
        mock_kill.side_effect = OSError(2, 'message')

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

        mock_pid.assert_called_once_with(self.info['uuid'])
        mock_kill.assert_called_once_with(mock_pid.return_value,
                                          signal.SIGTERM)
        mock_unlink.assert_called_once_with(pid_file)
コード例 #32
0
    def test_start_shellinabox_console(self, mock_popen):
        mock_popen.return_value.poll.return_value = 0

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

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

        mock_popen.assert_called_once_with(mock.ANY,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
        mock_popen.return_value.poll.assert_called_once_with()
コード例 #33
0
    def test_start_shellinabox_console(self, mock_popen):
        mock_popen.return_value.poll.return_value = 0

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

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

        mock_popen.assert_called_once_with(mock.ANY,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
        mock_popen.return_value.poll.assert_called_once_with()
コード例 #34
0
    def test_start_ics_console_log(self, mock_stop, mock_dir_exists,
                                   mock_popen):
        self.config(terminal='ironic-console-server', group='console')
        mock_popen.return_value.pid = 12345

        # 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_ics_console_log(self.info['uuid'],
                                            self.info['port'], 'ls&', True)

        mock_stop.assert_called_once_with(self.info['uuid'])
        mock_dir_exists.assert_called_once_with()
        mock_popen.assert_called_once_with(mock.ANY)
コード例 #35
0
    def test_start_ics_console_log(self, mock_stop,
                                   mock_dir_exists,
                                   mock_popen):
        self.config(terminal='ironic-console-server', group='console')
        mock_popen.return_value.pid = 12345

        # 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_ics_console_log(self.info['uuid'],
                                            self.info['port'],
                                            'ls&',
                                            True)

        mock_stop.assert_called_once_with(self.info['uuid'])
        mock_dir_exists.assert_called_once_with()
        mock_popen.assert_called_once_with(mock.ANY)
コード例 #36
0
    def test_start_shellinabox_console(self, mock_stop, mock_dir_exists,
                                       mock_pid_exists, mock_pid, mock_popen):
        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()