Skip to content

config: runtime: base: python: make more generic #2909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions config/runtime/base/python.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,36 @@ class BaseJob:
storage_cred = os.getenv('KCI_STORAGE_CREDENTIALS')
return kernelci.storage.get_storage(storage_config, storage_cred)

def _get_tarball_url(self, node):
if node.get('artifacts') and 'tarball' in node['artifacts']:
return node['artifacts']['tarball']
def _get_artifact_url(self, node, artifact):
if node.get('artifacts') and artifact in node['artifacts']:
return node['artifacts'][artifact]
if node.get('parent'):
parent = self._api.node.get(node['parent'])
return self._get_tarball_url(parent)
raise ValueError(f"'tarball' artifact not found in node {self._node['id']} ancestors")
return self._get_artifact_url(parent, artifact)
raise ValueError(f"'{artifact}' artifact not found in node {node['id']} ancestors")

def _get_tarball_url(self, node):
return self._get_artifact_url(node, 'tarball')

def _get_source(self, url):
def _get_source(self, url, path=None):
if path is None:
path = self._workspace
# Ensure our destination folder exists
os.makedirs(path, exist_ok=True)
resp = requests.get(url, stream=True)
resp.raise_for_status()
tarball_name = os.path.basename(urllib.parse.urlparse(url).path)
base, ext = tarball_name.split('.tar.')
with tarfile.open(fileobj=resp.raw, mode=f'r|{ext}') as tarball:
tarball.extractall(path=self._workspace)
return os.path.join(self._workspace, base)
tarball.extractall(path=path)
return os.path.join(path, base)

def _get_kernel_source(self):
print("Getting kernel source tree...")
tarball_url = self._get_tarball_url(self._node)
src_path = self._get_source(tarball_url)
print(f"Source directory: {src_path}")
return src_path

def _run(self, src_path):
raise NotImplementedError("_run() method required to run job")
Expand All @@ -119,10 +133,14 @@ class BaseJob:
if self._node.get('debug') and 'dry_run' in self._node['debug']:
return self.dry_run(self._node['debug']['result'])

print("Getting kernel source tree...")
tarball_url = self._get_tarball_url(self._node)
src_path = self._get_source(tarball_url)
print(f"Source directory: {src_path}")
# Ensure our workspace folder exists
os.makedirs(self._workspace, exist_ok=True)

if self._node.get('kind') == 'kbuild':
src_path = self._get_kernel_source()
else:
src_path = self._workspace

print("Running job...")
return self._run(src_path)

Expand Down