Move all minigraph-related action from rc.local to updategraph (#1452)

- Move all minigraph-related action from rc.local to updategraph
- updategraph service is now after database. All feature services are now after and depending on updategraph
This commit is contained in:
Taoyu Li 2018-03-09 17:17:08 -08:00 committed by GitHub
parent 16f81afe9a
commit e84e093dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 129 additions and 88 deletions

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=BGP container Description=BGP container
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=DHCP relay container Description=DHCP relay container
Requires=docker.service teamd.service Requires=updategraph.service swss.service teamd.service
After=swss.service teamd.service After=updategraph.service swss.service teamd.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=LLDP container Description=LLDP container
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Platform monitor container Description=Platform monitor container
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Router advertiser container Description=Router advertiser container
Requires=docker.service Requires=updategraph.service
After=swss.service After=updategraph.service swss.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=SNMP container Description=SNMP container
Requires=database.service swss.service Requires=updategraph.service swss.service
After=database.service swss.service After=updategraph.service swss.service
[Service] [Service]
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStartPre=/usr/bin/{{docker_container_name}}.sh start

View File

@ -1,12 +1,12 @@
[Unit] [Unit]
Description=switch state service Description=switch state service
Requires=database.service Requires=database.service updategraph.service
{% if sonic_asic_platform == 'broadcom' %} {% if sonic_asic_platform == 'broadcom' %}
Requires=opennsl-modules-3.16.0-5-amd64.service Requires=opennsl-modules-3.16.0-5-amd64.service
{% elif sonic_asic_platform == 'nephos' %} {% elif sonic_asic_platform == 'nephos' %}
Requires=nps-modules-3.16.0-5-amd64.service Requires=nps-modules-3.16.0-5-amd64.service
{% endif %} {% endif %}
After=database.service After=database.service updategraph.service
After=interfaces-config.service After=interfaces-config.service
{% if sonic_asic_platform == 'broadcom' %} {% if sonic_asic_platform == 'broadcom' %}
After=opennsl-modules-3.16.0-5-amd64.service After=opennsl-modules-3.16.0-5-amd64.service

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=TEAMD container Description=TEAMD container
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
User={{ sonicadmin_user }} User={{ sonicadmin_user }}

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Control Plane ACL configuration daemon Description=Control Plane ACL configuration daemon
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=simple Type=simple

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Host config enforcer daemon Description=Host config enforcer daemon
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=simple Type=simple

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Update hostname based on configdb Description=Update hostname based on configdb
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Update interfaces configuration Description=Update interfaces configuration
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Update NTP configuration Description=Update NTP configuration
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -157,15 +157,6 @@ firsttime_exit()
exit 0 exit 0
} }
test_config()
{
if [ -d /host/old_config ] && ( [ -f /host/old_config/minigraph.xml ] || [ -f /host/old_config/config_db.json ] ); then
return 0
fi
return 1
}
# Given a string of tuples of the form field=value, extract the value for a field # Given a string of tuples of the form field=value, extract the value for a field
# In : $string, $field # In : $string, $field
# Out: $value # Out: $value
@ -193,46 +184,21 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then
firsttime_exit firsttime_exit
fi fi
if [ ! -f /etc/sonic/init_cfg.json ]; then
# Generate an empty init_cfg.json
echo '{}' > /etc/sonic/init_cfg.json
fi
# Try to take old configuration saved during installation # Try to take old configuration saved during installation
if test_config; then # and create a flag in /tmp/ to let updategraph service know
rm -f /host/old_config/sonic_version.yml if [ -d /host/old_config ]; then
mv -f /host/old_config/* /etc/sonic/ mv -f /host/old_config /etc/sonic/
if [ ! -f /etc/sonic/config_db.json ]; then touch /tmp/pending_config_migration
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
fi
elif [ -f /host/minigraph.xml ]; then elif [ -f /host/minigraph.xml ]; then
mv /host/minigraph.xml /etc/sonic/ mkdir -p /etc/sonic/old_config
# Combine information in minigraph and init_cfg.json to form initiate config DB dump file. mv /host/minigraph.xml /etc/sonic/old_config/
# TODO: After moving all information from minigraph to DB, sample config DB dump should be provide touch /tmp/pending_config_migration
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
elif [ -n "$migration" ] && [ -f /host/migration/minigraph.xml ]; then elif [ -n "$migration" ] && [ -f /host/migration/minigraph.xml ]; then
# Use the minigraph that was imported from the NOS mkdir -p /etc/sonic/old_config
mv /host/migration/minigraph.xml /etc/sonic/ mv /host/migration/minigraph.xml /etc/sonic/old_config/
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json touch /tmp/pending_config_migration
else else
# Use default minigraph.xml touch /tmp/pending_config_initialization
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
fi
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v DEVICE_METADATA.localhost.hwsku`
if [ -f /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 ]; then
# generate and merge buffers configuration into config file
sonic-cfggen -m -t /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 > /tmp/buffers.json
sonic-cfggen -j /etc/sonic/config_db.json -j /tmp/buffers.json --print-data > /tmp/config_db.json
mv /tmp/config_db.json /etc/sonic/config_db.json
# Only apply qos.json when buffer configuration is available.
if [ -f /usr/share/sonic/device/$platform/$HWSKU/qos.json ]; then
# merge qos configuration into init config file
sonic-cfggen -j /etc/sonic/config_db.json -j /usr/share/sonic/device/$platform/$HWSKU/qos.json --print-data > /tmp/config_db.json
mv /tmp/config_db.json /etc/sonic/config_db.json
fi
fi fi
if [ -d /host/image-$sonic_version/platform/$platform ]; then if [ -d /host/image-$sonic_version/platform/$platform ]; then

View File

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=Update rsyslog configuration Description=Update rsyslog configuration
Requires=database.service Requires=updategraph.service
After=database.service After=updategraph.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,6 +1,7 @@
[Unit] [Unit]
Description=Takes care of updates to SSH config file with respect to the SSH allow list Description=Takes care of updates to SSH config file with respect to the SSH allow list
After=database.service After=updategraph.service
Requires=updategraph.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service] [Service]

View File

@ -1,5 +1,38 @@
#!/bin/bash #!/bin/bash
CONFIG_DB_INDEX=4
reload_minigraph()
{
echo "Reloading minigraph..."
if [ ! -f /etc/sonic/init_cfg.json ]; then
echo "{}" > /etc/sonic/init_cfg.json
fi
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
if [ -f /etc/sonic/acl.json ]; then
acl-loader update full /etc/sonic/acl.json
fi
config qos reload
}
copy_default_minigraph()
{
. /host/machine.conf
if [ -n "$aboot_platform" ]; then
platform=$aboot_platform
elif [ -n "$onie_platform" ]; then
platform=$onie_platform
else
echo "Unknown sonic platform."
exit 1
fi
echo "Copying default minigraph..."
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
}
if [ ! -f /etc/sonic/updategraph.conf ]; then if [ ! -f /etc/sonic/updategraph.conf ]; then
echo "No updategraph.conf found, generating a default one." echo "No updategraph.conf found, generating a default one."
echo "enabled=false" >/etc/sonic/updategraph.conf echo "enabled=false" >/etc/sonic/updategraph.conf
@ -7,6 +40,47 @@ fi
. /etc/sonic/updategraph.conf . /etc/sonic/updategraph.conf
if [ -f /tmp/pending_config_migration ]; then
if [ "$enabled" = "true" ]; then
echo "Use minigraph.xml from old system..."
cp /etc/sonic/old_config/minigraph.xml /etc/sonic/
if [ -f /etc/sonic/old_config/init_cfg.json ]; then
cp /etc/sonic/old_config/init_cfg.json /etc/sonic/
fi
if [ -f /etc/sonic/old_config/snmp.yml ]; then
cp /etc/sonic/old_config/snmp.yml /etc/sonic/
fi
if [ -f /etc/sonic/old_config/acl.json ]; then
cp /etc/sonic/old_config/acl.json /etc/sonic/
fi
reload_minigraph
sonic-cfggen -d --print-data > /etc/sonic/config_db.json
else
echo "Use config_db.json from old system..."
cp /etc/sonic/old_config/config_db.json /etc/sonic/
sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
fi
rm -f /tmp/pending_config_migration
sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf
exit 0
fi
if [ -f /tmp/pending_config_initialization ] && [ "$enabled" != "true" ]; then
copy_default_minigraph
reload_minigraph
sonic-cfggen -d --print-data > /etc/sonic/config_db.json
rm -f /tmp/pending_config_initialization
exit 0
fi
if [ "$enabled" = "reload_only" ]; then
reload_minigraph
sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf
exit 0
fi
if [ "$enabled" != "true" ]; then if [ "$enabled" != "true" ]; then
echo "Disabled in updategraph.conf. Skipping graph update." echo "Disabled in updategraph.conf. Skipping graph update."
exit 0 exit 0
@ -38,7 +112,9 @@ if [ "$src" = "dhcp" ]; then
else else
cp -f /tmp/device_meta.json /etc/sonic/config_db.json cp -f /tmp/device_meta.json /etc/sonic/config_db.json
fi fi
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
if [ "$dhcp_as_static" = "true" ]; then if [ "$dhcp_as_static" = "true" ]; then
sed -i "/enabled=/d" /etc/sonic/updategraph.conf sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf echo "enabled=false" >> /etc/sonic/updategraph.conf
@ -86,17 +162,6 @@ while true; do
sleep 5 sleep 5
done done
echo "Regenerating config DB from minigraph..."
if [ -f /etc/sonic/init_cfg.json ]; then
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
else
sonic-cfggen -H -m --print-data > /etc/sonic/config_db.json
fi
# Mark as disabled after graph is successfully downloaded
sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf
if [ -n "$ACL_URL" ]; then if [ -n "$ACL_URL" ]; then
if [ -f /etc/sonic/acl.json ]; then if [ -f /etc/sonic/acl.json ]; then
echo "Renaming acl.json to acl.json.old" echo "Renaming acl.json to acl.json.old"
@ -111,3 +176,11 @@ if [ -n "$ACL_URL" ]; then
else else
echo "Skip ACL config download." echo "Skip ACL config download."
fi fi
reload_minigraph
sonic-cfggen -d --print-data > /etc/sonic/config_db.json
# Mark as disabled after graph is successfully downloaded
sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf

View File

@ -1,7 +1,8 @@
[Unit] [Unit]
Description=download minigraph from graph service Description=Update minigraph and set configuration based on minigraph
After=rc-local.service After=rc-local.service
Before=database.service After=database.service
Requires=database.service
[Service] [Service]
Type=oneshot Type=oneshot