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

35 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-08 16:51 -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 "--collector", 

101 action="store", 

102 default=None, 

103 dest="collector", 

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

105 type=str, 

106 required=False, 

107 ) 

108 parser.add_argument( 

109 "--collector-port", 

110 action="store", 

111 default=9618, 

112 dest="collectorport", 

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

114 type=int, 

115 required=False, 

116 ) 

117 parser.add_argument( 

118 "-s", 

119 "--qos", 

120 action="store", 

121 default=None, 

122 dest="qos", 

123 help="Slurm qos for glidein job", 

124 type=str, 

125 ) 

126 parser.add_argument( 

127 "-m", 

128 "--maximum-wall-clock", 

129 action="store", 

130 dest="maximumWallClock", 

131 default=None, 

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

133 type=str, 

134 required=True, 

135 ) 

136 parser.add_argument( 

137 "-q", 

138 "--queue", 

139 action="store", 

140 dest="queue", 

141 default="roma,milano", 

142 help="queue / partition name", 

143 ) 

144 parser.add_argument( 

145 "-O", 

146 "--output-log", 

147 action="store", 

148 dest="outputLog", 

149 default=None, 

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

151 ) 

152 parser.add_argument( 

153 "-E", 

154 "--error-log", 

155 action="store", 

156 dest="errorLog", 

157 default=None, 

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

159 ) 

160 parser.add_argument( 

161 "-g", 

162 "--glidein-shutdown", 

163 action="store", 

164 dest="glideinShutdown", 

165 type=int, 

166 default=None, 

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

168 ) 

169 parser.add_argument( 

170 "--openfiles", 

171 action="store", 

172 dest="openfiles", 

173 type=int, 

174 default=20480, 

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

176 ) 

177 parser.add_argument( 

178 "-p", 

179 "--pack", 

180 action="store_true", 

181 dest="packnodes", 

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

183 ) 

184 parser.add_argument( 

185 "--exclude", 

186 action="store", 

187 default=None, 

188 dest="exclude", 

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

190 type=str, 

191 required=False, 

192 ) 

193 parser.add_argument( 

194 "--nodelist", 

195 action="store", 

196 default=None, 

197 dest="nodelist", 

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

199 type=str, 

200 required=False, 

201 ) 

202 parser.add_argument( 

203 "--exclusive", 

204 action="store_true", 

205 dest="exclusive", 

206 default=None, 

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

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

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

210 ) 

211 parser.add_argument( 

212 "--exclusive-user", 

213 action="store_true", 

214 dest="exclusiveUser", 

215 default=None, 

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

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

218 ) 

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

220 parser.add_argument( 

221 "-r", 

222 "--reservation", 

223 action="store", 

224 dest="reservation", 

225 default=None, 

226 help="target a particular Slurm reservation", 

227 ) 

228 parser.add_argument( 

229 "-d", 

230 "--dynamic", 

231 const="__default__", 

232 nargs="?", 

233 action="store", 

234 dest="dynamic", 

235 type=str, 

236 default="__default__", 

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

238 ) 

239 

240 self.args = parser.parse_args() 

241 

242 return self.args 

243 

244 def getArgs(self): 

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

246 are initialized. 

247 

248 Returns 

249 ------- 

250 args: `argparse.Namespace` 

251 remaining command line arguments 

252 """ 

253 return self.args 

254 

255 def getPlatform(self): 

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

257 the command line. 

258 

259 Returns 

260 ------- 

261 platform: `str` 

262 the name of the "platform" 

263 """ 

264 return self.args.platform