-
Notifications
You must be signed in to change notification settings - Fork 666
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
[sonic_installer] Change sonic_installer check ASIC mismatch by platforms list #1836
Conversation
To make this PR functional, it requires sonic-net/sonic-buildimage#8814 to work. |
@@ -533,14 +533,14 @@ def install(url, force, skip_platform_check=False, skip_migration=False, skip_pa | |||
raise click.Abort() | |||
else: | |||
# Verify not installing non-secure image in a secure running image | |||
if not bootloader.verify_secureboot_image(image_path) and not force: | |||
if not force and not bootloader.verify_secureboot_image(image_path): | |||
echo_and_log("Image file '{}' is of a different type than running image.\n".format(url) + | |||
"If you are sure you want to install this image, use -f|--force|--skip-secure-check.\n" + | |||
"Aborting...", LOG_ERR) | |||
raise click.Abort() | |||
|
|||
# Verify that the binary image is of the same platform type as running platform |
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.
will change
sonic_installer/bootloader/grub.py
Outdated
click.echo("Caught an exception: " + str(e)) | ||
with open(os.devnull, 'w') as fnull: | ||
p = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe) | ||
output = subprocess.check_output(["tar", "xf", "-", PLATFORMS_ASIC, -O], stdin=p.stdout, stderr=fnull, preexec_fn=default_sigpipe, text=True) |
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.
Yes. It works as expected.
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.
My bad. Will change later.
sonic_installer/bootloader/grub.py
Outdated
click.echo("Caught an exception: " + str(e)) | ||
with open(os.devnull, 'w') as fnull: | ||
p = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe) | ||
output = subprocess.check_output(["tar", "xf", "-", PLATFORMS_ASIC, -O], stdin=p.stdout, stderr=fnull, preexec_fn=default_sigpipe, text=True) |
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.
No. I tried locally. None
still prompt error msg.
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.
Then the with
scope is too small, you need to cover p2.wait()
, to be safer, cover until function exit
sonic_installer/bootloader/grub.py
Outdated
with open(os.devnull, 'w') as fnull: | ||
p = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe) | ||
output = subprocess.check_output(["tar", "xf", "-", PLATFORMS_ASIC, -O], stdin=p.stdout, stderr=fnull, preexec_fn=default_sigpipe, text=True) | ||
return platform in 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.
I was thinking using pipe and grep. But seems Popen dont have better ways to handle the case of unexisted file.
Because 'platform_asic nonexistence' and 'platform unmatch' will both produce the empty string if using pipe and grep.
I am thinking of Popen(['sed'...) first then check_call(['tar'...) first to see if there is any CalledProcessError to confirm platforms_asic exist. Then do the above sed & tar then pipe and grep.
But it will cost more time as you can see. Do you prefer the pipe and grep over check_output?
sonic_installer/bootloader/aboot.py
Outdated
try: | ||
output = subprocess.check_output(['/usr/bin/unzip', '-qop', image_path, '.platforms_asic'], text=True) | ||
return platform in output | ||
except subprocess.CalledProcessError: |
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.
I am refering here. Seems the image_path is guaranteed to exist. So it only raise exeption if platform_asic is not existed. Maybe it is enough to just for checking existence?
image_version
sonic_installer/bootloader/aboot.py
Outdated
output = subprocess.check_output(['/usr/bin/unzip', '-qop', image_path, '.platforms_asic'], text=True) | ||
return platform in output | ||
except subprocess.CalledProcessError: | ||
pass |
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.
will change
sonic_installer/bootloader/grub.py
Outdated
output = subprocess.check_output(["tar", "xf", "-", PLATFORMS_ASIC, -O], stdin=p.stdout, stderr=fnull, preexec_fn=default_sigpipe, text=True) | ||
return platform in output | ||
except subprocess.CalledProcessError: | ||
pass |
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.
will change
Regarding the PR description, you can move "Check by devices list instead of machine.conf" into the section "How I did it". Please give more explanation on the question "What I did". This PR actually changes behavior. In reply to: 927791388 |
|
||
# Needed to prevent "broken pipe" error messages when piping | ||
# output of multiple commands using subprocess.Popen() | ||
def default_sigpipe(): |
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). |
What I did
In this patch, the installation process will also check asic but based on platform info which will stay the same even with wrong image installed.
How I did it
Add a devices list file for the same ASIC while build the image and Check by devices list instead of machine.conf
How to verify it
Install a bin file which differs the running platform's ASIC. For example;
install sonic-broadcom.bin to mellanox ASIC platform
install sonic-vs.bin to broadcom ASIC platform
install sonic-aboot-barefoot.swi to broadcom ASIC platform
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)