Exemple #1
0
 def test_unlock(self):
     p = daemon.Pidfile('thefile', 'python')
     p.unlock()
     self.fcntl.flock.assert_has_calls([
         mock.call(FAKE_FD, self.fcntl.LOCK_EX),
         mock.call(FAKE_FD, self.fcntl.LOCK_UN)
     ])
Exemple #2
0
    def test_init(self):
        self.os.O_CREAT = os.O_CREAT
        self.os.O_RDWR = os.O_RDWR

        daemon.Pidfile('thefile', 'python')
        self.os.open.assert_called_once_with('thefile', os.O_CREAT | os.O_RDWR)
        self.fcntl.flock.assert_called_once_with(FAKE_FD, self.fcntl.LOCK_EX)
Exemple #3
0
    def test_write(self):
        p = daemon.Pidfile('thefile', 'python')
        p.write(34)

        self.os.assert_has_calls([
            mock.call.ftruncate(FAKE_FD, 0),
            mock.call.write(FAKE_FD, '34'),
            mock.call.fsync(FAKE_FD)
        ])
Exemple #4
0
    def test_init_open_fail(self):
        self.os.open.side_effect = IOError

        with mock.patch.object(daemon.sys, 'stderr'):
            with testtools.ExpectedException(SystemExit):
                daemon.Pidfile('thefile', 'python')
                sys.assert_has_calls(
                    [mock.call.stderr.write(mock.ANY),
                     mock.call.exit(1)])
Exemple #5
0
    def test_init_open_fail(self):
        self.os.open.side_effect = IOError

        with mock.patch.object(daemon.sys, 'stderr') as stderr:
            with self.assertRaises(SystemExit):
                p = daemon.Pidfile('thefile', 'python')
                sys.assert_has_calls(
                    [mock.call.stderr.write(mock.ANY),
                     mock.call.exit(1)])
Exemple #6
0
    def test_is_running_uuid_true(self):
        with mock.patch('quantum.agent.linux.utils.execute') as execute:
            execute.return_value = 'python 1234'
            p = daemon.Pidfile('thefile', 'python', uuid='1234')

            with mock.patch.object(p, 'read') as read:
                read.return_value = 34
                self.assertTrue(p.is_running())

            execute.assert_called_once_with(['cat', '/proc/34/cmdline'],
                                            'sudo')
Exemple #7
0
 def test_read(self):
     self.os.read.return_value = '34'
     p = daemon.Pidfile('thefile', 'python')
     self.assertEqual(34, p.read())