Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable BMP feature switch in Nightly test #16081

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a77166c
Enable BMP feature switch in Nightly test
FengPan-Frank Dec 16, 2024
411a4e2
Enable BMP feature switch in Nightly test
FengPan-Frank Dec 16, 2024
1c7dc99
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
9c1525c
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
41696e4
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
704e09c
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
fb391aa
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
a58a462
Merge branch 'sonic-net:master' into feature_switch
FengPan-Frank Jan 6, 2025
dbcbfb8
Merge branch 'sonic-net:master' into feature_switch
FengPan-Frank Jan 7, 2025
0725c2b
Merge branch 'sonic-net:master' into feature_switch
FengPan-Frank Jan 8, 2025
89727d9
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Dec 17, 2024
0ac3aa5
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 9, 2025
9e4b79d
Fix original FEATURE table restore
FengPan-Frank Jan 14, 2025
d65d3bc
Merge branch 'sonic-net:master' into feature_switch
FengPan-Frank Jan 14, 2025
9af4385
Fix original FEATURE table restore
FengPan-Frank Jan 14, 2025
d46c987
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 15, 2025
c6e4d4f
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 15, 2025
cdb4819
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 15, 2025
075c817
Merge branch 'sonic-net:master' into feature_switch
FengPan-Frank Jan 16, 2025
f3cd991
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 15, 2025
38d60a0
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 16, 2025
e590722
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 16, 2025
e495896
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 16, 2025
cf79f92
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 16, 2025
39fa80a
Merge branch 'feature_switch' of https://github.com/FengPan-Frank/son…
FengPan-Frank Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions ansible/library/generate_golden_config_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import copy
import json
import re

from ansible.module_utils.basic import AnsibleModule
from sonic_py_common import multi_asic

DOCUMENTATION = '''
module: generate_golden_config_db.py
Expand Down Expand Up @@ -100,6 +102,73 @@ def generate_mx_golden_config_db(self):
gold_config_db.update(dhcp_server_config_obj)
return gold_config_db

def check_bmp_version(self):
# skip multi_asic first
if multi_asic.is_multi_asic():
return False

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version_number

There is a common function to parse version string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help to give a pointer, sorry I failed to find the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def _get_sonic_release(self):

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 get_config_from_minigraph(self):
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))
return out

def generate_bmp_golden_config_db(self, config):
full_config = config
onlyFeature = config == "{}" # FEATURE needs special handling since it does not support incremental update.
if config == "{}":
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
full_config = self.get_config_from_minigraph()

ori_config_db = json.loads(full_config)
if "FEATURE" not in ori_config_db:
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
full_config = self.get_config_from_minigraph()
feature_config_db = json.loads(full_config)
ori_config_db["FEATURE"] = feature_config_db.get("FEATURE", {})

# Append "bmp" section to the original "FEATURE" section
ori_config_db.setdefault("FEATURE", {}).setdefault("bmp", {}).update({
"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
if onlyFeature:
gold_config_db = {
"FEATURE": copy.deepcopy(ori_config_db["FEATURE"])
}
else:
gold_config_db = ori_config_db
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:
Expand Down Expand Up @@ -150,13 +219,18 @@ 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":
config = self.generate_smartswitch_golden_config_db()
else:
config = "{}"

# version check
if self.check_bmp_version() is True:
config = self.generate_bmp_golden_config_db(config)
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved

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))
Expand Down
1 change: 1 addition & 0 deletions spytest/apis/common/sonic_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"threshold",
"rest",
"gnmi",
"bmp",
"bgp-neighbotship-performance",
"prevent-delete-vlans-with-members",
"routing-mode-separated-by-default",
Expand Down
Loading