13 from __future__
import print_function
14 from future
import standard_library
15 standard_library.install_aliases()
17 from urllib.parse
import urlparse
18 from FetchMTTTool
import *
19 from distutils.spawn
import find_executable
36 FetchMTTTool.__init__(self)
42 self.
options[
'url'] = (
None,
"URL to access the repository")
43 self.
options[
'version_file'] = (
None,
"File containing name of most recent tarball version tested")
44 self.
options[
'mpi_name'] = (
None,
"Name of OMPI tarball being tested")
50 IPlugin.activate(self)
54 IPlugin.deactivate(self)
58 return "OMPI_Snapshot"
61 lines = testDef.printOptions(self.
options)
67 testDef.logger.verbose_print(
"OMP_Snapshot Execute")
70 testDef.parseOptions(log, self.
options, keyvals, cmds)
73 if cmds[
'url']
is not None:
77 log[
'stderr'] =
"No repository URL was provided"
79 testDef.logger.verbose_print(
"Download OMPI url " + url)
81 snapshot_url = url +
'/latest_snapshot.txt'
83 snapshot_req = requests.get(snapshot_url)
86 snapshot_req.raise_for_status()
87 except requests.exceptions.HTTPError
as error:
88 testDef.logger.verbose_print(
"HTTP Error: ",error)
90 log[
'stderr'] =
"HTTP error"
92 except requests.exceptions.ConnectionError
as connection_error:
93 testDef.logger.verbose_print(
"Error connecting: ", connection_error)
95 log[
'stderr'] =
"Error connecting"
97 except requests.exceptions.Timeout:
98 testDef.logger.verbose_print(
"Timeout error ")
100 log[
'stderr'] =
"Timeout error"
102 except requests.exceptions.RequestException
as base_class_error:
103 testDef.logger.verbose_print(
"An error occured: ", base_class_error)
105 log[
'stderr'] =
"An error occured"
110 if self.
options[
'version_file']
is not None:
111 if os.path.exists(cmds[
'version_file']):
113 f = open(cmds[
'version_file'],
'r')
114 last_version = f.readline().strip()
116 if last_version == snapshot_req.text.strip():
118 log[
'stderr'] =
"No new tarballs to test"
123 log[
'stderr'] =
"An error occurred reading version file: " + cmds[
'version_file']
124 testDef.logger.verbose_print(
"An error occurred reading version file: " + cmds[
'version_file'])
127 testDef.logger.verbose_print(
"Version file does not exist")
133 tarball_base_name =
'openmpi-' + snapshot_req.text.strip()
134 tarball_name = tarball_base_name +
'.tar.gz'
135 download_url = url +
'/' + tarball_name
138 if self.
done[tarball_base_name]
is not None:
139 log[
'status'] = self.
done[tarball_base_name][0]
140 log[
'location'] = self.
done[tarball_base_name][1]
145 if not find_executable(
"curl"):
147 log[
'stderr'] =
"curl command not found"
153 dst = os.path.join(testDef.options[
'scratchdir'], log[
'section'].replace(
":",
"_"))
155 if not os.path.exists(dst): os.mkdir(dst)
158 log[
'stderr'] =
"Unable to create " + dst
164 if os.path.exists(tarball_base_name):
165 if not os.path.isdir(tarball_base_name):
167 log[
'stderr'] =
"Cannot update requested OMPI tarball as a file of that name already exists".format(tarball_base_name)
169 self.done.append((tarball_base_name, 1))
172 os.chdir(tarball_base_name)
183 testDef.logger.verbose_print(
"downloading tarball " + tarball_name +
"url: " + download_url)
184 status, stdout, stderr, _ = testDef.execmd.execute(
None, [
"curl",
"-o", tarball_name, download_url], testDef)
187 log[
'stderr'] =
"download for tarball " + tarball_name +
"url: " + download_url +
"FAILED"
190 testDef.logger.verbose_print(
"untarring tarball " + tarball_name)
191 status, stdout, stderr, _ = testDef.execmd.execute(
None, [
"tar",
"-zxf", tarball_name], testDef)
194 log[
'stderr'] =
"untar of tarball " + tarball_name +
"FAILED"
198 if self.
options[
'version_file']
is not None:
200 f = open(cmds[
'version_file'],
'w')
201 print(snapshot_req.text.strip(), file=f);
204 log[
'stderr'] =
"Failed to update version file"
205 testDef.logger.verbose_print(
"Failed to update version file")
210 os.chdir(tarball_base_name)
212 log[
'status'] = status
213 log[
'stdout'] = stdout
214 log[
'stderr'] = stderr
215 log[
'mpi_info'] = {
'name' : cmds[
'mpi_name'],
'version' : snapshot_req.text.strip()}
216 testDef.logger.verbose_print(
"setting mpi_info to " + str(log.get(
'mpi_info')))
219 log[
'location'] = os.getcwd()
221 self.
done[tarball_base_name] = (status, log[
'location'])