Skip to content

Commit

Permalink
fix(kbuild): On kbuild failures generate failure for node
Browse files Browse the repository at this point in the history
Generate incomplete state with proper error message for easier
diagnostics, for example missing fragment.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Oct 9, 2024
1 parent e533da4 commit 6cb63d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions kernelci/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ErrorCodes(str, enum.Enum):
OBJECT_NOT_PERSISTED = 'ObjectNotPersisted'
UNEXISTING_PERMISSION_CODENAME = 'Unexisting permission codename.'
JOB_GENERATION_ERROR = 'job_generation_error'
KBUILD_INTERNAL_ERROR = 'kbuild_internal_error'


class KernelVersion(BaseModel):
Expand Down
30 changes: 29 additions & 1 deletion kernelci/kbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ def _getcrosfragment(self, fragment):
def extract_config(self, frag):
""" Extract config fragments from legacy config file """
txt = ''
config = frag['configs']
config = frag.get('configs', None)
if not config:
print("No configs section in fragment")
config = []

for c in config:
txt += c + '\n'
return txt
Expand All @@ -440,20 +444,23 @@ def add_legacy_fragment(self, fragname):

if not yml:
print(f"No suitable config file found in {LEGACY_CONFIG}")
self.submit_failure(f"No suitable config file found in {LEGACY_CONFIG}")
sys.exit(1)

print(f"Searching for fragment {fragname} in {cfg_path}")
if 'fragments' in yml:
frag = yml['fragments']
else:
print("No fragments section in config file")
self.submit_failure("No fragments section in config file")
sys.exit(1)

if fragname in frag:
txt = self.extract_config(frag[fragname])
buffer += txt
else:
print(f"Fragment {fragname} not found")
self.submit_failure(f"Fragment {fragname} not found")
sys.exit(1)

return buffer
Expand All @@ -468,7 +475,9 @@ def _parse_fragments(self, firmware=False):
elif fragment.startswith("CONFIG_"):
content = fragment + '\n'
else:
# TODO: implement 'path' option properly
content = self.add_legacy_fragment(fragment)

fragfile = os.path.join(self._fragments_dir, f"{num}.config")
with open(fragfile, 'w') as f:
f.write(content)
Expand Down Expand Up @@ -825,6 +834,25 @@ def _update_metadata(self, job_result):
with open(metadata_file, 'w') as f:
json.dump(metadata, f, indent=4)

def submit_failure(self, message):
'''
Submit to API that kbuild failed due internal error
'''
node = self._node.copy()
node['result'] = 'incomplete'
node['state'] = 'done'
if 'data' not in node:
node['data'] = {}
node['data']['error_code'] = 'kbuild_internal_error'
node['data']['error_msg'] = message
api = kernelci.api.get_api(self._api_config, self._api_token)
try:
api.node.update(node)
except requests.exceptions.HTTPError as err:
err_msg = json.loads(err.response.content).get("detail", [])
self.log.error(err_msg)
return

def submit(self, retcode, dry_run=False):
'''
Submit results to API and artifacts to storage
Expand Down

0 comments on commit 6cb63d0

Please sign in to comment.