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 6de2c94
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@
become: true
when: topo == "t1-28-lag"

- name: Copy bmp config
copy: src=golden_config_db/bmp.json
dest=/tmp/bmp.json
become: true

- name: Generate golden_config_db.json
generate_golden_config_db:
topo_name: "{{ topo }}"
Expand Down
7 changes: 7 additions & 0 deletions ansible/golden_config_db/bmp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"FEATURE": {
"bmp": {
"state": "enabled"
}
}
}
27 changes: 26 additions & 1 deletion ansible/library/generate_golden_config_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
GOLDEN_CONFIG_DB_PATH = "/etc/sonic/golden_config_db.json"
TEMP_DHCP_SERVER_CONFIG_PATH = "/tmp/dhcp_server.json"
TEMP_SMARTSWITCH_CONFIG_PATH = "/tmp/smartswitch.json"
TEMP_BMP_CONFIG_PATH = "/tmp/bmp.json"
DUMMY_QUOTA = "dummy_single_quota"


Expand Down Expand Up @@ -92,6 +93,30 @@ def generate_mx_golden_config_db(self):
gold_config_db.update(dhcp_server_config_obj)
return gold_config_db

def generate_bmp_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:
self.module.fail_json(msg="Failed to get config from minigraph: {}".format(err))

# Generate FEATURE table from init_cfg.ini
ori_config_db = json.loads(out)
if "FEATURE" not in ori_config_db \
or "bmp" not in ori_config_db["FEATURE"] \
or "state" not in ori_config_db["FEATURE"]["bmp"]:
return "{}"

ori_config_db["FEATURE"]["bmp"]["state"] = "enabled"
gold_config_db = {
"FEATURE": copy.deepcopy(ori_config_db["FEATURE"])
}

rc, out, err = self.module.run_command("cat {}".format(TEMP_BMP_CONFIG_PATH))
if rc != 0:
self.module.fail_json(msg="Failed to get bmp config: {}".format(err))
bmp_config_obj = json.loads(out)
gold_config_db.update(bmp_config_obj)
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 @@ -121,7 +146,7 @@ def generate(self):
elif self.topo_name == "t1-28-lag":
config = self.generate_smartswitch_golden_config_db()
else:
config = "{}"
config = self.generate_bmp_golden_config_db()

with open(GOLDEN_CONFIG_DB_PATH, "w") as temp_file:
temp_file.write(config)
Expand Down

0 comments on commit 6de2c94

Please sign in to comment.