Skip to content

fix(ci): handle empty API responses safely in azure_marketplace_publi… - #4208

Open
shellyco-code wants to merge 1 commit into
flatcar:mainfrom
shellyco-code:fix/azure-marketplace-publish-indexerror
Open

fix(ci): handle empty API responses safely in azure_marketplace_publi…#4208
shellyco-code wants to merge 1 commit into
flatcar:mainfrom
shellyco-code:fix/azure-marketplace-publish-indexerror

Conversation

@shellyco-code

@shellyco-code shellyco-code commented Aug 11, 2026

Copy link
Copy Markdown

This PR fixes potential IndexError and JSONDecodeError runtime exceptions in ci-automation/release/azure_marketplace_publish.py. When fetching product or plan durable IDs from Microsoft Partner Center (get_product_durable_id and get_plan_durable_id), empty API responses or unexpected payloads caused fixed-index string splits (split("/")[1] / split("/")[2]) to throw an IndexError.

To prevent crashes during marketplace image publishing, string path splits were updated to .split("/")[-1] alongside early null-checks (if not product_durable_id: / if not plan_durable_id:) to safely skip invalid offers. Additionally, try/except error handling was wrapped around resp.json() across get_product_durable_id, get_plan_durable_id, get_image_versions, and generate_partner_center_token to validate dictionary structures before accessing response fields, and get_active_plans now falls back to returning [] if channel-info.txt cannot be fetched.

Fixes flatcar/Flatcar#2316.

How to use

Reviewers can inspect ci-automation/release/azure_marketplace_publish.py or execute the publishing script in test mode (-t / --test-mode) with Partner Center credentials to verify that missing or empty API responses for offers or plans log an error and skip cleanly without raising unhandled IndexError exceptions.

Testing done

  1. Python Compilation Test:
python -m py_compile ci-automation/release/azure_marketplace_publish.py

Output: Exit code 0 (no syntax errors)

  1. Automated Unit Tests:
    Executed unit tests covering valid API payloads, empty {"value": []} arrays, non-JSON HTTP responses, and variable-length ID path formats:
python test_azure_publish.py

Output:

ERROR:root:There is some issue with the channel-info.txt file. Please check https://flatcar.cdn.cncf.io/channel-info.txt
ERROR:root:Returned status code: 404
.WARNING:root:No existing vmImageVersions found for product 'prod', plan 'plan'.
.ERROR:root:Failed to fetch plan durable ID for product 'product1', plan 'plan1'. Status: 200, Response: {"value": []}
.ERROR:root:Failed to fetch product durable ID for offer 'offer1'. Status: 200, Response: {"value": []}
ERROR:root:Failed to parse JSON response for product durable ID (offer 'offer1'). Status: 200, Error: Invalid JSON
..
----------------------------------------------------------------------
Ran 5 tests in 0.008s

OK
  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

Signed-off-by: shellyco-code shellychahar57@gmail.com

…sh.py

Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@shellyco-code
shellyco-code requested a review from a team as a code owner August 11, 2026 09:18
@ader1990 ader1990 added the question Further information is requested label Aug 11, 2026

@sayanchowdhury sayanchowdhury left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @shellyco-code

Currently there is too much of duplication of the code. How about having a method like _parse_json_dict(resp, context) where the context can have all the info to build the error message.

Comment on lines +424 to +425
product_durable_id = product_durable_id.split("/")[-1]
plan_durable_id = plan_durable_id.split("/")[-1]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave updating the index?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants