From a77166ca7f258e8e744563b8e716432c7ba7f862 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 16 Dec 2024 02:33:13 +0000 Subject: [PATCH 1/4] Enable BMP feature switch in Nightly test --- ansible/library/generate_golden_config_db.py | 42 ++++++++++++++++++++ spytest/apis/common/sonic_features.py | 1 + 2 files changed, 43 insertions(+) diff --git a/ansible/library/generate_golden_config_db.py b/ansible/library/generate_golden_config_db.py index 7bf0dd72203..4a5f30a9380 100644 --- a/ansible/library/generate_golden_config_db.py +++ b/ansible/library/generate_golden_config_db.py @@ -7,6 +7,7 @@ import copy import json +import re from ansible.module_utils.basic import AnsibleModule @@ -92,6 +93,42 @@ def generate_mx_golden_config_db(self): gold_config_db.update(dhcp_server_config_obj) return gold_config_db + def check_bmp_version(self): + rc, out, err = self.module.run_command("sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version") + if rc != 0: + self.module.fail_json(msg="Failed to get version from sonic_version.yml: {}".format(err)) + build_version = out.strip() + + if re.match(r'^(\d{8})', build_version): + version_number = int(re.findall(r'\d{8}', build_version)[0]) + if version_number > 20241130: + return True + else: + return False + elif re.match(r'^internal-(\d{8})', build_version): + internal_version_number = int(re.findall(r'\d{8}', build_version)[0]) + if internal_version_number > 20241130: + return True + else: + return False + elif re.match(r'^master', build_version) or re.match(r'^HEAD', build_version): + return True + else: + return False + + def generate_bmp_golden_config_db(self, config): + ori_config_db = json.loads(config) + if "FEATURE" not in ori_config_db: + ori_config_db["FEATURE"] = {} + if "bmp" not in ori_config_db["FEATURE"]: + ori_config_db["FEATURE"]["bmp"] = {} + ori_config_db["FEATURE"]["bmp"]["state"] = "enabled" + gold_config_db = { + "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]) + } + + return json.dumps(gold_config_db, indent=4) + def generate_smartswitch_golden_config_db(self): rc, out, err = self.module.run_command("sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data") if rc != 0: @@ -116,6 +153,7 @@ def generate_smartswitch_golden_config_db(self): return json.dumps(gold_config_db, indent=4) def generate(self): + # topo check if self.topo_name == "mx" or "m0" in self.topo_name: config = self.generate_mgfx_golden_config_db() elif self.topo_name == "t1-28-lag": @@ -123,6 +161,10 @@ def generate(self): else: config = "{}" + # version check + if self.check_bmp_version() is True: + config = self.generate_bmp_golden_config_db(config) + with open(GOLDEN_CONFIG_DB_PATH, "w") as temp_file: temp_file.write(config) self.module.run_command("sudo rm -f {}".format(TEMP_DHCP_SERVER_CONFIG_PATH)) diff --git a/spytest/apis/common/sonic_features.py b/spytest/apis/common/sonic_features.py index 438e80579b6..97d60219d10 100755 --- a/spytest/apis/common/sonic_features.py +++ b/spytest/apis/common/sonic_features.py @@ -23,6 +23,7 @@ "threshold", "rest", "gnmi", + "bmp", "bgp-neighbotship-performance", "prevent-delete-vlans-with-members", "routing-mode-separated-by-default", From 411a4e2f6bb342b918f3319524b3091897fc618d Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 16 Dec 2024 02:33:13 +0000 Subject: [PATCH 2/4] Enable BMP feature switch in Nightly test --- ansible/library/generate_golden_config_db.py | 57 ++++++++++++++++++++ spytest/apis/common/sonic_features.py | 1 + 2 files changed, 58 insertions(+) diff --git a/ansible/library/generate_golden_config_db.py b/ansible/library/generate_golden_config_db.py index 7bf0dd72203..c1deab480e1 100644 --- a/ansible/library/generate_golden_config_db.py +++ b/ansible/library/generate_golden_config_db.py @@ -7,6 +7,7 @@ import copy import json +import re from ansible.module_utils.basic import AnsibleModule @@ -92,6 +93,57 @@ def generate_mx_golden_config_db(self): gold_config_db.update(dhcp_server_config_obj) return gold_config_db + def check_bmp_version(self): + rc, out, err = self.module.run_command("sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version") + if rc != 0: + self.module.fail_json(msg="Failed to get version from sonic_version.yml: {}".format(err)) + build_version = out.strip() + + if re.match(r'^(\d{8})', build_version): + version_number = int(re.findall(r'\d{8}', build_version)[0]) + if version_number > 20241130: + return True + else: + return False + elif re.match(r'^internal-(\d{8})', build_version): + internal_version_number = int(re.findall(r'\d{8}', build_version)[0]) + if internal_version_number > 20241130: + return True + else: + return False + elif re.match(r'^master', build_version) or re.match(r'^HEAD', build_version): + return True + else: + return False + + def generate_bmp_golden_config_db(self, config): + full_config = config + if config == "{}": + rc, out, err = self.module.run_command("sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data") + if rc != 0: + self.module.fail_json(msg="Failed to get config from minigraph: {}".format(err)) + full_config = out + + ori_config_db = json.loads(full_config) + if "FEATURE" not in ori_config_db: + ori_config_db["FEATURE"] = {} + if "bmp" not in ori_config_db["FEATURE"]: + ori_config_db["FEATURE"]["bmp"] = {} + ori_config_db["FEATURE"]["bmp"]["auto_restart"] = "disabled" + ori_config_db["FEATURE"]["bmp"]["check_up_status"] = "false" + ori_config_db["FEATURE"]["bmp"]["delayed"] = "False" + ori_config_db["FEATURE"]["bmp"]["has_global_scope"] = "False" + ori_config_db["FEATURE"]["bmp"]["has_per_asic_scope"] = "True" + ori_config_db["FEATURE"]["bmp"]["high_mem_alert"] = "disabled" + ori_config_db["FEATURE"]["bmp"]["set_owner"] = "local" + ori_config_db["FEATURE"]["bmp"]["state"] = "enabled" + ori_config_db["FEATURE"]["bmp"]["support_syslog_rate_limit"] = "true" + gold_config_db = { + "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]) + } + + return json.dumps(gold_config_db, indent=4) + def generate_smartswitch_golden_config_db(self): rc, out, err = self.module.run_command("sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data") if rc != 0: @@ -116,6 +168,7 @@ def generate_smartswitch_golden_config_db(self): return json.dumps(gold_config_db, indent=4) def generate(self): + # topo check if self.topo_name == "mx" or "m0" in self.topo_name: config = self.generate_mgfx_golden_config_db() elif self.topo_name == "t1-28-lag": @@ -123,6 +176,10 @@ def generate(self): else: config = "{}" + # version check + if self.check_bmp_version() is True: + config = self.generate_bmp_golden_config_db(config) + with open(GOLDEN_CONFIG_DB_PATH, "w") as temp_file: temp_file.write(config) self.module.run_command("sudo rm -f {}".format(TEMP_DHCP_SERVER_CONFIG_PATH)) diff --git a/spytest/apis/common/sonic_features.py b/spytest/apis/common/sonic_features.py index 438e80579b6..97d60219d10 100755 --- a/spytest/apis/common/sonic_features.py +++ b/spytest/apis/common/sonic_features.py @@ -23,6 +23,7 @@ "threshold", "rest", "gnmi", + "bmp", "bgp-neighbotship-performance", "prevent-delete-vlans-with-members", "routing-mode-separated-by-default", From 9e4b79d7889fbd193dba9a02afdaa75f0b7e601e Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Tue, 14 Jan 2025 14:45:09 +0000 Subject: [PATCH 3/4] Fix original FEATURE table restore --- ansible/library/generate_golden_config_db.py | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ansible/library/generate_golden_config_db.py b/ansible/library/generate_golden_config_db.py index aa794c663bf..7f6eab7bd1e 100644 --- a/ansible/library/generate_golden_config_db.py +++ b/ansible/library/generate_golden_config_db.py @@ -140,21 +140,26 @@ def generate_bmp_golden_config_db(self, config): ori_config_db = json.loads(full_config) if "FEATURE" not in ori_config_db: ori_config_db["FEATURE"] = {} + + # Add "bmp" section to the original "FEATURE" section if "bmp" not in ori_config_db["FEATURE"]: - ori_config_db["FEATURE"]["bmp"] = {} - ori_config_db["FEATURE"]["bmp"]["auto_restart"] = "enabled" - ori_config_db["FEATURE"]["bmp"]["check_up_status"] = "false" - ori_config_db["FEATURE"]["bmp"]["delayed"] = "False" - ori_config_db["FEATURE"]["bmp"]["has_global_scope"] = "True" - ori_config_db["FEATURE"]["bmp"]["has_per_asic_scope"] = "False" - ori_config_db["FEATURE"]["bmp"]["high_mem_alert"] = "disabled" - ori_config_db["FEATURE"]["bmp"]["set_owner"] = "local" - ori_config_db["FEATURE"]["bmp"]["state"] = "enabled" - ori_config_db["FEATURE"]["bmp"]["support_syslog_rate_limit"] = "true" - gold_config_db = { - "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]) + ori_config_db["FEATURE"]["bmp"] = { + "auto_restart": "enabled", + "check_up_status": "false", + "delayed": "False", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled", + "support_syslog_rate_limit": "true" } + # Create the gold_config_db dictionary with both "FEATURE" and "bmp" sections + gold_config_db = { + "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]), + "bmp": ori_config_db["FEATURE"]["bmp"] + } return json.dumps(gold_config_db, indent=4) def generate_smartswitch_golden_config_db(self): From 9af43853637217090a8bd4df29c31e06b467fd54 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Tue, 14 Jan 2025 14:45:09 +0000 Subject: [PATCH 4/4] Fix original FEATURE table restore --- ansible/library/generate_golden_config_db.py | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ansible/library/generate_golden_config_db.py b/ansible/library/generate_golden_config_db.py index aa794c663bf..38ca2cb92af 100644 --- a/ansible/library/generate_golden_config_db.py +++ b/ansible/library/generate_golden_config_db.py @@ -140,21 +140,26 @@ def generate_bmp_golden_config_db(self, config): ori_config_db = json.loads(full_config) if "FEATURE" not in ori_config_db: ori_config_db["FEATURE"] = {} + + # Add "bmp" section to the original "FEATURE" section if "bmp" not in ori_config_db["FEATURE"]: - ori_config_db["FEATURE"]["bmp"] = {} - ori_config_db["FEATURE"]["bmp"]["auto_restart"] = "enabled" - ori_config_db["FEATURE"]["bmp"]["check_up_status"] = "false" - ori_config_db["FEATURE"]["bmp"]["delayed"] = "False" - ori_config_db["FEATURE"]["bmp"]["has_global_scope"] = "True" - ori_config_db["FEATURE"]["bmp"]["has_per_asic_scope"] = "False" - ori_config_db["FEATURE"]["bmp"]["high_mem_alert"] = "disabled" - ori_config_db["FEATURE"]["bmp"]["set_owner"] = "local" - ori_config_db["FEATURE"]["bmp"]["state"] = "enabled" - ori_config_db["FEATURE"]["bmp"]["support_syslog_rate_limit"] = "true" + ori_config_db["FEATURE"]["bmp"] = { + "auto_restart": "enabled", + "check_up_status": "false", + "delayed": "False", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled", + "support_syslog_rate_limit": "true" + } + + # Create the gold_config_db dictionary with both "FEATURE" and "bmp" sections gold_config_db = { - "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]) + "FEATURE": copy.deepcopy(ori_config_db["FEATURE"]), + "bmp": ori_config_db["FEATURE"]["bmp"] } - return json.dumps(gold_config_db, indent=4) def generate_smartswitch_golden_config_db(self):