diff --git a/.gitmodules b/.gitmodules index 55299d62fe7..1f034d19080 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 @@ -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 @@ -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 diff --git a/dockers/docker-database/database_config.json.j2 b/dockers/docker-database/database_config.json.j2 index f0807b23837..753b8d12283 100644 --- a/dockers/docker-database/database_config.json.j2 +++ b/dockers/docker-database/database_config.json.j2 @@ -93,6 +93,11 @@ "id" : 14, "separator": ":", "instance" : "redis" + }, + "PROFILE_DB" : { + "id" : 15, + "separator": ":", + "instance" : "redis" } }, "VERSION" : "1.0" diff --git a/platform/vs/docker-sonic-vs/database_config.json b/platform/vs/docker-sonic-vs/database_config.json index 04cb3d3aaae..4be9108865a 100644 --- a/platform/vs/docker-sonic-vs/database_config.json +++ b/platform/vs/docker-sonic-vs/database_config.json @@ -77,6 +77,11 @@ "id" : 14, "separator": ":", "instance" : "redis" + }, + "PROFILE_DB" : { + "id" : 15, + "separator": ":", + "instance" : "redis" } }, "VERSION" : "1.0" diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 287640d8a11..5c734f4272b 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -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 @@ -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 +profile_tables = ['BUFFER_POOL', 'BUFFER_PROFILE'] PY3x = sys.version_info >= (3, 0) @@ -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. @@ -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() @@ -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)) @@ -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 @@ -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: @@ -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)) @@ -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: @@ -449,4 +480,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/src/sonic-swss b/src/sonic-swss index bdedf694f10..d2099e3ed6a 160000 --- a/src/sonic-swss +++ b/src/sonic-swss @@ -1 +1 @@ -Subproject commit bdedf694f10b6f8b5ea71fb30eef5d0c3b354409 +Subproject commit d2099e3ed6a93587cca01ca7508b912d763cbd2d diff --git a/src/sonic-swss-common b/src/sonic-swss-common index a4987b931b2..72907c608e9 160000 --- a/src/sonic-swss-common +++ b/src/sonic-swss-common @@ -1 +1 @@ -Subproject commit a4987b931b246c141dff91fa2f0e971dbc41820e +Subproject commit 72907c608e9e25b5aa8bfadbbe7cec01a01ad295 diff --git a/src/sonic-utilities b/src/sonic-utilities index fb8f98bfa67..35b9a0d4ad4 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit fb8f98bfa672a80f56398d57a470a02d031d3da3 +Subproject commit 35b9a0d4ad436ac7873e138a5d8949f53bdb661a