Coverage for python / lsst / ctrl / execute / pbsPlugin.py: 0%

47 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 logging 

29import os 

30import sys 

31from string import Template 

32 

33from lsst.ctrl.execute.allocator import Allocator 

34 

35_LOG = logging.getLogger(__name__) 

36 

37 

38class PbsPlugin(Allocator): 

39 def submit(self, platform, platformPkgDir): 

40 # This have specific paths to prevent abitrary binaries from being 

41 # executed. The "gsi"* utilities are configured to use either grid 

42 # proxies or ssh, automatically. 

43 remoteLoginCmd = "/usr/bin/gsissh" 

44 remoteCopyCmd = "/usr/bin/gsiscp" 

45 

46 configName = os.path.join(platformPkgDir, "etc", "config", "pbsConfig.py") 

47 

48 self.loadPbs(configName) 

49 verbose = self.isVerbose() 

50 

51 pbsName = os.path.join(platformPkgDir, "etc", "templates", "generic.pbs.template") 

52 generatedPbsFile = self.createPbsFile(pbsName) 

53 

54 condorFile = os.path.join(platformPkgDir, "etc", "templates", "glidein_condor_config.template") 

55 generatedCondorConfigFile = self.createCondorConfigFile(condorFile) 

56 

57 scratchDirParam = self.getScratchDirectory() 

58 template = Template(scratchDirParam) 

59 scratchDir = template.substitute(USER_HOME=self.getUserHome()) 

60 

61 userName = self.getUserName() 

62 hostName = self.getHostName() 

63 

64 utilityPath = self.getUtilityPath() 

65 

66 # 

67 # execute copy of PBS file to XSEDE node 

68 # 

69 cmd = ( 

70 f"{remoteCopyCmd} {generatedPbsFile} " 

71 f"{userName}@{hostName}:{scratchDir}/{os.path.basename(generatedPbsFile)}" 

72 ) 

73 _LOG.debug(cmd) 

74 exitCode = self.runCommand(cmd, verbose) 

75 if exitCode != 0: 

76 _LOG.error("error running %s to %s.", remoteCopyCmd, hostName) 

77 sys.exit(exitCode) 

78 

79 # 

80 # execute copy of Condor config file to XSEDE node 

81 # 

82 cmd = ( 

83 f"{remoteCopyCmd} {generatedCondorConfigFile} " 

84 f"{userName}@{hostName}:{scratchDir}/{os.path.basename(generatedCondorConfigFile)}" 

85 ) 

86 _LOG.debug(cmd) 

87 exitCode = self.runCommand(cmd, verbose) 

88 if exitCode != 0: 

89 _LOG.error("error running %s to %s.", remoteCopyCmd, hostName) 

90 sys.exit(exitCode) 

91 

92 # 

93 # execute qsub command on XSEDE node to perform Condor glide-in 

94 # 

95 cmd = ( 

96 f"{remoteLoginCmd} {userName}@{hostName} " 

97 f"{utilityPath}/qsub {scratchDir}/{os.path.basename(generatedPbsFile)}" 

98 ) 

99 _LOG.debug(cmd) 

100 exitCode = self.runCommand(cmd, verbose) 

101 if exitCode != 0: 

102 _LOG.error("error running %s to %s.", remoteLoginCmd, hostName) 

103 sys.exit(exitCode) 

104 

105 self.printNodeSetInfo() 

106 

107 def loadPbs(self, name): 

108 configuration = self.loadAllocationConfig(name, "pbs") 

109 template = Template(configuration.platform.scratchDirectory) 

110 scratchDir = template.substitute(USER_HOME=self.getUserHome()) 

111 self.defaults["SCRATCH_DIR"] = scratchDir