Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fd1f1c0
Add STATIC_CONFIG_DB
liuh-80 Aug 19, 2022
1dd56ad
Rename STATIC_CONFIG_DB to PROFILE_DB
liuh-80 Aug 25, 2022
8f72e52
Test swss-common
liuh-80 Sep 8, 2022
7017b05
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Sep 8, 2022
3403388
Merge branch 'sonic-net:master' into dev/liuh/swss_default_value
liuh-80 Oct 10, 2022
fb317ac
Update to test code
liuh-80 Oct 10, 2022
5fc3cc0
Fix merge issue
liuh-80 Oct 10, 2022
7dd293e
Add swss change
liuh-80 Oct 14, 2022
402efda
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Oct 14, 2022
ad732bd
Fix code issue
liuh-80 Oct 14, 2022
8ebee99
Update module
liuh-80 Oct 14, 2022
4636fdf
update submodule
liuh-80 Oct 17, 2022
19abfab
update submodule
liuh-80 Oct 18, 2022
63f92f1
Update submodule
liuh-80 Oct 19, 2022
44d4883
change use 202205 branch swss for warm reboot issue test
liuh-80 Oct 21, 2022
c66a536
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Oct 23, 2022
cac2deb
Update code
liuh-80 Oct 27, 2022
05cff50
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Nov 3, 2022
0e5e9ac
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Nov 4, 2022
02f7fea
Fix multi-asic issue
liuh-80 Nov 9, 2022
1a6d1c3
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Jan 4, 2023
7583c4e
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Jan 5, 2023
f99bddf
Merge remote-tracking branch 'origin' into dev/liuh/swss_default_value
liuh-80 Jan 16, 2023
dd82b83
Update submodule
liuh-80 Jan 16, 2023
5bc24d6
Update submodule
liuh-80 Jan 17, 2023
86e5086
Update submodule
liuh-80 Jan 17, 2023
5beb93e
Update submodule
liuh-80 Jan 20, 2023
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
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "sonic-swss-common"]
path = src/sonic-swss-common
url = https://github.com/sonic-net/sonic-swss-common
url = https://github.com/liuh-80/sonic-swss-common
branch = dev/liuh/add-decorator
[submodule "sonic-linux-kernel"]
path = src/sonic-linux-kernel
url = https://github.com/sonic-net/sonic-linux-kernel
Expand All @@ -9,7 +10,8 @@
url = https://github.com/sonic-net/sonic-sairedis
[submodule "sonic-swss"]
path = src/sonic-swss
url = https://github.com/sonic-net/sonic-swss
url = https://github.com/liuh-80/sonic-swss
branch = dev/liuh/buffer-config-static-config-poc
[submodule "src/p4c-bm/p4c-bm"]
path = platform/p4/p4c-bm/p4c-bm
url = https://github.com/krambn/p4c-bm
Expand All @@ -30,7 +32,8 @@
url = https://github.com/p4lang/ptf.git
[submodule "src/sonic-utilities"]
path = src/sonic-utilities
url = https://github.com/sonic-net/sonic-utilities
url = https://github.com/liuh-80/sonic-utilities
branch = dev/liuh/profile-db-init
[submodule "platform/broadcom/sonic-platform-modules-arista"]
path = platform/broadcom/sonic-platform-modules-arista
url = https://github.com/aristanetworks/sonic
Expand Down
5 changes: 5 additions & 0 deletions dockers/docker-database/database_config.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"id" : 14,
"separator": ":",
"instance" : "redis"
},
"PROFILE_DB" : {
"id" : 15,
"separator": ":",
"instance" : "redis"
}
},
"VERSION" : "1.0"
Expand Down
5 changes: 5 additions & 0 deletions platform/vs/docker-sonic-vs/database_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
"id" : 14,
"separator": ":",
"instance" : "redis"
},
"PROFILE_DB" : {
"id" : 15,
"separator": ":",
"instance" : "redis"
}
},
"VERSION" : "1.0"
Expand Down
45 changes: 38 additions & 7 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python
"""sonic-cfggen

A tool to read SONiC config data from one or more of the following sources:
minigraph file, config DB, json file(s), yaml files(s), command line input,
and write the data into DB, print as json, or render a jinja2 config template.

Examples:
Render template with minigraph:
sonic-cfggen -m -t /usr/share/template/bgpd.conf.j2
Expand Down Expand Up @@ -33,8 +31,9 @@ from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse
from portconfig import get_port_config, get_breakout_mode
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id, is_multi_asic
from sonic_py_common import device_info
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector

Check notice

Code scanning / CodeQL

Unused import

Import of 'SonicV2Connector' is not used.

profile_tables = ['BUFFER_POOL', 'BUFFER_PROFILE']

PY3x = sys.version_info >= (3, 0)

Expand Down Expand Up @@ -147,7 +146,6 @@ def load_namespace_config(asic_name):
class FormatConverter:
"""Convert config DB based schema to legacy minigraph based schema for backward capability.
We will move to DB schema and remove this class when the config templates are modified.

