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

36 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-05 02:22 -0800

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 "-s", 

128 "--qos", 

129 action="store", 

130 default=None, 

131 dest="qos", 

132 help="Slurm qos for glidein job", 

133 type=str, 

134 ) 

135 parser.add_argument( 

136 "-m", 

137 "--maximum-wall-clock", 

138 action="store", 

139 dest="maximumWallClock", 

140 default=None, 

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

142 type=str, 

143 required=True, 

144 ) 

145 parser.add_argument( 

146 "-q", 

147 "--queue", 

148 action="store", 

149 dest="queue", 

150 default="roma,milano", 

151 help="queue / partition name", 

152 ) 

153 parser.add_argument( 

154 "-O", 

155 "--output-log", 

156 action="store", 

157 dest="outputLog", 

158 default=None, 

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

160 ) 

161 parser.add_argument( 

162 "-E", 

163 "--error-log", 

164 action="store", 

165 dest="errorLog", 

166 default=None, 

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

168 ) 

169 parser.add_argument( 

170 "-g", 

171 "--glidein-shutdown", 

172 action="store", 

173 dest="glideinShutdown", 

174 type=int, 

175 default=None, 

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

177 ) 

178 parser.add_argument( 

179 "--openfiles", 

180 action="store", 

181 dest="openfiles", 

182 type=int, 

183 default=20480, 

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

185 ) 

186 parser.add_argument( 

187 "-p", 

188 "--pack", 

189 action="store_true", 

190 dest="packnodes", 

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

192 ) 

193 parser.add_argument( 

194 "--exclude", 

195 action="store", 

196 default=None, 

197 dest="exclude", 

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

199 type=str, 

200 required=False, 

201 ) 

202 parser.add_argument( 

203 "--nodelist", 

204 action="store", 

205 default=None, 

206 dest="nodelist", 

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

208 type=str, 

209 required=False, 

210 ) 

211 parser.add_argument( 

212 "--exclusive", 

213 action="store_true", 

214 dest="exclusive", 

215 default=None, 

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

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

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

219 ) 

220 parser.add_argument( 

221 "--exclusive-user", 

222 action="store_true", 

223 dest="exclusiveUser", 

224 default=None, 

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

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

227 ) 

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

229 parser.add_argument( 

230 "-r", 

231 "--reservation", 

232 action="store", 

233 dest="reservation", 

234 default=None, 

235 help="target a particular Slurm reservation", 

236 ) 

237 parser.add_argument( 

238 "-d", 

239 "--dynamic", 

240 const="__default__", 

241 nargs="?", 

242 action="store", 

243 dest="dynamic", 

244 type=str, 

245 default="__default__", 

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

247 ) 

248 

249 self.args = parser.parse_args() 

250 

251 return self.args 

252 

253 def getArgs(self): 

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

255 are initialized. 

256 

257 Returns 

258 ------- 

259 args: `argparse.Namespace` 

260 remaining command line arguments 

261 """ 

262 return self.args 

263 

264 def getPlatform(self): 

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

266 the command line. 

267 

268 Returns 

269 ------- 

270 platform: `str` 

271 the name of the "platform" 

272 """ 

273 return self.args.platform