Skip to content

Commit

Permalink
Enable BMP feature switch in Nightly test
Browse files Browse the repository at this point in the history
  • Loading branch information
FengPan-Frank committed Dec 16, 2024
1 parent 4f66f6f commit fbd00c1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ansible/library/generate_golden_config_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import copy
import json
import re

from ansible.module_utils.basic import AnsibleModule

Expand Down Expand Up @@ -92,6 +93,38 @@ 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)
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:
Expand All @@ -116,13 +149,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)

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

0 comments on commit fbd00c1

Please sign in to comment.