TODO(taoyl): Current version of config db only supports BGP admin states.
All other configuration are still loaded from minigraph. Plan to remove
minigraph and move everything into config db in a later commit.
Expand Down Expand Up @@ -252,6 +250,19 @@ def _get_jinja2_env(paths):

return env

def filter_profile_tables(data, generate_profile):
if generate_profile:
# remove all none profile tables
tables = list(data.keys())
for table in tables:
if table not in profile_tables:
del data[table]
else:
# remove profile tables
for table in profile_tables:
if table in data.keys():
del data[table]

def main():
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
group = parser.add_mutually_exclusive_group()
Expand All @@ -268,6 +279,7 @@ def main():
parser.add_argument("-d", "--from-db", help="read config from configdb", action='store_true')
parser.add_argument("-H", "--platform-info", help="read platform and hardware info", action='store_true')
parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection")
parser.add_argument("-P", "--profile-config", help="generate profile config", action='store_true')
group = parser.add_mutually_exclusive_group()
group.add_argument("-t", "--template", help="render the data with the template file", action="append", default=[],
type=lambda opt_value: tuple(opt_value.split(',')) if ',' in opt_value else (opt_value, sys.stdout))
Expand Down Expand Up @@ -368,6 +380,17 @@ def main():
configdb.connect()
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))

if args.profile_config:
# remove profile table, some data used by following code
filter_profile_tables(data, False)

# create new connection to PROFILE_DB
if args.namespace is None:
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, **db_kwargs)
else:
SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace)
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, namespace=args.namespace, **db_kwargs)
configdb.db_connect("PROFILE_DB")

# the minigraph file must be provided to get the mac address for backend asics
# or switch_type chassis_packet
Expand Down Expand Up @@ -414,7 +437,7 @@ def main():
for template_file, dest_file in args.template:
template = env.get_template(os.path.basename(template_file))
template_data = template.render(data)
if dest_file == "config-db":
if dest_file == "config-db" or dest_file == "profile-db":
deep_update(data, FormatConverter.to_deserialized(json.loads(template_data)))
else:
with smart_open(dest_file, 'w') as df:
Expand All @@ -424,6 +447,10 @@ def main():
template = jinja2.Template('{{' + args.var + '}}')
print(template.render(data))

if args.profile_config:
# TODO: after profile DB migration finish, remove the if check to remove profile tables from config DB
filter_profile_tables(data, args.profile_config)

if args.var_json is not None and args.var_json in data:
if args.key is not None:
print(json.dumps(FormatConverter.to_serialized(data[args.var_json], args.key), indent=4, cls=minigraph_encoder))
Expand All @@ -437,7 +464,11 @@ def main():
SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace)
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, namespace=args.namespace, **db_kwargs)

configdb.connect(False)
if args.profile_config:
configdb.db_connect("PROFILE_DB")
else:
configdb.connect(False)

configdb.mod_config(FormatConverter.output_to_db(data))

if args.print_data:
Expand All @@ -449,4 +480,4 @@ def main():


if __name__ == "__main__":
main()
main()