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