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

[minigraph] Consume golden_config_db.json while loading minigraph #2140

Merged
merged 3 commits into from
May 9, 2022

Conversation

wen587
Copy link
Contributor

@wen587 wen587 commented Apr 26, 2022

What I did

This PR is for supporting consume golden_config_db.json while loading minigraph. User can put the golden_config_db.json with minigraph file to override configDB after reload minigraph.
The golden_config_db.json looks just like a config_db.json and it will be placed on /etc/sonic/golden_config_db.json.
Step1: Load minigraph to configDB
Step2: If golden_config_db.json exists and contains some Table configuration, that Table in configDB will be overriden by the config in golden_config_db.json. Other config that not included in golden_config_db.json will keep the same as minigraph.
For example, assume below ACL_TABLE is loaded from minigraph:
config from minigraph:

        "ACL_TABLE": {
            "DATAACL": {
                "policy_desc": "DATAACL",
                "ports": [
                    "Ethernet4"
                ],
                "stage": "ingress",
                "type": "L3"
            },
            "NTP_ACL": {
                "policy_desc": "NTP_ACL",
                "services": [
                    "NTP"
                ],
                "stage": "ingress",
                "type": "CTRLPLANE"
            }
        },

The golden_config_db.json also contains ACL_TABLE as below.
config from golden_config_db.json

"ACL_TABLE": {
            "EVERFLOWV6": {
                "policy_desc": "EVERFLOWV6",
                "ports": [
                    "Ethernet12"
                ],
                "stage": "ingress",
                "type": "MIRRORV6"
            }
        },

During load_minigraph, the final config will be the same with golden_config_db.json because ACL_TABLE will be overriden by golden_config_db.json.
configDB ACL_TABLE final state:

"ACL_TABLE": {
            "EVERFLOWV6": {
                "policy_desc": "EVERFLOWV6",
                "ports": [
                    "Ethernet12"
                ],
                "stage": "ingress",
                "type": "MIRRORV6"
            }
        },

How I did it

Add code config override-config-table command to let it consume golden_config_db.json

How to verify it

Add UT tests and run.

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

admin@vlab-01:~$ sudo config override-config-table -h
Usage: config override-config-table [OPTIONS] INPUT_CONFIG_DB

  Override current configDB with input config.

Options:
  --dry_run TEXT  Dry run, writes config to the given file
  -h, -?, --help  Show this message and exit.

@wen587 wen587 requested a review from qiluo-msft April 26, 2022 10:24
@wen587 wen587 changed the title Golden Config Support in SONiC [minigraph] Consume golden_config_db.json while loading minigraph Apr 26, 2022
@@ -99,6 +99,9 @@
QUEUE_RANGE = click.IntRange(min=0, max=255)
GRE_TYPE_RANGE = click.IntRange(min=0, max=65535)

# Load sonic-cfggen from source since /usr/local/bin/sonic-cfggen does not have .py extension.
sonic_cfggen = load_module_from_source('sonic_cfggen', '/usr/local/bin/sonic-cfggen')
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 26, 2022

Choose a reason for hiding this comment

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

load_module_from_source

We can move some useful functions to an official python module (ref: src/sonic-config-engine/setup.py) so it will be easy to reuse. This ask is in low priority, you can check this after all others resolved. #Pending

config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
@wen587 wen587 requested a review from isabelmsft April 27, 2022 01:08
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

LGTM. Let's wait a while for more eyes.

@prsunny
Copy link
Contributor

prsunny commented May 9, 2022

Can you please provide more details in the description?

For e.g, what is overridden from the golden_config? Is any config taken from the minigraph in this case?

@wen587
Copy link
Contributor Author

wen587 commented May 10, 2022

Can you please provide more details in the description?

For e.g, what is overridden from the golden_config? Is any config taken from the minigraph in this case?

Updated in description.
In short, configDB will be overriden by all golden_config_db.json 's configurations. The other Table configurations will keep the same as minigraph generated config if not listed in Golden Config,

@@ -1619,6 +1623,10 @@ def load_minigraph(db, no_service_restart):
cfggen_namespace_option = " -n {}".format(namespace)
clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)

# Load golden_config_db.json
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
Copy link
Contributor

@judyjoseph judyjoseph May 26, 2022

Choose a reason for hiding this comment

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

@wen587, @qiluo-msft, to support multi-asic devices, to start with could we also call this API override_config_by() per namespace as well? This will help with the pilot of this feature MACSEC_PROFILE table which is needed in the redis_db per namespace as well -- macsec/swss dockers run per asic/namespace.

Later when we design the table contents in the golden_config_db.json file, we could name the table based on the asic/namespace name eg: ASIC0_PORT_TABLE, ASIC1_PORT_TABLE etc - so that the respective tables will be pushed to the right redis DB in namespaces.

wen587 added a commit that referenced this pull request Jun 23, 2022
…raph (#2227)

This PR is to cherry-pick changes in PR #2140 to 202012 branch after resolving conflicts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants