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

[vstest] Virtual chssis config rendering from default_config.json #8008

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions platform/vs/docker-sonic-vs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ popd

[ -d /etc/sonic ] || mkdir -p /etc/sonic

if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then
CHASS_CFG="-j /usr/share/sonic/virtual_chassis/default_config.json"
fi

# Note: libswsscommon requires a dabase_config file in /var/run/redis/sonic-db/
# Prepare this file before any dependent application, such as sonic-cfggen
mkdir -p /var/run/redis/sonic-db
cp /etc/default/sonic-db/database_config.json /var/run/redis/sonic-db/

SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
sonic-cfggen -t /usr/share/sonic/templates/init_cfg.json.j2 -a "{\"system_mac\": \"$SYSTEM_MAC_ADDRESS\"}" $CHASS_CFG > /etc/sonic/init_cfg.json
sonic-cfggen -t /usr/share/sonic/templates/init_cfg.json.j2 -a "{\"system_mac\": \"$SYSTEM_MAC_ADDRESS\"}" > /etc/sonic/init_cfg.json

if [[ -f /usr/share/sonic/virtual_chassis/default_config.json ]]; then
sonic-cfggen -j /etc/sonic/init_cfg.json -j /usr/share/sonic/virtual_chassis/default_config.json --print-data > /tmp/init_cfg.json
Copy link
Contributor

@prsunny prsunny Jul 1, 2021

Choose a reason for hiding this comment

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

why dont we write directly to /etc/sonic/init_cfg.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The template /usr/share/sonic/templates/init_cfg.json.j2 does not have j2 code to take the /usr/share/sonic/virtual_chassis/default_config.json contents as data and generate the result with the default_config,json contents in /etc/sonic/init_cfg.json

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, but do you need to write to /tmp/init_cfg.json or can you update init_cfg.json?

Copy link
Contributor Author

@vganesan-nokia vganesan-nokia Jul 1, 2021

Choose a reason for hiding this comment

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

I think it is possible to update the init_cfg.json directly since sonic-cfggen loads all the contents first as data and then produces the output. But for here, I just followed the model used for generating config_db.json (given just below these lines from 43-45) to appear consistent

Copy link
Collaborator

@stepanblyschak stepanblyschak Jul 2, 2021

Choose a reason for hiding this comment

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

@vganesan-nokia Does this mean that "-t" & "-j" does not work together in sonic-cfggen?

-j JSON, --json JSON  json file that contains additional variables
-t TEMPLATE, --template TEMPLATE
                        render the data with the template file

Copy link
Contributor Author

@vganesan-nokia vganesan-nokia Jul 2, 2021

Choose a reason for hiding this comment

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

When -t option is used the template file, the contents of the json file given with option -j are loaded as data to the template. If the template does not have explicit j2 code to take these data, the rendering will not have the json files contents in the output.

So, it IS possible to make -t and -j options work together if the template has appropriate j2 instructions to take the contents of the json file.

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 details, now I understand.

mv /tmp/init_cfg.json /etc/sonic/init_cfg.json
fi

if [ -f /etc/sonic/config_db.json ]; then
sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json
Expand Down