From 391e44c15fbc06a14cfc9e832fca235972e67e8a Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Fri, 31 Jan 2020 15:52:08 -0800 Subject: [PATCH 1/7] [init_cfg.json] Create a separete init_cfg.json.j2 file and initialize this file using the content from sonic_debian_extension.j2. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 5 +++++ files/build_templates/sonic_debian_extension.j2 | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 files/build_templates/init_cfg.json.j2 diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 new file mode 100644 index 000000000000..30e29dea5a08 --- /dev/null +++ b/files/build_templates/init_cfg.json.j2 @@ -0,0 +1,5 @@ + {"DEVICE_METADATA": { "localhost": { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} } }, +{%- print ' "CRM": { "Config": { "polling_interval": "300", ' %} +{%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] -%} +"{{crm_res}}_threshold_type": "percentage", "{{crm_res}}_low_threshold": "70", "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif %} +{%- endfor %} } } } diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index bdcb415839d4..d88708b90da8 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -254,6 +254,7 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/misc/docker-wait-any $FILESYSTEM_ROOT/usr/bin/ # Copy updategraph script and service file +j2 files/build_templates/init_cfg.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/init_cfg.json j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ echo "updategraph.service" | sudo tee -a $GENERATED_SERVICE_FILE @@ -264,11 +265,6 @@ sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph {% else %} sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" {% endif %} -sudo bash -c "echo '{ \"DEVICE_METADATA\": { \"localhost\": { \"default_bgp_status\": {% if shutdown_bgp_on_start == "y" %}\"down\"{% else %}\"up\"{% endif %}, \"default_pfcwd_status\": {% if enable_pfcwd_on_start == "y" %}\"enable\"{% else %}\"disable\"{% endif %} } }, -{%- print ' \\"CRM\\": { \\"Config\\": { \\"polling_interval\\": \\"300\\", ' %} -{%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] -%} -\"{{crm_res}}_threshold_type\": \"percentage\", \"{{crm_res}}_low_threshold\": \"70\", \"{{crm_res}}_high_threshold\": \"85\"{% if not loop.last %}, {% endif %} -{%- endfor %} } } }' >> $FILESYSTEM_ROOT/etc/sonic/init_cfg.json" # Copy config-setup script and service file j2 files/build_templates/config-setup.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/config-setup.service From 95d222caf2a32c051d84fed64bf579bbc2f5b79f Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Sun, 2 Feb 2020 10:50:40 -0800 Subject: [PATCH 2/7] [init_cfg.json] Reorganize the template file and move the command to generate init_cfg.json to line 269 in sonic_debian_extension.j2. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 23 +++++++++++++++---- .../build_templates/sonic_debian_extension.j2 | 4 +++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index 30e29dea5a08..e0f68bf938dd 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -1,5 +1,18 @@ - {"DEVICE_METADATA": { "localhost": { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} } }, -{%- print ' "CRM": { "Config": { "polling_interval": "300", ' %} -{%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] -%} -"{{crm_res}}_threshold_type": "percentage", "{{crm_res}}_low_threshold": "70", "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif %} -{%- endfor %} } } } + {"DEVICE_METADATA": + { "localhost": + { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, + "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} + } + }, + {%- print ' "CRM": + { "Config": { "polling_interval": "300", ' %} + {%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", + "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", + "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] -%} + "{{crm_res}}_threshold_type": "percentage", + "{{crm_res}}_low_threshold": "70", + "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif %} + {%- endfor %} + } + } +} diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index d88708b90da8..fb9f36a1c6ac 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -254,7 +254,6 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/misc/docker-wait-any $FILESYSTEM_ROOT/usr/bin/ # Copy updategraph script and service file -j2 files/build_templates/init_cfg.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/init_cfg.json j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ echo "updategraph.service" | sudo tee -a $GENERATED_SERVICE_FILE @@ -266,6 +265,9 @@ sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" {% endif %} +# Generate initial SONiC configureation file +j2 files/build_templates/init_cfg.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/init_cfg.json + # Copy config-setup script and service file j2 files/build_templates/config-setup.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/config-setup.service sudo cp $IMAGE_CONFIGS/config-setup/config-setup $FILESYSTEM_ROOT/usr/bin/config-setup From 9a23e5ed3639f5abb806b26c2dc0d3bf03ef83d9 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Sun, 2 Feb 2020 13:34:04 -0800 Subject: [PATCH 3/7] [init_cfg.json] Corrent a typo and reorganize the init_cfg.json.j2. Signed-off-by: Yong Zhao --- 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 fb9f36a1c6ac..16b7a3b160b5 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -265,7 +265,7 @@ sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" {% endif %} -# Generate initial SONiC configureation file +# Generate initial SONiC configuration file j2 files/build_templates/init_cfg.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/init_cfg.json # Copy config-setup script and service file From c308f1cccb8ab0733b4a9971aa6881b76ac767b0 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Sun, 2 Feb 2020 17:04:30 -0800 Subject: [PATCH 4/7] [init_cfg.json] Remove the tailing extra spaces. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index e0f68bf938dd..7aa7e0a177b8 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -1,18 +1,20 @@ - {"DEVICE_METADATA": - { "localhost": - { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, - "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} - } - }, - {%- print ' "CRM": - { "Config": { "polling_interval": "300", ' %} - {%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", - "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", - "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] -%} - "{{crm_res}}_threshold_type": "percentage", - "{{crm_res}}_low_threshold": "70", - "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif %} - {%- endfor %} + { + "DEVICE_METADATA": { + "localhost": { + "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, + "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} + } + }, + "CRM": { + "Config": { + "polling_interval": "300", +{%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", + "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", + "acl_group", "acl_entry", "acl_counter", "fdb_entry"] %} + "{{crm_res}}_threshold_type": "percentage", + "{{crm_res}}_low_threshold": "70", + "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif -%} +{% endfor %} } } } From 5dd98ef575efb29d47997785f8ec009ee76009d2 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Sun, 2 Feb 2020 17:09:49 -0800 Subject: [PATCH 5/7] [init_cfg.json] Use one indent. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index 7aa7e0a177b8..79b85e38e688 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -1,13 +1,13 @@ { - "DEVICE_METADATA": { - "localhost": { - "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, - "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} - } - }, - "CRM": { - "Config": { - "polling_interval": "300", + "DEVICE_METADATA": { + "localhost": { + "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, + "default_pfcwd_status": {% if enable_pfcwd_on_start == "y" %}"enable"{% else %}"disable"{% endif %} + } + }, + "CRM": { + "Config": { + "polling_interval": "300", {%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry"] %} From e093e6cbc6834c32af160bab177af521a402b2a5 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 10:38:33 -0800 Subject: [PATCH 6/7] [init_cfg.json] Delete the heading space at line 1. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index 79b85e38e688..85586cf3dc8d 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -1,4 +1,4 @@ - { +{ "DEVICE_METADATA": { "localhost": { "default_bgp_status": {% if shutdown_bgp_on_start == "y" %}"down"{% else %}"up"{% endif %}, From 7a84818409e79243382d2e8f4b83a0ca65fff184 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 10:41:56 -0800 Subject: [PATCH 7/7] [init_cfg.json] Delete a extra space in line 16 between brace. Signed-off-by: Yong Zhao --- files/build_templates/init_cfg.json.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index 85586cf3dc8d..33cfe990f900 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -13,7 +13,7 @@ "acl_group", "acl_entry", "acl_counter", "fdb_entry"] %} "{{crm_res}}_threshold_type": "percentage", "{{crm_res}}_low_threshold": "70", - "{{crm_res}}_high_threshold": "85"{% if not loop.last %}, {% endif -%} + "{{crm_res}}_high_threshold": "85"{% if not loop.last %},{% endif -%} {% endfor %} } }