Implementation for ImageService.List#206
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
host_modules/image_service.py:171
- The error message should include the actual error output from the subprocess for better debugging. Suggestion: return errno.EIO, "Failed to list images: {}".format(e.output.decode())
return errno.EIO, "Failed to list images"
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
host_modules/image_service.py
Outdated
|
|
||
| except subprocess.CalledProcessError as e: | ||
| logger.error("Failed to list images: {}".format(e.output.decode())) | ||
| return errno.EIO, "Failed to list images" |
There was a problem hiding this comment.
Done. Use json string for success case instead. Such also follows examples from docker.list
host_modules/image_service.py
Outdated
| try: | ||
| output = subprocess.check_output( | ||
| ["/usr/local/bin/sonic-installer", "list"], | ||
| stderr=subprocess.STDOUT, |
There was a problem hiding this comment.
nit: add indent. #Closed
host_modules/image_service.py
Outdated
| available_images = [] | ||
|
|
||
| for line in output: | ||
| if line.startswith("Current:"): |
There was a problem hiding this comment.
Have you checked all versions are this word? recommend use insensitive, like lower first then compare?
There was a problem hiding this comment.
Yes and checked. Lower case isn't really necessary since, the output method in sonic_installer is from 2017 and haven't changed since then.
host_modules/image_service.py
Outdated
| elif line.startswith("Available:"): | ||
| continue | ||
| else: | ||
| available_images.append(line.strip()) |
There was a problem hiding this comment.
Suggest to refactor the parsing into a separate helper function, making it easier to test and debug independently
| logger.info("Listing SONiC images") | ||
|
|
||
| try: | ||
| output = subprocess.check_output( |
There was a problem hiding this comment.
Still applicable, before we do parse, we could log it for future debug purpose.
There was a problem hiding this comment.
We have logs for 1. before calling sonic-installer, 2. the output of sonic-installer before we try to parse it, as well as 3. when sonic-installer have a nonzero rc. Added one for parse result of sonic-installer output.
host_modules/image_service.py
Outdated
| available_images.append(line.strip()) | ||
|
|
||
| except subprocess.CalledProcessError as e: | ||
| logger.error("Failed to list images: {}".format(e.output.decode())) |
| "Available:\n" | ||
| "image1\n" | ||
| "image2\n" | ||
| ) |
There was a problem hiding this comment.
There would be multiple combination for the output, you may have to test and retrieve them in multiple versions?
There was a problem hiding this comment.
What do you mean? All we care about is the service correctly output all of "current", "next" and "available" images, so adding different combinations doesn't really allow us to catch more bugs, right?
There was a problem hiding this comment.
If you check the implementation, you will notice that the current, next, available will be the combination, and they may not exist.
There was a problem hiding this comment.
Thanks for the clarification. Added testcase for outputs like "Current: blah\nNext: blah\n".
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
host_modules/image_service.py
Outdated
|
|
||
| for line in output.split("\n"): | ||
| if "current:" in line.lower(): | ||
| current_image = line.split(":")[1].strip() |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Why I did it Supports OS.Verify for Upgrading OS How I did it Implement GNOI server and client for GNOI.OS.Verify Backend PR: sonic-net/sonic-host-services#206 How to verify it On Mellanox: gnoi_client -target 127.0.0.1:50052 -logtostderr -insecure -module OS -rpc Verify OS Verify {"version":"SONiC-OS-20240510.23"}
|
@hdwhdw can you please help to add the code PRs by referring to sonic-net/SONiC#806 ? Thanks. |
This PR contains implementation for List method in ImageService host module. The method will list the current, next and available SONiC image on the SONiC device.
It will be used in GNOI library for verifying OS installation.