-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_machine.py
204 lines (169 loc) · 7.59 KB
/
base_machine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python
#
# Author: Veronica G. Vergara L.
#
#
from .scheduler_factory import SchedulerFactory
from .jobLauncher_factory import JobLauncherFactory
from abc import abstractmethod, ABCMeta
import os
import shutil
class BaseMachine(metaclass=ABCMeta):
""" BaseMachine represents a compute resource and has the following
properties:
Attributes:
name: string representing the system's name
scheduler: an object of the BaseScheduler class
jobLauncher: an object of the BaseJobLauncher class
Methods:
get_machine_name:
print_machine_info:
print_scheduler_info:
print_jobLauncher_info:
set_numNodes:
"""
def __init__(self,name,scheduler_type,jobLauncher_type,numNodes,
numSockets,numCoresPerSocket,rgt_test_input_file,workspace,
harness_id,scripts_dir):
self.__name = name
self.__scheduler = SchedulerFactory.create_scheduler(scheduler_type)
self.__jobLauncher = JobLauncherFactory.create_jobLauncher(jobLauncher_type)
self.__numNodes = numNodes
self.__numSockets = numSockets
self.__numCoresPerSocket = numCoresPerSocket
self.__rgt_test_input_file = rgt_test_input_file
self.__rgt_workspace = workspace
self.__rgt_harness_id = harness_id
self.__rgt_scripts_dir = scripts_dir
self.set_rgt_results_dir()
def print_machine_info(self):
""" Print information about the machine"""
print("Machine name:\n"+self.get_machine_name())
self.__scheduler.print_scheduler_info()
print("Job Launcher info: ")
self.print_jobLauncher_info()
def get_machine_name(self):
""" Return a string with the system's name."""
return self.__name
def get_rgt_workspace(self):
""" Return a string with the path to the workspace."""
return self.__rgt_workspace
def create_rgt_workspace(self):
""" Create a workspace for this test instance."""
os.makedirs(self.get_rgt_workspace())
return
def get_rgt_input_file_name(self):
""" Return a string with the test input file name."""
return self.__rgt_test_input_file
def get_scheduler_type(self):
""" Return a string with the system's name."""
return self.__scheduler.get_scheduler_type()
def get_scheduler_template_file_name(self):
""" Return a string with the name of the scheduler's template file."""
return self.__scheduler.get_scheduler_template_file_name()
def submit_to_scheduler(self,batchfilename,unique_id):
""" Return the jobID for the submission."""
submit_exit_value = self.__scheduler.submit_job(batchfilename)
write_job_id_exit_value = self.__scheduler.write_jobid_to_status(unique_id)
return submit_exit_value and write_job_id_exit_value
def build_jobLauncher_command(self,template_dict):
""" Return the jobLauncher command."""
return self.__jobLauncher.build_job_command(template_dict)
def start_build_script(self,buildscriptname):
""" Return the status of the build."""
os.chdir(self.get_rgt_scripts_dir())
currentdir = os.getcwd()
print("current directory in base_machine: ",currentdir)
(dir_head1, dir_tail1) = os.path.split(currentdir)
(dir_head2, dir_tail2) = os.path.split(dir_head1)
path_to_source = os.path.join(dir_head2,"Source")
print("Path to Source: ",path_to_source)
self.create_rgt_workspace()
path_to_build_directory = os.path.join(self.get_rgt_workspace(),"build_directory")
print("Path to Build Dir: ", path_to_build_directory)
shutil.copytree(path_to_source,path_to_build_directory)
os.chdir(path_to_build_directory)
print("Starting build in directory: " + path_to_build_directory + " using " + buildscriptname)
build_exit_status = os.system(buildscriptname)
os.chdir(currentdir)
return build_exit_status
def check_results(self,checkscriptname):
""" Run the check script provided by the user and log the result to the status file."""
jstatus = self.start_check_script(checkscriptname)
self.write_check_exit_status(jstatus)
def start_check_script(self,checkscriptname):
""" Check if results are correct. """
currentdir = os.getcwd()
print("current directory in base_machine: ",currentdir)
os.chdir(self.get_rgt_results_dir())
print("Starting check script in base_machine: ",os.getcwd())
path_to_checkscript = os.path.join(self.get_rgt_scripts_dir(),checkscriptname)
print("Using check script: ",path_to_checkscript)
check_exit_status = os.system(path_to_checkscript)
os.chdir(currentdir)
return check_exit_status
def write_check_exit_status(self,jstatus):
""" Write the status of checking results to the status directory."""
(dir_head1, dir_tail1) = os.path.split(self.get_rgt_results_dir())
(dir_head2, dir_tail2) = os.path.split(dir_head1)
file1 = os.path.join(dir_head2,"Status",dir_tail1,"job_status.txt")
file1_obj = open(file1,"w")
print("Writing check_exit_status = ",jstatus," into ",file1)
# Set the string to write to the job_status.txt file.
#if jstatus == 0:
# pf = "1"
#elif jstatus == 1:
# pf = "0"
#elif jstatus >= 2:
# pf = "2"
string1 = "%s\n" % (jstatus)
file1_obj.write(string1)
file1_obj.close()
def start_report_script(self,reportscriptname):
""" Check if results are correct. """
os.chdir(self.get_rgt_scripts_dir())
currentdir = os.getcwd()
print("current directory in base_machine: ",currentdir)
report_exit_status = os.system(reportscriptname)
os.chdir(currentdir)
return report_exit_status
def get_rgt_harness_id(self):
""" Return the string with the Harness ID for this test instance."""
return self.__rgt_harness_id
def set_rgt_results_dir(self):
""" Return the string with the path to the Run_Archive/Harness ID directory."""
os.chdir(self.get_rgt_scripts_dir())
currentdir = os.getcwd()
(dir_head1, dir_tail1) = os.path.split(currentdir)
self.__rgt_results_dir = os.path.join(dir_head1,"Run_Archive",self.get_rgt_harness_id())
return
def get_rgt_results_dir(self):
""" Return the string corresponding to the path to the Run_Archive directory."""
return self.__rgt_results_dir
def get_rgt_scripts_dir(self):
return self.__rgt_scripts_dir
def get_rgt_workdir(self):
""" Return the string with the path to the Run_Archive/Harness ID directory."""
return os.path.join(self.get_rgt_workspace(),"workdir")
def print_jobLauncher_info(self):
""" Print information about the machine's job launcher."""
print("Job Launcher Information")
print(str(self.__jobLauncher))
def set_numNodes(self,numNodes):
self.__numNodes = numNodes
@abstractmethod
def read_rgt_test_input(self):
if os.path.isfile(self.get_rgt_input_file_name()):
print("Reading input file")
else:
print("No input found. Provide your own scripts")
@abstractmethod
def make_batch_script(self):
print("I'm making a batch script in the base class")
return
@abstractmethod
def submit_batch_script(self):
print("I'm submitting a batch script in the base class")
return
if __name__ == "__main__":
print("This is the BaseMachine class!")