-
Notifications
You must be signed in to change notification settings - Fork 86
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
Implementation for ImageService.List #206
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add indent. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
host_modules/image_service.py
Outdated
available_images = [] | ||
|
||
for line in output: | ||
if line.startswith("Current:"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked all versions are this word? recommend use insensitive, like lower first then compare?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to refactor the parsing into a separate helper function, making it easier to test and debug independently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
logger.info("Listing SONiC images") | ||
|
||
try: | ||
output = subprocess.check_output( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still applicable, before we do parse, we could log it for future debug purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
"Available:\n" | ||
"image1\n" | ||
"image2\n" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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"}
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.