@@ 231-264 (lines=34) @@ | ||
228 | assert_true(os.path.isdir(self.logs_dir)) |
|
229 | assert_equal(len(os.listdir(self.logs_dir)), 1) |
|
230 | assert_equal(len(open(running_commands_file).readlines()), 0) |
|
231 | assert_equal(len(open(pending_commands_file).readlines()), len(commands)) |
|
232 | ||
233 | def test_main_resume_by_expanding_pool_default(self): |
|
234 | # Create SMART_DISPATCH_LOGS structure. |
|
235 | call(self.launch_command, shell=True) |
|
236 | batch_uid = os.listdir(self.logs_dir)[0] |
|
237 | ||
238 | # Simulate that some commands are in the running state. |
|
239 | nb_commands_files = 2 # 'commands.txt' and 'running_commands.txt' |
|
240 | path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands") |
|
241 | pending_commands_file = pjoin(path_job_commands, "commands.txt") |
|
242 | running_commands_file = pjoin(path_job_commands, "running_commands.txt") |
|
243 | commands = open(pending_commands_file).read().strip().split("\n") |
|
244 | with open(running_commands_file, 'w') as running_commands: |
|
245 | running_commands.write("\n".join(commands[::2]) + "\n") |
|
246 | with open(pending_commands_file, 'w') as pending_commands: |
|
247 | pending_commands.write("\n".join(commands[1::2]) + "\n") |
|
248 | ||
249 | # Remove PBS files so we can check that new ones are going to be created. |
|
250 | for f in os.listdir(path_job_commands): |
|
251 | if f.startswith('job_commands_') and f.endswith('.sh'): |
|
252 | os.remove(pjoin(path_job_commands, f)) |
|
253 | ||
254 | # Should NOT move running commands back to pending but should add new workers. |
|
255 | command_line = self.resume_command.format(batch_uid) |
|
256 | command_line += " --expandPool" |
|
257 | exit_status = call(command_line, shell=True) |
|
258 | ||
259 | # Test validation |
|
260 | assert_equal(exit_status, 0) |
|
261 | assert_equal(len(open(running_commands_file).readlines()), len(commands[::2])) |
|
262 | assert_equal(len(open(pending_commands_file).readlines()), len(commands[1::2])) |
|
263 | ||
264 | nb_job_commands_files = len(os.listdir(path_job_commands)) |
|
265 | assert_equal(nb_job_commands_files-nb_commands_files, len(commands[1::2])) |
|
266 | ||
267 | def test_main_resume_by_expanding_pool(self): |
|
@@ 197-229 (lines=33) @@ | ||
194 | with open(running_commands_file, 'w') as running_commands: |
|
195 | running_commands.write("\n".join(commands[::2]) + "\n") |
|
196 | with open(pending_commands_file, 'w') as pending_commands: |
|
197 | pending_commands.write("\n".join(commands[1::2]) + "\n") |
|
198 | ||
199 | # Actual test (should move running commands back to pending). |
|
200 | exit_status = call(self.resume_command.format(batch_uid), shell=True) |
|
201 | ||
202 | # Test validation |
|
203 | assert_equal(exit_status, 0) |
|
204 | assert_true(os.path.isdir(self.logs_dir)) |
|
205 | assert_equal(len(os.listdir(self.logs_dir)), 1) |
|
206 | assert_equal(len(open(running_commands_file).readlines()), 0) |
|
207 | assert_equal(len(open(pending_commands_file).readlines()), len(commands)) |
|
208 | ||
209 | # Test when batch_uid is a path instead of a jobname. |
|
210 | # Setup |
|
211 | batch_uid = os.path.join(self.logs_dir, os.listdir(self.logs_dir)[0]) |
|
212 | ||
213 | # Simulate that some commands are in the running state. |
|
214 | path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands") |
|
215 | pending_commands_file = pjoin(path_job_commands, "commands.txt") |
|
216 | running_commands_file = pjoin(path_job_commands, "running_commands.txt") |
|
217 | commands = open(pending_commands_file).read().strip().split("\n") |
|
218 | with open(running_commands_file, 'w') as running_commands: |
|
219 | running_commands.write("\n".join(commands[::2]) + "\n") |
|
220 | with open(pending_commands_file, 'w') as pending_commands: |
|
221 | pending_commands.write("\n".join(commands[1::2]) + "\n") |
|
222 | ||
223 | # Actual test (should move running commands back to pending). |
|
224 | exit_status = call(self.resume_command.format(batch_uid), shell=True) |
|
225 | ||
226 | # Test validation |
|
227 | assert_equal(exit_status, 0) |
|
228 | assert_true(os.path.isdir(self.logs_dir)) |
|
229 | assert_equal(len(os.listdir(self.logs_dir)), 1) |
|
230 | assert_equal(len(open(running_commands_file).readlines()), 0) |
|
231 | assert_equal(len(open(pending_commands_file).readlines()), len(commands)) |
|
232 |