Coverage for tests/test_transform.py: 24%

73 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-16 02:18 -0700

1# This file is part of ctrl_bps. 

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 program is free software: you can redistribute it and/or modify 

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21"""Unit tests of transform.py""" 

22import os 

23import shutil 

24import tempfile 

25import unittest 

26 

27from cqg_test_utils import make_test_clustered_quantum_graph 

28from lsst.ctrl.bps import BPS_SEARCH_ORDER, BpsConfig 

29from lsst.ctrl.bps.transform import create_generic_workflow, create_generic_workflow_config 

30 

31TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

32 

33 

34class TestCreateGenericWorkflowConfig(unittest.TestCase): 

35 """Tests of create_generic_workflow_config.""" 

36 

37 def testCreate(self): 

38 """Test successful creation of the config.""" 

39 config = BpsConfig({"a": 1, "b": 2, "uniqProcName": "testCreate"}) 

40 wf_config = create_generic_workflow_config(config, "/test/create/prefix") 

41 assert isinstance(wf_config, BpsConfig) 

42 for key in config: 

43 assert wf_config[key] == config[key] 

44 assert wf_config["workflowName"] == "testCreate" 

45 assert wf_config["workflowPath"] == "/test/create/prefix" 

46 

47 

48class TestCreateGenericWorkflow(unittest.TestCase): 

49 """Tests of create_generic_workflow.""" 

50 

51 def setUp(self): 

52 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR) 

53 self.config = BpsConfig( 

54 { 

55 "runInit": True, 

56 "computeSite": "global", 

57 "runQuantumCommand": "gexe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}", 

58 "clusterTemplate": "{D1}_{D2}", 

59 "cluster": { 

60 "cl1": {"pipetasks": "T1, T2", "dimensions": "D1, D2"}, 

61 "cl2": {"pipetasks": "T3, T4", "dimensions": "D1, D2"}, 

62 }, 

63 "cloud": { 

64 "cloud1": {"runQuantumCommand": "c1exe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}"}, 

65 "cloud2": {"runQuantumCommand": "c2exe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}"}, 

66 }, 

67 "site": { 

68 "site1": {"runQuantumCommand": "s1exe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}"}, 

69 "site2": {"runQuantumCommand": "s2exe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}"}, 

70 "global": {"runQuantumCommand": "s3exe -q {qgraphFile} --qgraph-node-id {qgraphNodeId}"}, 

71 }, 

72 # Needed because transform assumes they exist 

73 "whenSaveJobQgraph": "NEVER", 

74 "executionButler": {"whenCreate": "SUBMIT", "whenMerge": "ALWAYS"}, 

75 }, 

76 BPS_SEARCH_ORDER, 

77 ) 

78 self.cqg = make_test_clustered_quantum_graph(self.config) 

79 

80 def tearDown(self): 

81 shutil.rmtree(self.tmpdir, ignore_errors=True) 

82 

83 def testCreatingGenericWorkflowGlobal(self): 

84 """Test creating a GenericWorkflow with global settings.""" 

85 config = BpsConfig(self.config) 

86 config["computeCloud"] = "cloud1" 

87 config["computeSite"] = "site2" 

88 config["queue"] = "global_queue" 

89 print(config) 

90 workflow = create_generic_workflow(config, self.cqg, "test_gw", self.tmpdir) 

91 for jname in workflow: 

92 gwjob = workflow.get_job(jname) 

93 print(gwjob) 

94 assert gwjob.compute_site == "site2" 

95 assert gwjob.compute_cloud == "cloud1" 

96 assert gwjob.executable.src_uri == "s2exe" 

97 assert gwjob.queue == "global_queue" 

98 final = workflow.get_final() 

99 assert final.compute_site == "site2" 

100 assert final.compute_cloud == "cloud1" 

101 assert final.queue == "global_queue" 

102 

103 def testCreatingQuantumGraphMixed(self): 

104 """Test creating a GenericWorkflow with setting overrides.""" 

105 config = BpsConfig(self.config) 

106 config[".cluster.cl1.computeCloud"] = "cloud2" 

107 config[".cluster.cl1.computeSite"] = "notthere" 

108 config[".cluster.cl2.computeSite"] = "site1" 

109 config[".executionButler.queue"] = "special_final_queue" 

110 config[".executionButler.computeSite"] = "special_site" 

111 config[".executionButler.computeCloud"] = "special_cloud" 

112 workflow = create_generic_workflow(config, self.cqg, "test_gw", self.tmpdir) 

113 for jname in workflow: 

114 gwjob = workflow.get_job(jname) 

115 print(gwjob) 

116 if jname.startswith("cl1"): 

117 assert gwjob.compute_site == "notthere" 

118 assert gwjob.compute_cloud == "cloud2" 

119 assert gwjob.executable.src_uri == "c2exe" 

120 elif jname.startswith("cl2"): 

121 assert gwjob.compute_site == "site1" 

122 assert gwjob.compute_cloud is None 

123 assert gwjob.executable.src_uri == "s1exe" 

124 elif jname.startswith("pipetask"): 

125 assert gwjob.compute_site == "global" 

126 assert gwjob.compute_cloud is None 

127 assert gwjob.executable.src_uri == "s3exe" 

128 final = workflow.get_final() 

129 assert final.compute_site == "special_site" 

130 assert final.compute_cloud == "special_cloud" 

131 assert final.queue == "special_final_queue" 

132 

133 

134if __name__ == "__main__": 134 ↛ 135line 134 didn't jump to line 135, because the condition on line 134 was never true

135 unittest.main()