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

add onie image install's platform verification #8814

Merged
merged 10 commits into from
Oct 25, 2021

Conversation

wen587
Copy link
Contributor

@wen587 wen587 commented Sep 22, 2021

Depends on #8542. Please DO NOT MERGE before it

Why I did it

Provide onie image install verification

How I did it

Add devices folder based on platform_asic and check if current platform inside the list

How to verify it

In onie env, 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

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

@wen587
Copy link
Contributor Author

wen587 commented Sep 22, 2021

Based on #8542.
Wait for above PR merge first.

@wen587 wen587 requested a review from qiluo-msft September 22, 2021 06:53
@wen587 wen587 marked this pull request as ready for review September 22, 2021 06:57
@wen587 wen587 requested a review from lguohan as a code owner September 22, 2021 06:57
build_image.sh Outdated Show resolved Hide resolved
build_image.sh Outdated Show resolved Hide resolved
build_image.sh Outdated Show resolved Hide resolved
build_image.sh Outdated Show resolved Hide resolved
@@ -92,6 +92,39 @@ VAR_LOG_SIZE=4096

[ -r platforms/$onie_platform ] && . platforms/$onie_platform

# Verify image platform is inside devices list
# Temporarily set TIMEOUT as 10 seconds
if [ "$install_env" = "onie" ] && [ -d devices ]; then
Copy link
Collaborator

@qiluo-msft qiluo-msft Sep 22, 2021

Choose a reason for hiding this comment

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

onie

Is it possible to run on all the envrionment besides ONIE? #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be an option among sonic/onie/build

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have sonic_installer to block wrong platform already. It might be tedious if user input --skip-platform-check and be prompted here the second time to confirm install.

Copy link
Collaborator

@qiluo-msft qiluo-msft Sep 23, 2021

Choose a reason for hiding this comment

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

Reasonable. Could you change sonic-utilities code with same logic, checking platform_asic instead of previous image asic.

Or, we could unify the logic here, so my comment will be finally applicable.

build_image.sh Outdated
{
# Generate asic-specific ONIE device list
rm -rf ./installer/x86_64/devices/
mkdir -p ./installer/x86_64/devices/
Copy link
Collaborator

@qiluo-msft qiluo-msft Sep 23, 2021

Choose a reason for hiding this comment

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

You just need to create an empty file in this folder. No need to remove directory. #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.

generate_onie_installer_image
I am following the above code to refresh the folder every time. And the folder needs to be created the first time.

@qiluo-msft
Copy link
Collaborator

qiluo-msft commented Sep 23, 2021

#!/bin/sh

I notice there are many CPU architectures besides x86_64. Check installer/*/install.sh.


In reply to: 925587223


In reply to: 925587223


Refers to: installer/x86_64/install.sh:1 in e53fc70. [](commit_id = e53fc70, deletion_comment = False)

@wen587 wen587 requested a review from qiluo-msft September 26, 2021 02:29
if [ "$install_env" = "onie" ] && [ "$machine" != "generic" ]; then
if ! grep -Fxq "$onie_platform" devices/platforms_asic; then
INPUT_TIMEOUT=10
echo "The image you're trying to install is of a different platform as the running platform"
Copy link
Collaborator

@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

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

if [ "$install_env" = "onie" ] && [ "$machine" != "generic" ]; then
if ! grep -Fxq "$onie_platform" devices/platforms_asic; then
INPUT_TIMEOUT=10
echo "The image you're trying to install is of a different platform as the running platform"
Copy link
Collaborator

@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

asic #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

INPUT_TIMEOUT=10
echo "The image you're trying to install is of a different platform as the running platform"
while true; do
read -t $INPUT_TIMEOUT -r -p "Do you still wish to install this image? [y/n]: " input
Copy link
Collaborator

@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.

$INPUT_TIMEOUT

Actually there is no requirement to timeout. If the script is used by automation, the prompt will be enough to break the normal path (The automation will have its own timeout).

If the script is used by user, it is too rush for them to response in 10 seconds, and without any hint. #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 remove it

build_image.sh Outdated
cp ./installer/x86_64/devices/platforms_asic .platforms_asic
zip -g $OUTPUT_ABOOT_IMAGE .platforms_asic
rm .platforms_asic
fi
Copy link
Collaborator

@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.

Implement a new function generate_aboot_device_list ? If some logic is common, you can extract into another function like generate_device_list. #Closed

Copy link
Contributor Author

@wen587 wen587 Sep 28, 2021

Choose a reason for hiding this comment

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

Will do.

build_image.sh Outdated
mkdir -p ./installer/x86_64/devices/
for d in `find -L ./device -maxdepth 2 -mindepth 2 -type d`; do
if [ -f $d/platform_asic ] && grep -Fxq "$CONFIGURED_PLATFORM" $d/platform_asic; then
echo "${d##*/}" >> ./installer/x86_64/devices/platforms_asic;
Copy link
Collaborator

