-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[installer] Fix variable inside machine.conf caused install.sh error #6600
Changes from 2 commits
538dc42
b085c74
72514f9
ec36f85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,21 @@ _trap_push() { | |
} | ||
_trap_push true | ||
|
||
read_conf_file() { | ||
local conf_file=$1 | ||
while IFS='=' read -r var value | ||
do | ||
f_char=$(echo $var | cut -c1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you assume the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your suggestion is helpful. I modify this part to remove the string behind |
||
[ "$f_char" = "#" ] && continue | ||
[ -z "$var" ] && continue | ||
# remove double quote in the beginning | ||
tmp_val=${value#\"} | ||
# remove double quote in the end | ||
value=${tmp_val%\"} | ||
eval "$var=\"$value\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not familiar with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In reply to: 568218112 [](ancestors = 568218112) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it in sh environment. There is no |
||
done < "$conf_file" | ||
} | ||
|
||
# Main | ||
set -e | ||
cd $(dirname $0) | ||
|
@@ -37,7 +52,7 @@ else | |
fi | ||
|
||
if [ -r ./machine.conf ]; then | ||
. ./machine.conf | ||
read_conf_file "./machine.conf" | ||
fi | ||
|
||
if [ -r ./onie-image.conf ]; then | ||
|
@@ -54,9 +69,9 @@ fi | |
|
||
# get running machine from conf file | ||
if [ -r /etc/machine.conf ]; then | ||
. /etc/machine.conf | ||
read_conf_file "/etc/machine.conf" | ||
elif [ -r /host/machine.conf ]; then | ||
. /host/machine.conf | ||
read_conf_file "/host/machine.conf" | ||
elif [ "$install_env" != "build" ]; then | ||
echo "cannot find machine.conf" | ||
exit 1 | ||
|
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.
Could you write a unit test to cover old cases and your new feature? #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.
Sure. But what kind of the test will be better and suitable?
Add a test inside sonic-mgmt and be independent from building. Or, add additional process to test this during building.
I haven't found similar case of this type of unit test.
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.
read_conf_file()
is complex. I expect you have tested it locally. Could you just automate the test in another shell script or a python test runner.In future we may either improve the code or the testcases.
In reply to: 568342160 [](ancestors = 568342160)
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 just copied the function to another script and test it with a sample
machine.conf
.The test can only be triggered manually for now.