Coverage for tests/test_allocator.py: 25%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# LSST Data Management System
3# Copyright 2008-2012 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22import sys
23import os.path
24import time
25import filecmp
26import unittest
27from lsst.ctrl.execute.namedClassFactory import NamedClassFactory
28from lsst.ctrl.execute.allocatorParser import AllocatorParser
29from lsst.ctrl.execute.condorConfig import CondorConfig
30import lsst.utils.tests
33def setup_module(module):
34 lsst.utils.tests.init()
37class TestAllocator(lsst.utils.tests.TestCase):
39 def verboseArgs(self):
40 argv = ["allocator_test",
41 "test_platform",
42 "-n", "64",
43 "-c", "12",
44 "-m", "00:30:00",
45 "-N", "test_set",
46 "-q", "normal",
47 "-e",
48 "-O", "outlog",
49 "-E", "errlog",
50 "-v",
51 ]
52 return argv
54 def regularArgs(self):
55 argv = ["allocator_test",
56 "test_platform",
57 "-n", "64",
58 "-c", "12",
59 "-m", "00:30:00",
60 "-N", "test_set",
61 "-q", "normal",
62 "-e",
63 "-O", "outlog",
64 "-E", "errlog",
65 ]
66 return argv
68 def subSetup(self, configFileName):
69 alp = AllocatorParser(sys.argv[0])
70 args = alp.getArgs()
72 condorConfigFile = os.path.join("tests", "testfiles", configFileName)
73 configuration = CondorConfig()
74 configuration.load(condorConfigFile)
76 fileName = os.path.join("tests", "testfiles", "allocator-info1.py")
78 schedulerName = configuration.platform.scheduler
79 schedulerClass = NamedClassFactory.createClass("lsst.ctrl.execute." + schedulerName + "Plugin")
81 scheduler = schedulerClass("lsst", args, configuration, fileName)
82 return scheduler
84 def test1(self):
85 sys.argv = self.verboseArgs()
86 al = self.subSetup("config_condor.py")
88 identifier1 = al.createUniqueIdentifier()
89 time.sleep(1)
90 identifier2 = al.createUniqueIdentifier()
91 self.assertTrue(identifier1 != identifier2)
93 def test2(self):
94 sys.argv = self.verboseArgs()
95 al = self.subSetup("config_asserts.py")
97 fileName = os.path.join("tests", "testfiles", "config_allocation.py")
98 al.loadPbs(fileName)
99 self.assertEqual(al.getHostName(), "bighost.lsstcorp.org")
100 self.assertEqual(al.getUtilityPath(), "/bin")
101 self.assertEqual(al.getScratchDirectory(), "/tmp")
102 self.assertEqual(al.getNodeSetName(), "test_set")
103 self.assertEqual(al.getNodes(), 64)
104 self.assertEqual(al.getCPUs(), 12)
105 self.assertEqual(al.getWallClock(), "00:30:00")
106 self.assertEqual(al.getParameter("NODE_COUNT"), 64)
107 self.assertEqual(al.getParameter("KAZOO"), None)
108 self.assertTrue(al.isVerbose())
109 localScratch = "./tests/condor_scratch_asserts"
110 configPath = "./tests/condor_scratch_asserts/configs"
111 os.rmdir(configPath)
112 os.rmdir(localScratch)
114 def test3(self):
115 sys.argv = self.regularArgs()
116 al = self.subSetup("config_condor.py")
118 fileName = os.path.join("tests", "testfiles", "config_allocation.py")
119 al.loadPbs(fileName)
120 pbsName = os.path.join("tests", "testfiles", "generic.pbs.template")
121 compare = os.path.join("tests", "testfiles", "generic.pbs.txt")
122 generatedPbsFile = al.createSubmitFile(pbsName)
124 self.assertTrue(filecmp.cmp(compare, generatedPbsFile))
125 condorFile = os.path.join("tests", "testfiles", "glidein_condor_config.template")
126 compare = os.path.join("tests", "testfiles", "glidein_condor_config.txt")
127 generatedCondorConfigFile = al.createCondorConfigFile(condorFile)
128 self.assertTrue(filecmp.cmp(compare, generatedCondorConfigFile))
129 os.remove(generatedCondorConfigFile)
130 os.remove(generatedPbsFile)
131 localScratch = "./tests/condor_scratch_condor"
132 configPath = "./tests/condor_scratch_condor/configs"
133 os.rmdir(configPath)
134 os.rmdir(localScratch)
136 def test4(self):
137 sys.argv = self.regularArgs()
138 al = self.subSetup("config_condor_slurm.py")
140 fileName = os.path.join("tests", "testfiles", "config_allocation_slurm.py")
141 al.loadSlurm(fileName, None)
142 slurmName = os.path.join("tests", "testfiles", "generic.slurm.template")
143 compare = os.path.join("tests", "testfiles", "generic.slurm.txt")
144 generatedSlurmFile = al.createSubmitFile(slurmName)
146 self.assertTrue(filecmp.cmp(compare, generatedSlurmFile))
147 condorFile = os.path.join("tests", "testfiles", "glidein_condor_config.template")
148 compare = os.path.join("tests", "testfiles", "glidein_condor_config.txt")
149 generatedCondorConfigFile = al.createCondorConfigFile(condorFile)
150 self.assertTrue(filecmp.cmp(compare, generatedCondorConfigFile))
151 os.remove(generatedCondorConfigFile)
152 os.remove(generatedSlurmFile)
153 localScratch = "./tests/condor_scratch_slurm"
154 configPath = "./tests/condor_scratch_slurm/configs"
155 os.rmdir(configPath)
156 os.rmdir(localScratch)
159class AllocatorMemoryTest(lsst.utils.tests.MemoryTestCase):
160 pass
163if __name__ == "__main__": 163 ↛ 164line 163 didn't jump to line 164, because the condition on line 163 was never true
164 lsst.utils.tests.init()
165 unittest.main()