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