Coverage for python / lsst / ctrl / execute / allocatorParser.py: 16%

37 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 08:59 +0000

1# This file is part of ctrl_execute. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27 

28import argparse 

29 

30 

31class AllocatorParser: 

32 """An argument parser for node allocation requests. 

33 

34 Parameters 

35 ---------- 

36 basename : `str` 

37 The name used to identify the running program 

38 """ 

39 

40 def __init__(self, basename): 

41 """Construct an AllocatorParser 

42 @param argv: list containing the command line arguments 

43 @return: the parser options and remaining arguments 

44 """ 

45 

46 self.defaults = {} 

47 self.args = self.parseArgs(basename) 

48 

49 def parseArgs(self, basename) -> argparse.Namespace: 

50 """Parse command line, and test for required arguments 

51 

52 Parameters 

53 ---------- 

54 argv: `list` 

55 list of strings containing the command line arguments 

56 

57 Returns 

58 ------- 

59 The parser options and remaining arguments 

60 """ 

61 

62 parser = argparse.ArgumentParser(prog=basename) 

63 parser.add_argument("platform", type=str, default="s3df", help="node allocation platform") 

64 parser.add_argument( 

65 "--auto", 

66 action="store_true", 

67 dest="auto", 

68 help="use automatic detection of jobs to determine glide-ins", 

69 ) 

70 parser.add_argument( 

71 "-n", 

72 "--node-count", 

73 action="store", 

74 default=None, 

75 dest="nodeCount", 

76 help="number of glideins to submit; these are chunks of a node, size the number of cores/cpus", 

77 type=int, 

78 required=True, 

79 ) 

80 parser.add_argument( 

81 "-c", 

82 "--cpus", 

83 action="store", 

84 default=16, 

85 dest="cpus", 

86 help="cores / cpus per glidein", 

87 type=int, 

88 required=False, 

89 ) 

90 parser.add_argument( 

91 "-a", 

92 "--account", 

93 action="store", 

94 default="rubin:developers", 

95 dest="account", 

96 help="Slurm account for glidein job", 

97 type=str, 

98 ) 

99 parser.add_argument( 

100 "--nodeset", 

101 action="store", 

102 default=None, 

103 dest="nodeset", 

104 help="nodeset label to attach to glideins", 

105 type=str, 

106 required=False, 

107 ) 

108 parser.add_argument( 

109 "--collector", 

110 action="store", 

111 default=None, 

112 dest="collector", 

113 help="machine name of nondefault htcondor collector", 

114 type=str, 

115 required=False, 

116 ) 

117 parser.add_argument( 

118 "--collector-port", 

119 action="store", 

120 default=9618, 

121 dest="collectorport", 

122 help="port used for nondefault htcondor collector", 

123 type=int, 

124 required=False, 

125 ) 

126 parser.add_argument( 

127 "--mempercore", 

128 action="store", 

129 default=4096, 

130 dest="mempercore", 

131 help="Memory per core in MB to be scheduled by default", 

132 type=int, 

133 required=False, 

134 ) 

135 parser.add_argument( 

136 "-s", 

137 "--qos", 

138 action="store", 

139 default=None, 

140 dest="qos", 

141 help="Slurm qos for glidein job", 

142 type=str, 

143 ) 

144 parser.add_argument( 

145 "-m", 

146 "--maximum-wall-clock", 

147 action="store", 

148 dest="maximumWallClock", 

149 default=None, 

150 help="maximum wall clock time; e.g., 3600, 10:00:00, 6-00:00:00, etc", 

151 type=str, 

152 required=True, 

153 ) 

154 parser.add_argument( 

155 "-q", 

156 "--queue", 

157 action="store", 

158 dest="queue", 

159 default="milano", 

160 help="queue / partition name", 

161 ) 

162 parser.add_argument( 

163 "-O", 

164 "--output-log", 

165 action="store", 

166 dest="outputLog", 

167 default=None, 

168 help="Output log filename; this option for PBS, unused with Slurm", 

169 ) 

170 parser.add_argument( 

171 "-E", 

172 "--error-log", 

173 action="store", 

174 dest="errorLog", 

175 default=None, 

176 help="Error log filename; this option for PBS, unused with Slurm", 

177 ) 

178 parser.add_argument( 

179 "-g", 

180 "--glidein-shutdown", 

181 action="store", 

182 dest="glideinShutdown", 

183 type=int, 

184 default=None, 

185 help="glide-in inactivity shutdown time in seconds", 

186 ) 

187 parser.add_argument( 

188 "--openfiles", 

189 action="store", 

190 dest="openfiles", 

191 type=int, 

192 default=20480, 

193 help="set the limit on number of open files (fd) per process", 

194 ) 

195 parser.add_argument( 

196 "-p", 

197 "--pack", 

198 action="store_true", 

199 dest="packnodes", 

200 help="encourage nodes to pack jobs rather than spread", 

201 ) 

202 parser.add_argument( 

203 "--exclude", 

204 action="store", 

205 default=None, 

206 dest="exclude", 

207 help="machine name(s) to exclude Slurm jobs from", 

208 type=str, 

209 required=False, 

210 ) 

211 parser.add_argument( 

212 "--nodelist", 

213 action="store", 

214 default=None, 

215 dest="nodelist", 

216 help="machine name(s) to target Slurm jobs toward", 

217 type=str, 

218 required=False, 

219 ) 

220 parser.add_argument( 

221 "--exclusive", 

222 action="store_true", 

223 dest="exclusive", 

224 default=None, 

225 help="glidein will be an exclusive batch job; the glidein will be " 

226 "the only job on the node, and have all available cores, memory." 

227 "Settings for the number of cores -c are ignored, overridden.", 

228 ) 

229 parser.add_argument( 

230 "--exclusive-user", 

231 action="store_true", 

232 dest="exclusiveUser", 

233 default=None, 

234 help="glidein will be an exclusive to the user batch job; only " 

235 " other jobs of the same user will share the node with the glidein", 

236 ) 

237 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", help="verbose") 

238 parser.add_argument( 

239 "-r", 

240 "--reservation", 

241 action="store", 

242 dest="reservation", 

243 default=None, 

244 help="target a particular Slurm reservation", 

245 ) 

246 parser.add_argument( 

247 "-d", 

248 "--dynamic", 

249 const="__default__", 

250 nargs="?", 

251 action="store", 

252 dest="dynamic", 

253 type=str, 

254 default="__default__", 

255 help="configure to use dynamic/partitionable slot; legacy option: this is always enabled now", 

256 ) 

257 

258 self.args = parser.parse_args() 

259 

260 return self.args 

261 

262 def getArgs(self): 

263 """Accessor method to get arguments left after standard parsed options 

264 are initialized. 

265 

266 Returns 

267 ------- 

268 args: `argparse.Namespace` 

269 remaining command line arguments 

270 """ 

271 return self.args 

272 

273 def getPlatform(self): 

274 """Accessor method to retrieve the "platform" that was specified on 

275 the command line. 

276 

277 Returns 

278 ------- 

279 platform: `str` 

280 the name of the "platform" 

281 """ 

282 return self.args.platform