Skip to content

Commit dfd996f

Browse files
committed
cmd-koji-upload: Refactor get_rpm_list
- Refactor get_rpm_list to allow packages from the new meta.json and extensions.json from the node-image Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
1 parent 1eecfd9 commit dfd996f

1 file changed

Lines changed: 37 additions & 7 deletions

File tree

src/cmd-koji-upload

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class Build(_Build):
105105
# new kind of image here, but _Build is geared towards that and has a
106106
# image_name_base() member that wants a platform string to name stuff
107107
self.platform = "koji"
108-
self._tmpdir = tempfile.mkdtemp(prefix="koji-build", dir=kwargs['buildroot'])
108+
self.buildroot = kwargs['buildroot']
109+
self._tmpdir = tempfile.mkdtemp(prefix="koji-build", dir=self.buildroot)
109110
self._state_file_tpl = self._tmpdir + "/cosa-cmd-koji-upload-{name}-{version}-{release}"
110111
kwargs.update({
111112
"require_commit": True,
@@ -116,7 +117,7 @@ class Build(_Build):
116117
self.name = f"{self.build_name}-{self.basearch}"
117118
self.source = self.get_meta_key(
118119
"meta", self.ckey("container-config-git"))
119-
self.host_rpms = self.get_rpm_list('host')
120+
self.host_rpms = self.get_rpm_list(host=True)
120121
def __del__(self):
121122
try:
122123
shutil.rmtree(self._tmpdir)
@@ -195,20 +196,41 @@ class Build(_Build):
195196

196197
return fname, True
197198

198-
def get_rpm_list(self, host=None):
199+
def get_rpm_list(self, **kwargs):
199200
"""
200201
Translate commitmeta.json/HOST OS rpms into a json list
201202
Returns the json rpms list
202203
"""
203204
components = []
204-
if host is None:
205+
if "meta" in kwargs:
206+
file_path = f"{self.buildroot}/meta.json"
207+
with open(file_path) as f:
208+
data = json.load(f)
209+
rpms = data['rpmdb.pkglist']
210+
if "extensions" in kwargs:
211+
file_path = f"{self.buildroot}/extensions.json"
212+
with open(file_path) as f:
213+
data = json.load(f)
214+
rpms = []
215+
# Extensions in node image are stored different
216+
for name, full_version in data.items():
217+
version_release, arch = full_version.rsplit('.', 1)
218+
version_str, release = version_release.rsplit('-', 1)
219+
if '.' in version_str:
220+
epoch, version = version_str.split('.', 1)
221+
else:
222+
epoch = '0'
223+
version = version_str
224+
rpm_list = [name, epoch, version, release, arch]
225+
rpms.append(rpm_list)
226+
if "commitmeta" in kwargs:
205227
rpms = self.commit["rpmostree.rpmdb.pkglist"]
206-
else:
228+
if "host" in kwargs:
207229
host_rpms = subprocess.check_output('rpm -qa --qf="%{NAME}:%{EPOCH}:%{RELEASE}:%{VERSION}:%{ARCH}:%{SIGMD5}:%{SIGPGP} \n"', shell=True).strip()
208230
rpms = (host_rpms.decode('utf-8')).split("\n")
209231

210232
for rpm in rpms:
211-
if host is None:
233+
if any(key in kwargs for key in ("meta", "commitmeta", "extensions")):
212234
name, epoch, version, release, arch = rpm
213235
sigmd5, sigpgp, epoch = None, None, None
214236
else:
@@ -648,6 +670,10 @@ class Upload(_KojiBase):
648670

649671
@property
650672
def image_files(self):
673+
""" Backward-compatible property to maintain existing behavior. """
674+
return self.get_image_files(meta=False)
675+
676+
def get_image_files(self, meta=False):
651677
""" Generate outputs prepares the output listing. """
652678
if self._image_files is not None:
653679
return self._image_files
@@ -657,7 +683,11 @@ class Upload(_KojiBase):
657683
file_output = self.get_file_meta(value)
658684
if file_output is not None:
659685
if "commitmeta.json" in value['upload_path']:
660-
file_output["components"] = self.build.get_rpm_list()
686+
file_output["components"] = self.build.get_rpm_list(commitmeta=True)
687+
if "meta.json" in value['upload_path'] and meta is not False:
688+
file_output["components"] = self.build.get_rpm_list(meta=True)
689+
if "extensions.json" in value['upload_path'] and meta is not False:
690+
file_output["components"] = self.build.get_rpm_list(extensions=True)
661691
outputs.append(file_output)
662692
self._image_files = outputs
663693
return self._image_files

0 commit comments

Comments
 (0)