예제 #1
0
    def test_open_first_fork_child_second_fork_child_and_pitfile(self):
        self.os_mock.fork = MagicMock(side_effect=[0, 0])
        self.daemoncontext.pidfile = Mock()
        terminate = getattr(self.daemoncontext, 'terminate')
        self.daemoncontext.signal_map = {
            self.signal_mock.SIGTSTP: None,
            self.signal_mock.SIGTTIN: None,
            self.signal_mock.SIGTTOU: None,
            self.signal_mock.SIGTERM: 'terminate'
        }

        self.daemoncontext.open()

        self.os_mock.assert_has_calls([
            call.getuid(),
            call.getgid(),
            call.chdir('/'),
            call.setgid(54321),
            call.setuid(12345),
            call.umask(0),
            call.fork(),
            call.setsid(),
            call.fork(),
            call.close(0),
            call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
            call.dup2(self.os_mock.open(), self.sys_mock.stdin.fileno()),
            call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
            call.dup2(self.os_mock.open(), self.sys_mock.stdout.fileno()),
            call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
            call.dup2(self.os_mock.open(), self.sys_mock.stderr.fileno())
        ])
        self.resource_mock.assert_has_calls([
            call.setrlimit(self.resource_mock.RLIMIT_CORE, (0, 0)),
            call.getrlimit(2048)
        ])
        self.signal_mock.assert_has_calls([
            call.signal(self.signal_mock.SIGTSTP, self.signal_mock.SIG_IGN),
            call.signal(self.signal_mock.SIGTERM, terminate),
            call.signal(self.signal_mock.SIGTTIN, self.signal_mock.SIG_IGN),
            call.signal(self.signal_mock.SIGTTOU, self.signal_mock.SIG_IGN)
        ],
                                          any_order=True)
        self.sys_mock.assert_has_calls([
            call.stdin.fileno(),
            call.stdout.fileno(),
            call.stderr.fileno(),
            call.stdin.fileno(),
            call.stdout.fileno(),
            call.stderr.fileno()
        ])
        self.daemoncontext.pidfile.assert_has_calls([call.acquire()])
예제 #2
0
 def test_redirect_stream_fileno(self):
     file1 = Mock()
     file1.fileno.return_value = 123
     file2 = Mock()
     file2.fileno.return_value = 321
     pep3143daemon.daemon.redirect_stream(file1, file2)
     self.os_mock.assert_has_calls([call.dup2(321, 123)])
예제 #3
0
 def test_redirect_stream_fileno(self):
     file1 = Mock()
     file1.fileno.return_value = 123
     file2 = Mock()
     file2.fileno.return_value = 321
     pep3143daemon.daemon.redirect_stream(file1, file2)
     self.os_mock.assert_has_calls([call.dup2(321, 123)])
예제 #4
0
 def test_redirect_stream_None(self):
     file = Mock()
     file.fileno.return_value = 123
     pep3143daemon.daemon.redirect_stream(file, None)
     self.os_mock.assert_has_calls(
         [call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
          call.dup2(self.os_mock.open(), 123)])
예제 #5
0
    def test_open_first_fork_child_second_fork_child_and_pitfile(self):
        self.os_mock.fork = MagicMock(side_effect=[0, 0])
        self.daemoncontext.pidfile = Mock()
        terminate = getattr(self.daemoncontext, 'terminate')
        self.daemoncontext.signal_map = {
            self.signal_mock.SIGTSTP: None,
            self.signal_mock.SIGTTIN: None,
            self.signal_mock.SIGTTOU: None,
            self.signal_mock.SIGTERM: 'terminate'}

        self.daemoncontext.open()

        self.os_mock.assert_has_calls(
            [call.getuid(),
             call.getgid(),
             call.chdir('/'),
             call.setgid(54321),
             call.setuid(12345),
             call.umask(0),
             call.fork(),
             call.setsid(),
             call.fork(),
             call.close(0),
             call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
             call.dup2(self.os_mock.open(), self.sys_mock.stdin.fileno()),
             call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
             call.dup2(self.os_mock.open(), self.sys_mock.stdout.fileno()),
             call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
             call.dup2(self.os_mock.open(), self.sys_mock.stderr.fileno())])
        self.resource_mock.assert_has_calls(
            [call.setrlimit(self.resource_mock.RLIMIT_CORE, (0, 0)),
             call.getrlimit(2048)])
        self.signal_mock.assert_has_calls(
            [call.signal(self.signal_mock.SIGTSTP, self.signal_mock.SIG_IGN),
             call.signal(self.signal_mock.SIGTERM, terminate),
             call.signal(self.signal_mock.SIGTTIN, self.signal_mock.SIG_IGN),
             call.signal(self.signal_mock.SIGTTOU, self.signal_mock.SIG_IGN)], any_order=True)
        self.sys_mock.assert_has_calls(
            [call.stdin.fileno(),
             call.stdout.fileno(),
             call.stderr.fileno(),
             call.stdin.fileno(),
             call.stdout.fileno(),
             call.stderr.fileno()])
        self.daemoncontext.pidfile.assert_has_calls(
            [call.acquire()]
        )
예제 #6
0
 def test_redirect_stream_None(self):
     file = Mock()
     file.fileno.return_value = 123
     pep3143daemon.daemon.redirect_stream(file, None)
     self.os_mock.assert_has_calls([
         call.open(self.os_mock.devnull, self.os_mock.O_RDWR),
         call.dup2(self.os_mock.open(), 123)
     ])