From 128d31a479a7fff126810c5f19eb1fb03be18eec Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 10 Feb 2017 01:28:16 +0000 Subject: [PATCH 01/11] Add a service to fetch minigraph automatically --- build_debian.sh | 6 ++++- .../build_templates/sonic_debian_extension.j2 | 8 ++++++ files/dhcp/dhclient.conf | 24 +++++++++++++++++ files/dhcp/graphserviceurl | 11 ++++++++ files/dhcp/sethostname | 15 +++++------ files/dhcp/snmpcommunity | 11 ++++++++ files/image_config/get_graph/get_graph | 26 +++++++++++++++++++ .../image_config/get_graph/get_graph.service | 12 +++++++++ files/image_config/interfaces/init_interfaces | 11 ++++++++ .../interfaces/interfaces-config.service | 2 +- .../interfaces/interfaces-config.sh | 3 +++ 11 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 files/dhcp/dhclient.conf create mode 100644 files/dhcp/graphserviceurl create mode 100644 files/dhcp/snmpcommunity create mode 100755 files/image_config/get_graph/get_graph create mode 100644 files/image_config/get_graph/get_graph.service create mode 100644 files/image_config/interfaces/init_interfaces diff --git a/build_debian.sh b/build_debian.sh index 76cd4467ce10..75b903ca760d 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -188,7 +188,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in usbutils \ pciutils \ iptables-persistent \ - logrotate + logrotate \ + wget ## Remove sshd host keys, and will regenerate on first sshd start sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key* @@ -241,6 +242,9 @@ EOF sudo cp files/dhcp/rfc3442-classless-routes $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d sudo cp files/dhcp/sethostname $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ +sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ +sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ +sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ if [ -f sonic_debian_extension.sh ]; then ./sonic_debian_extension.sh $FILESYSTEM_ROOT diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index be7f338dae81..092877038bbb 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -81,6 +81,14 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable interfaces-config.service sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/etc/sonic/templates/ +# Copy initial interfaces configuration file, will be overwritten on first boot +sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network + +# Copy get graph script and service file +sudo cp $IMAGE_CONFIGS/get_graph/get_graph.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable get_graph.service +sudo cp $IMAGE_CONFIGS/get_graph/get_gragh $FILESYSTEM_ROOT/usr/bin/ + # Copy SNMP configuration files sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/ diff --git a/files/dhcp/dhclient.conf b/files/dhcp/dhclient.conf new file mode 100644 index 000000000000..5f7ea819e465 --- /dev/null +++ b/files/dhcp/dhclient.conf @@ -0,0 +1,24 @@ +# Configuration file for /sbin/dhclient, which is included in Debian's +# dhcp3-client package. +# +# This is a sample configuration file for dhclient. See dhclient.conf's +# man page for more information about the syntax of this file +# and a more comprehensive list of the parameters understood by +# dhclient. +# +# Normally, if the DHCP server provides reasonable information and does +# not leave anything out (like the domain name, for example), then +# few changes must be made to this file, if any. +# + +option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; +option snmp-community code 224 = text; +option minigraph-service-url code 225 = text; + +send host-name = gethostname(); +request subnet-mask, broadcast-address, time-offset, routers, + domain-name, domain-name-servers, domain-search, host-name, + dhcp6.name-servers, dhcp6.domain-search, + netbios-name-servers, netbios-scope, interface-mtu, + rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-service-url; + diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl new file mode 100644 index 000000000000..c466087217ae --- /dev/null +++ b/files/dhcp/graphserviceurl @@ -0,0 +1,11 @@ +case $reason in + BOUND|RENEW|REBIND|REBOOT) + if [ -n "${new_minigraph_service_url}" ]; then + echo $new_minigraph_service_url > /etc/sonic/graph_service_url + else + if [ !-f "/etc/sonic/graph_service_url"]; then + echo "N/A" > /etc/sonic/graph_service_url + fi + fi + ;; +esac diff --git a/files/dhcp/sethostname b/files/dhcp/sethostname index 81bd458935fc..d0e508e62d2e 100644 --- a/files/dhcp/sethostname +++ b/files/dhcp/sethostname @@ -1,20 +1,19 @@ #!/bin/bash -# This script is to update hostname of the system. -if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \ - && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ] +if [ "$reason" = BOUND ] && ["$reason" != RENEW ] \ + && ["$reason" != REBIND ] && ["$reason" != REBOOT ] then exit 0 fi current_host_name=`hostname -s` -if [ "$current_host_name" != "$new_host_name" ] +if [ "$current_host_name" != "$new_host_name" ] && [ ! -z "$new_host_name" ] then echo $new_host_name > /etc/hostname - line_to_replace=`grep 127.0.0.1.*$current_host_name /etc/hosts` - new_line=`echo $line_to_replace | sed "s/$current_host_name/$new_host_name/"` - sed -i "s/$line_to_replace/$new_line/" /etc/hosts - hostname -F /etc/hostname + sed -i "/\s$current_host_name$/d" /etc/hosts + echo "127.0.0.1 $new_host_name" >> /etc/hosts fi + + diff --git a/files/dhcp/snmpcommunity b/files/dhcp/snmpcommunity new file mode 100644 index 000000000000..63924e01fc5f --- /dev/null +++ b/files/dhcp/snmpcommunity @@ -0,0 +1,11 @@ +case $reason in + BOUND|RENEW|REBIND|REBOOT) + if [ -n "${new_snmp_community}" ]; then + if [ -f /etc/sonic/snmp.yml ]; then + sed -i "s/^snmp_rocommunity:.*/snmp_rocommunity: $new_snmp_community/g" /etc/sonic/snmp.yml + else + echo "snmp_rocommunity: "$new_snmp_community > /etc/sonic/snmp.yml + fi + fi + ;; +esac diff --git a/files/image_config/get_graph/get_graph b/files/image_config/get_graph/get_graph new file mode 100755 index 000000000000..e1cb1d16d3b2 --- /dev/null +++ b/files/image_config/get_graph/get_graph @@ -0,0 +1,26 @@ +#!/bin/bash + +while [ ! -f /etc/sonic/graph_service_url ]; do + echo "No graph service url speficied, waiting for DHCP response..." + sleep 1 +done + +if [ `cat /etc/sonic/graph_service_url` = "N/A" ]; then + echo "Graph service url not included in DHCP response, skip minigraph downloading" + exit 0 +fi + +if [ -f /etc/sonic/minigraph.xml ]; then + echo "Renaming minigraph.xml to minigraph.old" + rm -rf /etc/sonic/minigraph.old + mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.old +fi + +HOSTNAME=`hostname -s` +GRAPH_URL=`sed "s/{{\s*hostname\s*}}/$HOSTNAME/g" /etc/sonic/graph_service_url` +echo "Getting minigraph from $GRAPH_URL" + +while true; do + wget -T 15 -c $GRAPH_URL -O /etc/sonic/minigraph.xml && break + sleep 5 +done diff --git a/files/image_config/get_graph/get_graph.service b/files/image_config/get_graph/get_graph.service new file mode 100644 index 000000000000..eb7f60651d48 --- /dev/null +++ b/files/image_config/get_graph/get_graph.service @@ -0,0 +1,12 @@ +[Unit] +Description=get minigraph +Before=ntp-config.service +Before=rsyslog-config.service +Before=interfaces-config.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/get_graph + +[Install] +WantedBy=multi-user.target diff --git a/files/image_config/interfaces/init_interfaces b/files/image_config/interfaces/init_interfaces new file mode 100644 index 000000000000..b13a36df47f8 --- /dev/null +++ b/files/image_config/interfaces/init_interfaces @@ -0,0 +1,11 @@ +# Initial /etc/network/interface file for first boot +# Will be overwritten based on minigraph information by interfaces-config service + +# The loopback network interface +auto lo +iface lo inet loopback +# +# The management network interface +auto eth0 +iface eth0 inet dhcp + diff --git a/files/image_config/interfaces/interfaces-config.service b/files/image_config/interfaces/interfaces-config.service index 48d6ede42557..92a82aeee0b8 100644 --- a/files/image_config/interfaces/interfaces-config.service +++ b/files/image_config/interfaces/interfaces-config.service @@ -1,6 +1,6 @@ [Unit] Description=Update interfaces configuration -Before=network.target +Before=database.service [Service] Type=oneshot diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index 69d72e916477..286c94796952 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -3,3 +3,6 @@ sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/interfaces.j2 >/etc/network/interfaces sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/vlan_interfaces.j2 >/etc/network/interfaces.d/vlan_interfaces sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/lag_interfaces.j2 >/etc/network/interfaces.d/lag_interfaces +ifdown eth0 && ifup eth0 +ifdown lo && ifup lo + From 967806239e234f353beb1cc9126b12c56e79347c Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 10 Feb 2017 04:29:25 +0000 Subject: [PATCH 02/11] Fix typo --- files/build_templates/sonic_debian_extension.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 092877038bbb..6f6de7c0aef9 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -87,7 +87,7 @@ sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network # Copy get graph script and service file sudo cp $IMAGE_CONFIGS/get_graph/get_graph.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable get_graph.service -sudo cp $IMAGE_CONFIGS/get_graph/get_gragh $FILESYSTEM_ROOT/usr/bin/ +sudo cp $IMAGE_CONFIGS/get_graph/get_graph $FILESYSTEM_ROOT/usr/bin/ # Copy SNMP configuration files sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/ From 71dfb9821da4c808d5cb3d25c2969b7d8b59c4db Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 10 Feb 2017 22:06:32 +0000 Subject: [PATCH 03/11] Add config option to disable DHCP graph service --- files/build_templates/sonic_debian_extension.j2 | 3 +++ files/dhcp/graphserviceurl | 2 +- files/image_config/get_graph/get_graph | 2 +- rules/config | 7 +++++++ slave.mk | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 6f6de7c0aef9..b9dbf167b419 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -88,6 +88,9 @@ sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network sudo cp $IMAGE_CONFIGS/get_graph/get_graph.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable get_graph.service sudo cp $IMAGE_CONFIGS/get_graph/get_graph $FILESYSTEM_ROOT/usr/bin/ +{% if enable_dhcp_graph_service != "y" %} +sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/graph_service_url" +{% endif %} # Copy SNMP configuration files sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/ diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl index c466087217ae..cbcd15ef1784 100644 --- a/files/dhcp/graphserviceurl +++ b/files/dhcp/graphserviceurl @@ -4,7 +4,7 @@ case $reason in echo $new_minigraph_service_url > /etc/sonic/graph_service_url else if [ !-f "/etc/sonic/graph_service_url"]; then - echo "N/A" > /etc/sonic/graph_service_url + echo "disabled" > /etc/sonic/graph_service_url fi fi ;; diff --git a/files/image_config/get_graph/get_graph b/files/image_config/get_graph/get_graph index e1cb1d16d3b2..3cf79f0f4f94 100755 --- a/files/image_config/get_graph/get_graph +++ b/files/image_config/get_graph/get_graph @@ -5,7 +5,7 @@ while [ ! -f /etc/sonic/graph_service_url ]; do sleep 1 done -if [ `cat /etc/sonic/graph_service_url` = "N/A" ]; then +if [ `cat /etc/sonic/graph_service_url` = "disabled" ]; then echo "Graph service url not included in DHCP response, skip minigraph downloading" exit 0 fi diff --git a/rules/config b/rules/config index d76477ce5adc..4f2cc261c952 100644 --- a/rules/config +++ b/rules/config @@ -31,3 +31,10 @@ USERNAME = admin # PASSWORD - password for installer build PASSWORD = YourPaSsWoRd + +# ENABLE_DHCP_GRAPH_SERVICE - specify the source of minigraph to generate configuration file. +# If set to y SONiC will get the minigraph from graph service. Graph service URL need to be +# passed through DHCP option 225. +# If not set (default behavior) the default minigraph built into the image will be used. +# ENABLE_DHCP_GRAPH_SERVICE = y + diff --git a/slave.mk b/slave.mk index a13178bb58e3..736e9cec112a 100644 --- a/slave.mk +++ b/slave.mk @@ -297,6 +297,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform export image_type="$($*_IMAGE_TYPE)" export sonicadmin_user="$(USERNAME)" export sonic_hwsku="$(CONFIGURED_SKU)" + export enable_dhcp_graph_service="$(ENABLE_DHCP_GRAPH_SERVICE)" $(foreach docker, $($*_DOCKERS),\ export docker_image="$(docker)" export docker_image_name="$(basename $(docker))" From 64942c8297c60b1e40cbe29f96cf0efc441382a3 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 10 Feb 2017 22:58:40 +0000 Subject: [PATCH 04/11] Modify get_graph service according to CR --- files/build_templates/sonic_debian_extension.j2 | 2 +- files/image_config/get_graph/get_graph.service | 4 ++-- files/image_config/get_graph/{get_graph => updategraph} | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) rename files/image_config/get_graph/{get_graph => updategraph} (95%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index b9dbf167b419..b74b0b49fab2 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -87,7 +87,7 @@ sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network # Copy get graph script and service file sudo cp $IMAGE_CONFIGS/get_graph/get_graph.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable get_graph.service -sudo cp $IMAGE_CONFIGS/get_graph/get_graph $FILESYSTEM_ROOT/usr/bin/ +sudo cp $IMAGE_CONFIGS/get_graph/updategraph $FILESYSTEM_ROOT/usr/bin/ {% if enable_dhcp_graph_service != "y" %} sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/graph_service_url" {% endif %} diff --git a/files/image_config/get_graph/get_graph.service b/files/image_config/get_graph/get_graph.service index eb7f60651d48..ba0b5dcb85e2 100644 --- a/files/image_config/get_graph/get_graph.service +++ b/files/image_config/get_graph/get_graph.service @@ -1,12 +1,12 @@ [Unit] -Description=get minigraph +Description=download minigraph from graph service Before=ntp-config.service Before=rsyslog-config.service Before=interfaces-config.service [Service] Type=oneshot -ExecStart=/usr/bin/get_graph +ExecStart=/usr/bin/updategraph [Install] WantedBy=multi-user.target diff --git a/files/image_config/get_graph/get_graph b/files/image_config/get_graph/updategraph similarity index 95% rename from files/image_config/get_graph/get_graph rename to files/image_config/get_graph/updategraph index 3cf79f0f4f94..1324567e0dd3 100755 --- a/files/image_config/get_graph/get_graph +++ b/files/image_config/get_graph/updategraph @@ -12,7 +12,6 @@ fi if [ -f /etc/sonic/minigraph.xml ]; then echo "Renaming minigraph.xml to minigraph.old" - rm -rf /etc/sonic/minigraph.old mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.old fi From 4c4b8e7bbe0ff035ebbf746da2aca64e0b6110db Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 10 Feb 2017 23:30:37 +0000 Subject: [PATCH 05/11] Use curl instead of wget --- build_debian.sh | 2 +- files/image_config/get_graph/updategraph | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index b4f3d73a0857..2d6cc35533f6 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -189,7 +189,7 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in pciutils \ iptables-persistent \ logrotate \ - wget + curl ## Remove sshd host keys, and will regenerate on first sshd start sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key* diff --git a/files/image_config/get_graph/updategraph b/files/image_config/get_graph/updategraph index 1324567e0dd3..cc28833286f3 100755 --- a/files/image_config/get_graph/updategraph +++ b/files/image_config/get_graph/updategraph @@ -20,6 +20,6 @@ GRAPH_URL=`sed "s/{{\s*hostname\s*}}/$HOSTNAME/g" /etc/sonic/graph_service_url` echo "Getting minigraph from $GRAPH_URL" while true; do - wget -T 15 -c $GRAPH_URL -O /etc/sonic/minigraph.xml && break + curl -f $GRAPH_URL -o /etc/sonic/minigraph.xml --connect-timeout 15 && break sleep 5 done From e79ea209949603f36af15b4dbcb1adbb395fb1a7 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Sat, 11 Feb 2017 00:28:59 +0000 Subject: [PATCH 06/11] Ignore DHCP message when graph_service_url file already exists --- files/dhcp/graphserviceurl | 8 ++++---- files/dhcp/sethostname | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl index cbcd15ef1784..00fa11e1206f 100644 --- a/files/dhcp/graphserviceurl +++ b/files/dhcp/graphserviceurl @@ -1,11 +1,11 @@ case $reason in BOUND|RENEW|REBIND|REBOOT) - if [ -n "${new_minigraph_service_url}" ]; then + if [ -f "/etc/sonic/graph_service_url" ] && [ -n `cat /etc/sonic/graph_service_url` ]; then + exit 0 + elif [ -n "$new_minigraph_service_url" ]; then echo $new_minigraph_service_url > /etc/sonic/graph_service_url else - if [ !-f "/etc/sonic/graph_service_url"]; then - echo "disabled" > /etc/sonic/graph_service_url - fi + echo "disabled" > /etc/sonic/graph_service_url fi ;; esac diff --git a/files/dhcp/sethostname b/files/dhcp/sethostname index d0e508e62d2e..ee817b90a753 100644 --- a/files/dhcp/sethostname +++ b/files/dhcp/sethostname @@ -1,19 +1,13 @@ -#!/bin/bash - -if [ "$reason" = BOUND ] && ["$reason" != RENEW ] \ - && ["$reason" != REBIND ] && ["$reason" != REBOOT ] -then - exit 0 -fi - -current_host_name=`hostname -s` - -if [ "$current_host_name" != "$new_host_name" ] && [ ! -z "$new_host_name" ] -then - echo $new_host_name > /etc/hostname - hostname -F /etc/hostname - sed -i "/\s$current_host_name$/d" /etc/hosts - echo "127.0.0.1 $new_host_name" >> /etc/hosts -fi - +case $reason in + BOUND|RENEW|REBIND|REBOOT) + current_host_name=`hostname -s` + if [ "$current_host_name" != "$new_host_name" ] && [ -n "$new_host_name" ] + then + echo $new_host_name > /etc/hostname + hostname -F /etc/hostname + sed -i "/\s$current_host_name$/d" /etc/hosts + echo "127.0.0.1 $new_host_name" >> /etc/hosts + fi + ;; +esac From aad5f39fe2ac7f6803cb01adf5b603ab165c8868 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 15 Feb 2017 03:36:16 +0000 Subject: [PATCH 07/11] Update according to CR comments --- files/build_templates/sonic_debian_extension.j2 | 8 ++++---- files/dhcp/dhclient.conf | 4 ++-- files/dhcp/sethostname | 2 +- files/image_config/{get_graph => updategraph}/updategraph | 0 .../get_graph.service => updategraph/updategraph.service} | 0 5 files changed, 7 insertions(+), 7 deletions(-) rename files/image_config/{get_graph => updategraph}/updategraph (100%) rename files/image_config/{get_graph/get_graph.service => updategraph/updategraph.service} (100%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 83802648dae7..f8739bb38019 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -84,10 +84,10 @@ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/etc/sonic/templates/ # Copy initial interfaces configuration file, will be overwritten on first boot sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network -# Copy get graph script and service file -sudo cp $IMAGE_CONFIGS/get_graph/get_graph.service $FILESYSTEM_ROOT/etc/systemd/system/ -sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable get_graph.service -sudo cp $IMAGE_CONFIGS/get_graph/updategraph $FILESYSTEM_ROOT/usr/bin/ +# Copy updategraph script and service file +sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service +sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ {% if enable_dhcp_graph_service != "y" %} sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/graph_service_url" {% endif %} diff --git a/files/dhcp/dhclient.conf b/files/dhcp/dhclient.conf index 5f7ea819e465..ce4ac4d9f445 100644 --- a/files/dhcp/dhclient.conf +++ b/files/dhcp/dhclient.conf @@ -13,12 +13,12 @@ option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; option snmp-community code 224 = text; -option minigraph-service-url code 225 = text; +option minigraph-url code 225 = text; send host-name = gethostname(); request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, domain-search, host-name, dhcp6.name-servers, dhcp6.domain-search, netbios-name-servers, netbios-scope, interface-mtu, - rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-service-url; + rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-url; diff --git a/files/dhcp/sethostname b/files/dhcp/sethostname index ee817b90a753..57f96ce63612 100644 --- a/files/dhcp/sethostname +++ b/files/dhcp/sethostname @@ -6,7 +6,7 @@ case $reason in echo $new_host_name > /etc/hostname hostname -F /etc/hostname sed -i "/\s$current_host_name$/d" /etc/hosts - echo "127.0.0.1 $new_host_name" >> /etc/hosts + echo "127.0.0.1 $new_host_name" >> /etc/hosts fi ;; esac diff --git a/files/image_config/get_graph/updategraph b/files/image_config/updategraph/updategraph similarity index 100% rename from files/image_config/get_graph/updategraph rename to files/image_config/updategraph/updategraph diff --git a/files/image_config/get_graph/get_graph.service b/files/image_config/updategraph/updategraph.service similarity index 100% rename from files/image_config/get_graph/get_graph.service rename to files/image_config/updategraph/updategraph.service From 3a972f6b962bde78a97c633c71e6fbef9e7e9b0e Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 15 Feb 2017 03:41:32 +0000 Subject: [PATCH 08/11] Use config-engine instead of sed for graph url render --- files/image_config/updategraph/updategraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index cc28833286f3..4c537d302d77 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -16,7 +16,7 @@ if [ -f /etc/sonic/minigraph.xml ]; then fi HOSTNAME=`hostname -s` -GRAPH_URL=`sed "s/{{\s*hostname\s*}}/$HOSTNAME/g" /etc/sonic/graph_service_url` +GRAPH_URL=`sonic-cfggen -t /etc/sonic/graph_service_url -a "{\"hostname\": \"$HOSTNAME\"}"` echo "Getting minigraph from $GRAPH_URL" while true; do From 02d8676a2ea11fc1c29013320df6ca262f4a92e4 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 15 Feb 2017 03:46:53 +0000 Subject: [PATCH 09/11] Rename graph_service_url to updategraph.conf and fix a bug introduced in previous commit --- files/build_templates/sonic_debian_extension.j2 | 2 +- files/dhcp/graphserviceurl | 8 ++++---- files/image_config/updategraph/updategraph | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index f8739bb38019..4f98a903cad3 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -89,7 +89,7 @@ sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/sys sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ {% if enable_dhcp_graph_service != "y" %} -sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/graph_service_url" +sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" {% endif %} # Copy SNMP configuration files diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl index 00fa11e1206f..768f658ff191 100644 --- a/files/dhcp/graphserviceurl +++ b/files/dhcp/graphserviceurl @@ -1,11 +1,11 @@ case $reason in BOUND|RENEW|REBIND|REBOOT) - if [ -f "/etc/sonic/graph_service_url" ] && [ -n `cat /etc/sonic/graph_service_url` ]; then + if [ -f "/etc/sonic/updategraph.conf" ] && [ -n `cat /etc/sonic/updategraph.conf` ]; then exit 0 - elif [ -n "$new_minigraph_service_url" ]; then - echo $new_minigraph_service_url > /etc/sonic/graph_service_url + elif [ -n "$new_minigraph_url" ]; then + echo $new_minigraph_url > /etc/sonic/updategraph.conf else - echo "disabled" > /etc/sonic/graph_service_url + echo "disabled" > /etc/sonic/updategraph.conf fi ;; esac diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 4c537d302d77..347539f5be6e 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -1,11 +1,11 @@ #!/bin/bash -while [ ! -f /etc/sonic/graph_service_url ]; do +while [ ! -f /etc/sonic/updategraph.conf ]; do echo "No graph service url speficied, waiting for DHCP response..." sleep 1 done -if [ `cat /etc/sonic/graph_service_url` = "disabled" ]; then +if [ `cat /etc/sonic/updategraph.conf` = "disabled" ]; then echo "Graph service url not included in DHCP response, skip minigraph downloading" exit 0 fi @@ -16,7 +16,7 @@ if [ -f /etc/sonic/minigraph.xml ]; then fi HOSTNAME=`hostname -s` -GRAPH_URL=`sonic-cfggen -t /etc/sonic/graph_service_url -a "{\"hostname\": \"$HOSTNAME\"}"` +GRAPH_URL=`sonic-cfggen -t /etc/sonic/updategraph.conf -a "{\"hostname\": \"$HOSTNAME\"}"` echo "Getting minigraph from $GRAPH_URL" while true; do From 33277c409bc4369f04a238363d2fab41765ffc6d Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 17 Feb 2017 01:28:40 +0000 Subject: [PATCH 10/11] Change updategraph.conf schema for extensibility --- .../build_templates/sonic_debian_extension.j2 | 8 +++- files/dhcp/graphserviceurl | 8 ++-- files/image_config/updategraph/updategraph | 41 +++++++++++++++---- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 4f98a903cad3..b79016dbf3bc 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -88,8 +88,12 @@ sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ -{% if enable_dhcp_graph_service != "y" %} -sudo bash -c "echo disabled > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" +{% if enable_dhcp_graph_service == "y" %} +sudo bash -c "echo enabled=true > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" +sudo bash -c "echo src=dhcp >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" +sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" +{% else %} +sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" {% endif %} # Copy SNMP configuration files diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl index 768f658ff191..0e8b1b83e141 100644 --- a/files/dhcp/graphserviceurl +++ b/files/dhcp/graphserviceurl @@ -1,11 +1,9 @@ case $reason in BOUND|RENEW|REBIND|REBOOT) - if [ -f "/etc/sonic/updategraph.conf" ] && [ -n `cat /etc/sonic/updategraph.conf` ]; then - exit 0 - elif [ -n "$new_minigraph_url" ]; then - echo $new_minigraph_url > /etc/sonic/updategraph.conf + if [ -n "$new_minigraph_url" ]; then + echo $new_minigraph_url > /tmp/dhcp_graph_url else - echo "disabled" > /etc/sonic/updategraph.conf + echo "N/A" > /tmp/dhcp_graph_url fi ;; esac diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 347539f5be6e..8f2b4294a03c 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -1,22 +1,47 @@ #!/bin/bash -while [ ! -f /etc/sonic/updategraph.conf ]; do - echo "No graph service url speficied, waiting for DHCP response..." - sleep 1 -done +if [ ! -f /etc/sonic/updategraph.conf ]; then + echo "No updategraph.conf found, generating a default one." + echo "enabled=false" >/etc/sonic/updategraph.conf +fi -if [ `cat /etc/sonic/updategraph.conf` = "disabled" ]; then - echo "Graph service url not included in DHCP response, skip minigraph downloading" +. <(grep "=" /etc/sonic/updategraph.conf) + +if [ "$enabled" != "true" ]; then + echo "Disabled in updategraph.conf. Skipping graph update." exit 0 fi +if [ "$src" = "dhcp" ]; then + while [ ! -f /tmp/dhcp_graph_url ]; do + echo "Waiting for DHCP response..." + sleep 1 + done + + if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then + echo "No graph_url option in DHCP response. Skipping graph update." + if [ "$dhcp_as_static" = "true" ]; then + sed -i "/enabled=/d" /etc/sonic/updategraph.conf + echo "enabled=false" >> /etc/sonic/updategraph.conf + fi + exit 0 + fi + + HOSTNAME=`hostname -s` + GRAPH_URL=`sonic-cfggen -t /tmp/dhcp_graph_url -a "{\"hostname\": \"$HOSTNAME\"}"` + if [ "$dhcp_as_static" = "true" ]; then + sed -i "/src=d/d" /etc/sonic/updategraph.conf + echo "src=$GRAPH_URL" >> /etc/sonic/updategraph.conf + fi +else + GRAPH_URL=$src +fi + if [ -f /etc/sonic/minigraph.xml ]; then echo "Renaming minigraph.xml to minigraph.old" mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.old fi -HOSTNAME=`hostname -s` -GRAPH_URL=`sonic-cfggen -t /etc/sonic/updategraph.conf -a "{\"hostname\": \"$HOSTNAME\"}"` echo "Getting minigraph from $GRAPH_URL" while true; do From fb0c25cf5718971d8fac5e0c89a29396f9bd9c78 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 17 Feb 2017 18:45:50 +0000 Subject: [PATCH 11/11] Modification according to PR comments --- files/image_config/updategraph/updategraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 8f2b4294a03c..203905b85c7c 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -5,7 +5,7 @@ if [ ! -f /etc/sonic/updategraph.conf ]; then echo "enabled=false" >/etc/sonic/updategraph.conf fi -. <(grep "=" /etc/sonic/updategraph.conf) +. /etc/sonic/updategraph.conf if [ "$enabled" != "true" ]; then echo "Disabled in updategraph.conf. Skipping graph update."