@@ -31,6 +31,7 @@ sys.path.insert(0, f"{cosa_dir}/cosalib")
31
31
sys .path .insert (0 , cosa_dir )
32
32
33
33
from cosalib .cmdlib import get_basearch , load_json , write_json
34
+ from enum import IntEnum
34
35
35
36
try :
36
37
from cosalib .build import _Build
@@ -105,7 +106,8 @@ class Build(_Build):
105
106
# new kind of image here, but _Build is geared towards that and has a
106
107
# image_name_base() member that wants a platform string to name stuff
107
108
self .platform = "koji"
108
- self ._tmpdir = tempfile .mkdtemp (prefix = "koji-build" , dir = kwargs ['buildroot' ])
109
+ self .buildroot = kwargs ['buildroot' ]
110
+ self ._tmpdir = tempfile .mkdtemp (prefix = "koji-build" , dir = self .buildroot )
109
111
self ._state_file_tpl = self ._tmpdir + "/cosa-cmd-koji-upload-{name}-{version}-{release}"
110
112
kwargs .update ({
111
113
"require_commit" : True ,
@@ -116,7 +118,7 @@ class Build(_Build):
116
118
self .name = f"{ self .build_name } -{ self .basearch } "
117
119
self .source = self .get_meta_key (
118
120
"meta" , self .ckey ("container-config-git" ))
119
- self .host_rpms = self .get_rpm_list ('host' )
121
+ self .host_rpms = self .get_rpm_list (RpmListType . HOST )
120
122
def __del__ (self ):
121
123
try :
122
124
shutil .rmtree (self ._tmpdir )
@@ -195,20 +197,41 @@ class Build(_Build):
195
197
196
198
return fname , True
197
199
198
- def get_rpm_list (self , host = None ):
200
+ def get_rpm_list (self , kind : RpmListType ):
199
201
"""
200
- Translate commitmeta.json /HOST OS rpms into a json list
202
+ Translate metadata /HOST OS rpms into a json list
201
203
Returns the json rpms list
202
204
"""
203
205
components = []
204
- if host is None :
206
+ if kind == RpmListType .META :
207
+ file_path = f"{ self .buildroot } /meta.json"
208
+ with open (file_path ) as f :
209
+ data = json .load (f )
210
+ rpms = data ['rpmdb.pkglist' ]
211
+ elif kind == RpmListType .EXTENSIONS :
212
+ file_path = f"{ self .buildroot } /extensions.json"
213
+ with open (file_path ) as f :
214
+ data = json .load (f )
215
+ rpms = []
216
+ # Extensions in node image are stored different
217
+ for name , full_version in data .items ():
218
+ version_release , arch = full_version .rsplit ('.' , 1 )
219
+ version_str , release = version_release .rsplit ('-' , 1 )
220
+ if '.' in version_str :
221
+ epoch , version = version_str .split ('.' , 1 )
222
+ else :
223
+ epoch = '0'
224
+ version = version_str
225
+ rpm_list = [name , epoch , version , release , arch ]
226
+ rpms .append (rpm_list )
227
+ elif kind == RpmListType .COMMITMETA :
205
228
rpms = self .commit ["rpmostree.rpmdb.pkglist" ]
206
- else :
229
+ elif kind == RpmListType . HOST :
207
230
host_rpms = subprocess .check_output ('rpm -qa --qf="%{NAME}:%{EPOCH}:%{RELEASE}:%{VERSION}:%{ARCH}:%{SIGMD5}:%{SIGPGP} \n "' , shell = True ).strip ()
208
231
rpms = (host_rpms .decode ('utf-8' )).split ("\n " )
209
232
210
233
for rpm in rpms :
211
- if host is None :
234
+ if kind != RpmListType . HOST :
212
235
name , epoch , version , release , arch = rpm
213
236
sigmd5 , sigpgp , epoch = None , None , None
214
237
else :
@@ -365,6 +388,11 @@ def kinit(keytab, principle):
365
388
except Exception as err :
366
389
raise Exception ("failed to auth: " , err )
367
390
391
+ class RpmListType (IntEnum ):
392
+ COMMITMETA = 1
393
+ EXTENSIONS = 2
394
+ HOST = 3
395
+ META = 4
368
396
369
397
class _KojiBase ():
370
398
"""
@@ -648,6 +676,10 @@ class Upload(_KojiBase):
648
676
649
677
@property
650
678
def image_files (self ):
679
+ """ Backward-compatible property to maintain existing behavior. """
680
+ return self .get_image_files (meta = False )
681
+
682
+ def get_image_files (self , meta = False ):
651
683
""" Generate outputs prepares the output listing. """
652
684
if self ._image_files is not None :
653
685
return self ._image_files
@@ -657,7 +689,11 @@ class Upload(_KojiBase):
657
689
file_output = self .get_file_meta (value )
658
690
if file_output is not None :
659
691
if "commitmeta.json" in value ['upload_path' ]:
660
- file_output ["components" ] = self .build .get_rpm_list ()
692
+ file_output ["components" ] = self .build .get_rpm_list (RpmListType .COMMITMETA )
693
+ elif "meta.json" in value ['upload_path' ] and meta is not False :
694
+ file_output ["components" ] = self .build .get_rpm_list (RpmListType .META )
695
+ elif "extensions.json" in value ['upload_path' ] and meta is not False :
696
+ file_output ["components" ] = self .build .get_rpm_list (RpmListType .EXTENSIONS )
661
697
outputs .append (file_output )
662
698
self ._image_files = outputs
663
699
return self ._image_files
0 commit comments