Skip to content
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

Merged
merged 7 commits into from
Oct 25, 2021

Conversation

wen587
Copy link
Contributor

@wen587 wen587 commented Sep 22, 2021

What I did

  1. Handle wrong image type installation by checking platform. Before the verification was done by comparing image's ASIC and running platform's ASIC. But the running's ASIC will change if wrong image was installed.
    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.
  2. Add the same support for Aboot image verification.

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)

@wen587 wen587 changed the title Use devicelist to check instead of machine.conf [sonic_installer]Change sonic_installer check ASIC mismatch by platforms list Sep 23, 2021
@wen587
Copy link
Contributor Author

wen587 commented Sep 23, 2021

To make this PR functional, it requires sonic-net/sonic-buildimage#8814 to work.
But it can also be merged alone. Because it works backward compatible.

@wen587 wen587 requested a review from qiluo-msft September 26, 2021 02:27
@wen587 wen587 marked this pull request as ready for review September 26, 2021 02:27
@@ -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
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

platform

Platform has multiple meanings in SONiC context. Suggest platform -> asic
running platform -> running platform's asic type #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change

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)
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

-O

Did you test this line? #Closed

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

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)
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

stderr=fnull

Is it the same as the default value None? #Closed

Copy link
Contributor Author

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.

Copy link
Contributor

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

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
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

output

output could be a long list. You can reduce the memory consuption by continuing pipe and grep, or use line-by-line file manipulation. #Closed

Copy link
Contributor Author

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?

try:
output = subprocess.check_output(['/usr/bin/unzip', '-qop', image_path, '.platforms_asic'], text=True)
return platform in output
except subprocess.CalledProcessError:
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

CalledProcessError

This section is good consideration for downgrade use case.

However, CalledProcessError is larger than the the case ".platforms_asic is not existed". Could you check it in straighforward way? #Closed

Copy link
Contributor Author

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

output = subprocess.check_output(['/usr/bin/unzip', '-qop', image_path, '.platforms_asic'], text=True)
return platform in output
except subprocess.CalledProcessError:
pass
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

pass

Your comment said "simply return True" #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change

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
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2021

Choose a reason for hiding this comment

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

pass

simply return True #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Sep 27, 2021

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

@qiluo-msft qiluo-msft changed the title [sonic_installer]Change sonic_installer check ASIC mismatch by platforms list [sonic_installer] Change sonic_installer check ASIC mismatch by platforms list Sep 29, 2021
@wen587 wen587 requested a review from qiluo-msft September 30, 2021 02:38

# Needed to prevent "broken pipe" error messages when piping
# output of multiple commands using subprocess.Popen()
def default_sigpipe():
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 30, 2021

Choose a reason for hiding this comment

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

default_sigpipe

what is the impact of ""broken pipe" error messages when piping" ? #Closed

qiluo-msft
qiluo-msft previously approved these changes Oct 9, 2021
@wen587
Copy link
Contributor Author

wen587 commented Oct 11, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wen587
Copy link
Contributor Author

wen587 commented Oct 15, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wen587 wen587 merged commit 8ea834b into sonic-net:master Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants