35
35
BUILD_ROOT = "https://openshift-release-artifacts.svc.ci.openshift.org/"
36
36
PREVIEW_ROOT = "http://mirror.openshift.com/pub/openshift-v4/{}/clients/ocp-dev-preview/"
37
37
38
- VERSION_RE = re .compile (r"^openshift-install- (?P<platform>\w+) "
39
- r"(-(?P<architecture>\w+))?-(?P<version>\d+.*)\.tar\.gz" )
38
+ VERSION_RE = re .compile (r"^openshift-install(-rhel (?P<rhel>\d+))?(-(?P<platform>(linux|mac)))? "
39
+ r"(-(?P<architecture>\w+))?( -(?P<version>\d+.*))? \.tar\.gz" )
40
40
EXTRACTION_RE = re .compile (r'.*Extracting tools for .*, may take up to a minute.*' )
41
41
42
42
43
- def _current_platform ():
43
+ def _current_platform () -> Tuple [ str , str ] :
44
44
if platform .system () == "Linux" and platform .machine () == "x86_64" :
45
45
return "linux" , "amd64"
46
46
if platform .system () == "Linux" and (
@@ -54,10 +54,14 @@ def _current_platform():
54
54
raise Exception (f"Unrecognized platform { platform .system ()} { platform .machine ()} " )
55
55
56
56
57
- def get_url (directory : str , arch : str ) -> Tuple [Optional [str ], Optional [str ]]:
57
+ def get_url (directory : str , arch : str , fips : bool = False ,
58
+ rhel_version : str = None ) -> Tuple [Optional [str ], Optional [str ]]:
58
59
"""Searches the http directory and returns both url to installer
59
60
and version.
60
61
"""
62
+ if fips and not rhel_version :
63
+ raise Exception ("Rhel version was not detected. Please download installer separatly." )
64
+
61
65
logging .debug ('Url for installers look-up %s' , directory )
62
66
lst = requests .get (directory , allow_redirects = True )
63
67
tree = BeautifulSoup (lst .content , 'html.parser' )
@@ -67,16 +71,29 @@ def get_url(directory: str, arch: str) -> Tuple[Optional[str], Optional[str]]:
67
71
for k in links :
68
72
logging .debug ('Parsing link: %s' , k .get ('href' ))
69
73
match = VERSION_RE .match (k .get ('href' ))
70
- if match and match .group ('platform' ) == os_name :
71
- if (local_arch == match .group ('architecture' )) \
72
- or (local_arch == arch and not match .group ('architecture' )):
73
- installer = lst .url + k .get ('href' )
74
+
75
+ if match :
76
+ if match .group ("version" ):
74
77
version = match .group ('version' )
78
+
79
+ if fips and match .group ("rhel" ) == rhel_version :
80
+ installer = lst .url + k .get ('href' )
75
81
break
82
+
83
+ if not fips and match .group ('platform' ) == os_name :
84
+ if (local_arch == match .group ('architecture' )) \
85
+ or (local_arch == arch and not match .group ('architecture' )):
86
+ installer = lst .url + k .get ('href' )
87
+ break
88
+ else :
89
+ if fips :
90
+ raise Exception (f"FIPS Installer not found for { rhel_version = } " )
91
+ raise Exception ("Installer not found" )
76
92
return installer , version
77
93
78
94
79
- def get_devel_url (version : str , arch : str ) -> Tuple [Optional [str ], Optional [str ]]:
95
+ def get_devel_url (version : str , arch : str , fips : bool = False ,
96
+ rhel_version : str = None ) -> Tuple [Optional [str ], Optional [str ]]:
80
97
"""
81
98
Searches developement sources and returns url to installer
82
99
"""
@@ -89,17 +106,19 @@ def get_devel_url(version: str, arch: str) -> Tuple[Optional[str], Optional[str]
89
106
req = requests .get (BUILD_ROOT + version , allow_redirects = True )
90
107
ast = BeautifulSoup (req .content , 'html.parser' )
91
108
logging .debug ('Installer found on page, continuing' )
92
- return get_url (req .url , arch )
109
+ return get_url (req .url , arch , fips , rhel_version )
93
110
94
111
95
- def get_prev_url (version : str , arch : str ) -> Tuple [Optional [str ], Optional [str ]]:
112
+ def get_prev_url (version : str , arch : str , fips : bool = False ,
113
+ rhel_version : str = None ) -> Tuple [Optional [str ], Optional [str ]]:
96
114
"""Returns installer url from dev-preview sources"""
97
- return get_url (PREVIEW_ROOT .format (arch ) + version + "/" , arch )
115
+ return get_url (PREVIEW_ROOT .format (arch ) + version + "/" , arch , fips , rhel_version )
98
116
99
117
100
- def get_prod_url (version : str , arch : str ) -> Tuple [Optional [str ], Optional [str ]]:
118
+ def get_prod_url (version : str , arch : str , fips : bool = False ,
119
+ rhel_version : str = None ) -> Tuple [Optional [str ], Optional [str ]]:
101
120
"""Returns installer url from production sources"""
102
- return get_url (PROD_ROOT .format (arch ) + version + "/" , arch )
121
+ return get_url (PROD_ROOT .format (arch ) + version + "/" , arch , fips , rhel_version )
103
122
104
123
105
124
def _get_storage_path (version : str , install_base : str ) -> str :
@@ -115,12 +134,12 @@ def _extract_tar(buffer: NamedTemporaryFile, target: str) -> Path:
115
134
with tarfile .open (buffer .name ) as tar :
116
135
inst_info = None
117
136
for i in tar .getmembers ():
118
- if i .name == 'openshift-install' :
137
+ if i .name in [ 'openshift-install' , 'openshift-install-fips' ] :
119
138
inst_info = i
120
139
if inst_info is None :
121
140
raise Exception ("error" )
122
141
stream = tar .extractfile (inst_info )
123
- result = Path (target ).joinpath ('openshift-install' )
142
+ result = Path (target ).joinpath (inst_info . name )
124
143
with result .open ('wb' ) as output :
125
144
copyfileobj (stream , output )
126
145
result .chmod (result .stat ().st_mode | stat .S_IXUSR )
@@ -132,10 +151,13 @@ def get_installer(tar_url: str, target: str):
132
151
return get_data (tar_url , target , _extract_tar )
133
152
134
153
154
+ # pylint: disable=too-many-arguments
135
155
def download_installer (installer_version : str ,
136
156
installer_arch : str ,
137
157
dest_directory : str ,
138
- source : str ) -> str :
158
+ source : str ,
159
+ fips : bool = False ,
160
+ rhel_version : str = None ) -> str :
139
161
"""Starts search and extraction of installer"""
140
162
logging .debug ("Getting version %s of %s, storing to directory %s and devel is %r" ,
141
163
installer_version , installer_arch , dest_directory , source )
@@ -150,12 +172,17 @@ def download_installer(installer_version: str,
150
172
else :
151
173
raise Exception ("Error for source profile " + source )
152
174
153
- url , version = downloader (installer_version , installer_arch )
175
+ url , version = downloader (installer_version , installer_arch , fips , rhel_version )
154
176
logging .debug ('Installer\' s URL is %s and full version is %s' , url , version )
155
177
root = Path (dest_directory ).joinpath (version )
156
178
157
- if root .exists () and root .joinpath ('openshift-install' ).exists ():
179
+ installer_exe_name = 'openshift-install'
180
+
181
+ if fips :
182
+ installer_exe_name = 'openshift-install-fips'
183
+
184
+ if root .exists () and root .joinpath (installer_exe_name ).exists ():
158
185
logging .info ('Found installer at %s' , root .as_posix ())
159
- return root .joinpath ('openshift-install' ).as_posix ()
160
- root .mkdir (parents = True )
186
+ return root .joinpath (installer_exe_name ).as_posix ()
187
+ root .mkdir (parents = True , exist_ok = True )
161
188
return get_installer (url , root .as_posix ())
0 commit comments