@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.

./installer/x86_64/devices/platforms_asic

This filename could be replace by a function parameter, and onie/aboot will call the function with different argument.

Then you don't need the extra step cp ./installer/x86_64/devices/platforms_asic .platforms_asic #Closed

@wen587
Copy link
Contributor Author

wen587 commented Oct 9, 2021

Ready to be merged.

build_image.sh Outdated
@@ -170,6 +184,13 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
zip -g $ABOOT_BOOT_IMAGE version
rm version

generate_device_list ".platforms_asic"
# Check file existence in case of general build
Copy link
Collaborator

@qiluo-msft qiluo-msft Oct 9, 2021

Choose a reason for hiding this comment

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

Check file existence in case of general build

What do you mean by "general build"? Is this file always existing after previous generating function? #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 think the file doesn't exist in some case. For example, if the TARGET_MACHINE was set to 'general', it won't match any platform_asic. I will bypass the check here.

build_image.sh Outdated
local platforms_asic=$1
for d in `find -L ./device -maxdepth 2 -mindepth 2 -type d`; do
if [ -f $d/platform_asic ] && grep -Fxq "$CONFIGURED_PLATFORM" $d/platform_asic; then
echo "${d##*/}" >> "$platforms_asic";
Copy link
Collaborator

@qiluo-msft qiluo-msft Oct 9, 2021

Choose a reason for hiding this comment

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

echo "${d##*/}" >> "$platforms_asic";

You need to clean the file at the begining in case the file is not empty. No need to rm before this function call.
If there is no platforms using CONFIGURED_PLATFORM asic, this function should generated an empty file. #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.

In case of general build, sonic installer verification would bypass because $platforms_asic file is not there. But if it is a empty file, it will fail because no platform is in the file. I guess general build means we could install it to any asic.
CONFIGURED_PLATFORM is general by default.
Check out here. general

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the generic fix!

Still:
clean the file at the begining in case the file is not empty. No need to rm before this function call.
If there is no platforms using CONFIGURED_PLATFORM asic, this function should generated an empty file.

Proposed code

# Generate asic-specific device list
generate_device_list()
{
    local platforms_asic=$1
    
    # Create an empty function, and later append to it
    echo -n > "$platforms_asic"
    
    for d in `find -L ./device  -maxdepth 2 -mindepth 2 -type d`; do
        if [ -f $d/platform_asic ]; then
            if [ "$CONFIGURED_PLATFORM" = "generic" ] || grep -Fxq "$CONFIGURED_PLATFORM" $d/platform_asic; then
                echo "${d##*/}" >> "$platforms_asic";
            fi;
        fi;
    done
}

Otherwise, you need add rm .platforms_asic in the aboot branch, which is actually best cleaned inside this function.

@wen587
Copy link
Contributor Author

wen587 commented Oct 9, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@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 wen587 merged commit ba2968d into sonic-net:master Oct 25, 2021
@TACappleman
Copy link
Contributor

@wen587 is there a way to bypass this check (or respond to it) in automation, e.g. if it's hit in a Jenkins run?

@wen587
Copy link
Contributor Author

wen587 commented Dec 15, 2021

@wen587 is there a way to bypass this check (or respond to it) in automation, e.g. if it's hit in a Jenkins run?

If you are using sonic-installer install, you can use sonic-installer install -f to bypass the check and force install.
If you are using onie install, a char of Y or y need to be responded if the platform does not match.

AidanCopeland pushed a commit to Metaswitch/sonic-buildimage that referenced this pull request Apr 14, 2022
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.

3 participants