From 7b06d9b982188ca3ea3ac78be91af8ecc4e64c54 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Wed, 11 Oct 2023 19:14:00 +0300 Subject: [PATCH 1/6] [hostcfgd] Fix issue: FeatureHandler might override user configuration (#16766) Signed-off-by: Nazarii Hnydyn --- src/sonic-host-services/scripts/hostcfgd | 35 +++++++++-- .../tests/hostcfgd/hostcfgd_test.py | 61 +++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/sonic-host-services/scripts/hostcfgd b/src/sonic-host-services/scripts/hostcfgd index 461c1b5b8b5a..3c06bd7ba4f4 100755 --- a/src/sonic-host-services/scripts/hostcfgd +++ b/src/sonic-host-services/scripts/hostcfgd @@ -352,7 +352,7 @@ class FeatureHandler(object): # sync has_per_asic_scope to CONFIG_DB in namespaces in multi-asic platform for ns, db in self.ns_cfg_db.items(): db.mod_entry('FEATURE', feature_config.name, {'has_per_asic_scope': str(feature_config.has_per_asic_scope)}) - + def update_systemd_config(self, feature_config): """Updates `Restart=` field in feature's systemd configuration file according to the value of `auto_restart` field in `FEATURE` table of `CONFIG_DB`. @@ -427,7 +427,7 @@ class FeatureHandler(object): unit_file_state = self.get_systemd_unit_state("{}.{}".format(feature_name, feature_suffixes[-1])) if unit_file_state == "enabled" or not unit_file_state: continue - cmds = [] + cmds = [] for suffix in feature_suffixes: cmds.append("sudo systemctl unmask {}.{}".format(feature_name, suffix)) @@ -474,11 +474,28 @@ class FeatureHandler(object): self.set_feature_state(feature, self.FEATURE_STATE_DISABLED) def resync_feature_state(self, feature): - self._config_db.mod_entry('FEATURE', feature.name, {'state': feature.state}) + current_entry = self._config_db.get_entry('FEATURE', feature.name) + current_feature_state = current_entry.get('state') if current_entry else None - # resync the feature state to CONFIG_DB in namespaces in multi-asic platform - for ns, db in self.ns_cfg_db.items(): - db.mod_entry('FEATURE', feature.name, {'state': feature.state}) + if feature.state == current_feature_state: + return + + # feature.state might be rendered from a template, so that it should resync CONFIG DB + # FEATURE table to override the template value to valid state value + # ('always_enabled', 'always_disabled', 'disabled', 'enabled'). However, we should only + # resync feature state in two cases: + # 1. the rendered feature state is always_enabled or always_disabled, it means that the + # feature state is immutable and potential state change during HostConfigDaemon.load + # in redis should be skipped; + # 2. the current feature state in DB is a template which should be replaced by rendered feature + # state + # For other cases, we should not resync feature.state to CONFIG DB to avoid overriding user configuration. + if self._feature_state_is_immutable(feature.state) or self._feature_state_is_template(current_feature_state): + self._config_db.mod_entry('FEATURE', feature.name, {'state': feature.state}) + + # resync the feature state to CONFIG_DB in namespaces in multi-asic platform + for ns, db in self.ns_cfg_db.items(): + db.mod_entry('FEATURE', feature.name, {'state': feature.state}) def set_feature_state(self, feature, state): self._feature_state_table.set(feature.name, [('state', state)]) @@ -487,6 +504,12 @@ class FeatureHandler(object): for ns, tbl in self.ns_feature_state_tbl.items(): tbl.set(feature.name, [('state', state)]) + def _feature_state_is_template(self, feature_state): + return feature_state not in ('always_enabled', 'always_disabled', 'disabled', 'enabled') + + def _feature_state_is_immutable(self, feature_state): + return feature_state in ('always_enabled', 'always_disabled') + class Iptables(object): def __init__(self): ''' diff --git a/src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py b/src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py index 35e28316290b..16d437de0c2d 100644 --- a/src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py +++ b/src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py @@ -241,6 +241,67 @@ def test_feature_config_parsing_defaults(self): assert swss_feature.has_global_scope assert not swss_feature.has_per_asic_scope + @mock.patch('hostcfgd.FeatureHandler.update_systemd_config', mock.MagicMock()) + @mock.patch('hostcfgd.FeatureHandler.update_feature_state', mock.MagicMock()) + @mock.patch('hostcfgd.FeatureHandler.sync_feature_asic_scope', mock.MagicMock()) + def test_feature_resync(self): + mock_db = mock.MagicMock() + mock_db.get_entry = mock.MagicMock() + mock_db.mod_entry = mock.MagicMock() + mock_feature_state_table = mock.MagicMock() + + feature_handler = hostcfgd.FeatureHandler(mock_db, mock_feature_state_table, {}) + feature_table = { + 'sflow': { + 'state': 'enabled', + 'auto_restart': 'enabled', + 'delayed': 'True', + 'has_global_scope': 'False', + 'has_per_asic_scope': 'True', + } + } + mock_db.get_entry.return_value = None + feature_handler.sync_state_field(feature_table) + mock_db.mod_entry.assert_called_with('FEATURE', 'sflow', {'state': 'enabled'}) + mock_db.mod_entry.reset_mock() + + feature_handler = hostcfgd.FeatureHandler(mock_db, mock_feature_state_table, {}) + mock_db.get_entry.return_value = { + 'state': 'disabled', + } + feature_handler.sync_state_field(feature_table) + mock_db.mod_entry.assert_not_called() + + feature_handler = hostcfgd.FeatureHandler(mock_db, mock_feature_state_table, {}) + feature_table = { + 'sflow': { + 'state': 'always_enabled', + 'auto_restart': 'enabled', + 'delayed': 'True', + 'has_global_scope': 'False', + 'has_per_asic_scope': 'True', + } + } + feature_handler.sync_state_field(feature_table) + mock_db.mod_entry.assert_called_with('FEATURE', 'sflow', {'state': 'always_enabled'}) + mock_db.mod_entry.reset_mock() + + feature_handler = hostcfgd.FeatureHandler(mock_db, mock_feature_state_table, {}) + mock_db.get_entry.return_value = { + 'state': 'some template', + } + feature_table = { + 'sflow': { + 'state': 'enabled', + 'auto_restart': 'enabled', + 'delayed': 'True', + 'has_global_scope': 'False', + 'has_per_asic_scope': 'True', + } + } + feature_handler.sync_state_field(feature_table) + mock_db.mod_entry.assert_called_with('FEATURE', 'sflow', {'state': 'enabled'}) + class TesNtpCfgd(TestCase): """ From 37fe9cc4eb0a5fa3fd03933868d0dc2e9b1f54fe Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:39:57 +0800 Subject: [PATCH 2/6] [submodule] Update submodule sonic-platform-common to the latest HEAD automatically (#16530) src/sonic-platform-common * ade83aa - (HEAD -> 202205, origin/202205) [202205] Fix issue: should use 'Value' column to calculate the health percentage for Virtium SSD (#385) (4 weeks ago) [Junchao-Mellanox] --- src/sonic-platform-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-platform-common b/src/sonic-platform-common index 6a38e71592b6..ade83aad1aa5 160000 --- a/src/sonic-platform-common +++ b/src/sonic-platform-common @@ -1 +1 @@ -Subproject commit 6a38e71592b622dddccdfb5567fbde83cad19e6a +Subproject commit ade83aad1aa5c673ca7d5a00fbf9eca61febebc1 From 87ab7a4e685f6c7f131ad8691045f82b25e70d96 Mon Sep 17 00:00:00 2001 From: Samuel Angebault Date: Wed, 11 Oct 2023 20:55:51 +0200 Subject: [PATCH 3/6] [202205][Arista] Update arista platform submodules (#16561) * [202205][Arista] Update arista platform submodules - fix issue where platform debug info would no longer be in the dump - fix issue in scd-xcvr where active low bits couldn't be set - fix issue in scd-smbus where it perform an oob access --- platform/barefoot/sonic-platform-modules-arista | 2 +- platform/broadcom/sonic-platform-modules-arista | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/barefoot/sonic-platform-modules-arista b/platform/barefoot/sonic-platform-modules-arista index 27e4837c405b..cb3e1e656b99 160000 --- a/platform/barefoot/sonic-platform-modules-arista +++ b/platform/barefoot/sonic-platform-modules-arista @@ -1 +1 @@ -Subproject commit 27e4837c405b52142876b86b6f6d2faf039ae917 +Subproject commit cb3e1e656b993cb699dc8e39b7e668891eea64af diff --git a/platform/broadcom/sonic-platform-modules-arista b/platform/broadcom/sonic-platform-modules-arista index 27e4837c405b..cb3e1e656b99 160000 --- a/platform/broadcom/sonic-platform-modules-arista +++ b/platform/broadcom/sonic-platform-modules-arista @@ -1 +1 @@ -Subproject commit 27e4837c405b52142876b86b6f6d2faf039ae917 +Subproject commit cb3e1e656b993cb699dc8e39b7e668891eea64af From 36cf71f79a5390e6b164f9f992a5198c91e27ad0 Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Thu, 12 Oct 2023 02:56:28 +0800 Subject: [PATCH 4/6] [submodule] Update submodule sonic-swss to the latest HEAD automatically (#16834) src/sonic-swss * 561cfd94 - (HEAD -> 202205, origin/202205) [202205][buffers] Add handler for the 'create_only_config_db_buffers' configuration knob (#2882) (11 hours ago) [Vadym Hlushko] --- src/sonic-swss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-swss b/src/sonic-swss index de7186c60fa3..561cfd94cc87 160000 --- a/src/sonic-swss +++ b/src/sonic-swss @@ -1 +1 @@ -Subproject commit de7186c60fa3176832b71e42e27e7875af6636cc +Subproject commit 561cfd94cc879940e775f3017185376ca74786e2 From 427a3325d16b93317af808a0f99446d9c6894414 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi <50386592+SuvarnaMeenakshi@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:02:33 -0700 Subject: [PATCH 5/6] [202205][SNMP][IPv6]: Revert PRs to support SNMP over IPv6 (#16650) * Revert "[SNMP][IPv6]: Fix to use link local IPv6 address as snmp agentAddress (#16013) (#16102)" This reverts commit 628e1ad981d5f9e323b9065db059c078b2b8c23e. * Revert "[SNMP][IPv6]: Fix SNMP IPv6 reachability issue in certain scenarios (#15487) (#15826)" This reverts commit 7cfb71bc18a5f6b83e6e7f1d24b623f5ff6c4040. --- dockers/docker-snmp/snmpd.conf.j2 | 39 ++----------------------------- dockers/docker-snmp/start.sh | 3 --- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index 182056b636e1..585fb5353e5b 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -13,47 +13,12 @@ # AGENT BEHAVIOUR # -# Listen for connections on all ip addresses, including eth0, ipv4 lo for multi-asic platform -# Listen on managment and loopback0 ips for single asic platform +# Listen for connections on all ip addresses, including eth0, ipv4 lo # -{% macro protocol(ip_addr) %} -{%- if ip_addr|ipv6 -%} -{{ 'udp6' }} -{%- else -%} -{{ 'udp' }} -{%- endif -%} -{% endmacro %} - {% if SNMP_AGENT_ADDRESS_CONFIG %} {% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %} -agentAddress {{ protocol(agentip) }}:[{{ agentip }}]{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} -{% endfor %} -{% elif NAMESPACE_COUNT is not defined or NAMESPACE_COUNT|int <= 1 %} -{% if MGMT_INTERFACE is defined %} -{% for intf, ip in MGMT_INTERFACE %} -{% set agentip = ip.split('/')[0]|lower %} -{% set zoneid = '' %} -# Use interface as zoneid for link local ipv6 -{% if agentip.startswith('fe80') %} -{% set zoneid = '%' + intf %} -{% endif %} -agentAddress {{ protocol(agentip) }}:[{{ agentip }}{{ zoneid }}]:161 -{% endfor %} -{% endif %} -{% if LOOPBACK_INTERFACE is defined %} -{% for lo in LOOPBACK_INTERFACE %} -{% if lo | length == 2 %} -{% set intf = lo[0] %} -{% set agentip = lo[1].split('/')[0]|lower %} -{% set zoneid = '' %} -# Use interface as zoneid for link local ipv6 -{% if agentip.startswith('fe80') %} -{% set zoneid = '%' + intf %} -{% endif %} -agentAddress {{ protocol(agentip) }}:[{{ agentip }}{{ zoneid }}]:161 -{% endif %} +agentAddress {{ agentip }}{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} {% endfor %} -{% endif %} {% else %} agentAddress udp:161 agentAddress udp6:161 diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index 559cdfdc341e..aefd0bfc3db6 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -16,14 +16,11 @@ mkdir -p /etc/ssw /etc/snmp # Parse snmp.yml and insert the data in Config DB /usr/bin/snmp_yml_to_configdb.py -ADD_PARAM=$(printf '%s {"NAMESPACE_COUNT":"%s"}' "-a" "$NAMESPACE_COUNT") - SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ -t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \ -t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \ - $ADD_PARAM \ " sonic-cfggen $SONIC_CFGGEN_ARGS From c774189d1493fa67855c5201610430024dcf97af Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:40:00 +0800 Subject: [PATCH 6/6] [submodule] Update submodule linkmgrd to the latest HEAD automatically (#16849) src/linkmgrd * d7ab364 - (HEAD -> 202205, origin/202205) [warmboot] config all interfaces back to `auto` if reconciliation times out (#220) (29 minutes ago) [Jing Zhang] --- src/linkmgrd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linkmgrd b/src/linkmgrd index 4bf3ebbe64d9..d7ab3644f578 160000 --- a/src/linkmgrd +++ b/src/linkmgrd @@ -1 +1 @@ -Subproject commit 4bf3ebbe64d906e43f035448b28e557bc41cfc8b +Subproject commit d7ab3644f578cf589a863eebab184411c640e8d1