Skip to content

Commit

Permalink
Fixed Support for Suse source package can be get via API
Browse files Browse the repository at this point in the history
Signed-off-by: Praveen K Pandey <[email protected]>
  • Loading branch information
PraveenPenguin committed Apr 16, 2024
1 parent c14deac commit 7e5730f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions common/OpTestUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,15 +2274,16 @@ def get_distro_version(self):
res = self.get_distro_details()
return res.get('VERSION_ID')[0].strip("\"")

def get_distro_src(self, package, dest_path, build_option=None):
def get_distro_src(self, package, dest_path, build_option=None, pack_dir=None):

'''
Downloads the source package and prepares it in the given dest_path
to be ready to build.
:param package: name of the package
:param dest_path: destination_path
:param build_option : rpmbuild option
:param build_option : rpmbuild option
:param pack_dir: final pakage dir in case of sles
:return path: build directory
'''
if dest_path is None:
Expand Down Expand Up @@ -2314,21 +2315,22 @@ def get_distro_src(self, package, dest_path, build_option=None):
return ""

elif self.distro_name() == 'sles':
host.host_run_command("zypper install rpm-build -y")
s_cmd = f"zypper -n source-install {package}"
host.host_run_command("zypper install -y rpm-build")
s_cmd = f"zypper -n source-install {package};cd /usr/src/packages/SOURCES/;./mkspec;cp {package}.spec ../SPECS/"
if host.host_run_command(s_cmd):

spec_path = f"/usr/src/packages/SPECS/{package}.spec"
else:
spec_path = None
if spec_path:
return self.prepare_source(spec_path,host, dest_path, package, build_option)
return self.prepare_source(spec_path,host, dest_path, package, build_option, 'sles', pack_dir)
else:
log.error("Failed to install distro package")
else:
return ""


def prepare_source(self,spec_file, host, dest_path, package, build_option=None):
def prepare_source(self,spec_file, host, dest_path, package, build_option=None, distro=None, pack_dir=None):
"""
Rpmbuild the spec path and return build dir
Expand All @@ -2344,7 +2346,10 @@ def prepare_source(self,spec_file, host, dest_path, package, build_option=None):
build_option += f" --define '_builddir {dest_path}'"
try:
host.host_run_command(f"rpmbuild {build_option} {spec_file}")
return host.host_run_command(f"ls -d -- {dest_path}/* | grep {package}")[0]
dir_name = host.host_run_command(f"ls -d -- {dest_path}/* | grep {package}")[0]
if distro is not None:
dir_name = host.host_run_command(f"ls -d -- {dir_name}/* | grep linux")[0]
return dir_name
except OpTestError:
return ""

Expand Down

0 comments on commit 7e5730f

Please sign in to comment.