Skip to content
Snippets Groups Projects
Commit 53beffbb authored by Iustin Pop's avatar Iustin Pop
Browse files

Expose utils.DaemonPidFileName

Since we need to compute this from outside utils.py, we change this to a
public function.

Reviewed-by: ultrotter
parent 5675cd1f
No related branches found
No related tags found
No related merge requests found
...@@ -1056,7 +1056,7 @@ def Daemonize(logfile, noclose_fds=None): ...@@ -1056,7 +1056,7 @@ def Daemonize(logfile, noclose_fds=None):
return 0 return 0
def _DaemonPidFileName(name): def DaemonPidFileName(name):
"""Compute a ganeti pid file absolute path, given the daemon name. """Compute a ganeti pid file absolute path, given the daemon name.
""" """
...@@ -1070,7 +1070,7 @@ def WritePidFile(name): ...@@ -1070,7 +1070,7 @@ def WritePidFile(name):
""" """
pid = os.getpid() pid = os.getpid()
pidfilename = _DaemonPidFileName(name) pidfilename = DaemonPidFileName(name)
if IsProcessAlive(ReadPidFile(pidfilename)): if IsProcessAlive(ReadPidFile(pidfilename)):
raise errors.GenericError("%s contains a live process" % pidfilename) raise errors.GenericError("%s contains a live process" % pidfilename)
...@@ -1084,7 +1084,7 @@ def RemovePidFile(name): ...@@ -1084,7 +1084,7 @@ def RemovePidFile(name):
""" """
pid = os.getpid() pid = os.getpid()
pidfilename = _DaemonPidFileName(name) pidfilename = DaemonPidFileName(name)
# TODO: we could check here that the file contains our pid # TODO: we could check here that the file contains our pid
try: try:
RemoveFile(pidfilename) RemoveFile(pidfilename)
......
...@@ -108,7 +108,7 @@ class TestPidFileFunctions(unittest.TestCase): ...@@ -108,7 +108,7 @@ class TestPidFileFunctions(unittest.TestCase):
def setUp(self): def setUp(self):
self.dir = tempfile.mkdtemp() self.dir = tempfile.mkdtemp()
self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name) self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name)
utils._DaemonPidFileName = self.f_dpn utils.DaemonPidFileName = self.f_dpn
def testPidFileFunctions(self): def testPidFileFunctions(self):
pid_file = self.f_dpn('test') pid_file = self.f_dpn('test')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment