1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
import os
import unittest
from .. import manage
from ..manage import getargs, main
from . import TestDir
manage.systemctl = '/bin/true'
class TestGen(unittest.TestCase):
def test_add(self):
with TestDir() as t:
main(getargs(['add', '-C', '/somedir', 'instname', '--', '/bin/sh', '-c', 'blah']), test=True)
#os.system('find '+t.dir)
confname = t.dir+'/procServ.d/instname.conf'
self.assertTrue(os.path.isfile(confname))
with open(confname, 'r') as F:
content = F.read()
self.assertEqual(content, """
[instname]
command = /bin/sh -c blah
chdir = /somedir
""")
main(getargs(['add',
'-C', '/somedir',
'-U', 'someone',
'-G', 'controls',
'other', '--', '/bin/sh', '-c', 'blah']), test=True)
confname = t.dir+'/procServ.d/other.conf'
self.assertTrue(os.path.isfile(confname))
with open(confname, 'r') as F:
content = F.read()
self.assertEqual(content, """
[other]
command = /bin/sh -c blah
chdir = /somedir
user = someone
group = controls
""")
def test_remove(self):
with TestDir() as t:
# we won't remove this config, so it should not be touched
with open(t.dir+'/procServ.d/other.conf', 'w') as F:
F.write("""
[other]
command = /bin/sh -c blah
chdir = /somedir
user = someone
group = controls
""")
confname = t.dir+'/procServ.d/blah.conf'
with open(confname, 'w') as F:
F.write("""
[blah]
command = /bin/sh -c blah
chdir = /somedir
user = someone
group = controls
""")
main(getargs(['remove', '-f', 'blah']), test=True)
self.assertFalse(os.path.isfile(confname))
self.assertTrue(os.path.isfile(t.dir+'/procServ.d/other.conf'))
confname = t.dir+'/procServ.d/blah.conf'
with open(confname, 'w') as F:
F.write("""
[blah]
command = /bin/sh -c blah
chdir = /somedir
user = someone
group = controls
[more]
# not normal, but we shouldn't nuke this file if it contains other instances
""")
main(getargs(['remove', '-f', 'blah']), test=True)
self.assertTrue(os.path.isfile(confname))
self.assertTrue(os.path.isfile(t.dir+'/procServ.d/other.conf'))
|