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 8, 2024
1 parent 34e668c commit e06b8b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
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
38 changes: 34 additions & 4 deletions 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?")
return None

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

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

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

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

return buffer

Expand All @@ -469,6 +476,10 @@ def _parse_fragments(self, firmware=False):
content = fragment + '\n'
else:
content = self.add_legacy_fragment(fragment)
if not content:
self.submit_failure(f"Fragment {fragment} not found")
sys.exit(0)

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 +836,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 e06b8b4

Please sign in to comment.