Commit af99afa6 authored by Guido Trotter's avatar Guido Trotter
Browse files

Add utils unittests for new functions

The submitted WritePidFile, RemovePidfile and IsPidFileAlive functions
miss unit tests. Adding a simple one which covers their basic
functionality.

Reviewed-by: iustinp
parent ce594241
......@@ -32,6 +32,7 @@ import signal
import socket
import shutil
import re
import tempfile
import ganeti
import testutils
......@@ -98,6 +99,24 @@ class TestIsProcessAlive(unittest.TestCase):
self.assert_(not IsProcessAlive(self.pid_non_existing),
"noexisting process detected")
class TestPidFileFunctions(unittest.TestCase):
"""Tests for WritePidFile, RemovePidFile and IsPidFileAlive"""
def setUp(self):
self.dir = tempfile.mkdtemp()
self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name)
utils._DaemonPidFileName = self.f_dpn
def testPidFileFunctions(self):
utils.WritePidFile('test')
self.assert_(os.path.exists(self.f_dpn('test')))
self.assert_(utils.IsPidFileAlive(self.f_dpn('test')))
utils.RemovePidFile('test')
self.assert_(not os.path.exists(self.f_dpn('test')))
def tearDown(self):
os.rmdir(self.dir)
class TestRunCmd(unittest.TestCase):
"""Testing case for the RunCmd function"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment