Repository: sonic-net/sonic-utilities

Issue:
SONiC Environment file is only updated during `load_minirgaph`
<!--
    If you are reporting a new issue, make sure that we do not have any duplicates
    already open. You can ensure this by searching the issue list for this
    repository. If there is a duplicate, please close your issue and add a comment
    to the existing issue instead.

    If you suspect your issue is a bug, please edit your issue description to
    include the BUG REPORT INFORMATION shown below. If you fail to provide this
    information within 7 days, we cannot debug your issue and will close it. We
    will, however, reopen it if you later provide the information.

    For more information about reporting issues, see
    https://github.com/Azure/SONiC/wiki#report-issues

    ---------------------------------------------------
    GENERAL SUPPORT INFORMATION
    ---------------------------------------------------

    The GitHub issue tracker is for bug reports and feature requests.
    General support can be found at the following locations:

    - SONiC Support Forums - https://groups.google.com/forum/#!forum/sonicproject

    ---------------------------------------------------
    BUG REPORT INFORMATION
    ---------------------------------------------------
    Use the commands below to provide key information from your environment:
    You do NOT have to include this information if this is a FEATURE REQUEST
-->

#### Description

<!--
     Briefly describe the problem you are having in a few paragraphs.
-->
Master/202012 images only.

If the HWSKU on a device is changed without performing a `load_minigraph`, the old HWKSU will persist in the sonic-environment file and cause orchagent to crash.

## Steps to reproduce the issue
1. On a healthy device, change the HWSKU in `/etc/sonic/config_db.json`
2. Perform `config reload`
3.

#### Describe the results you received
Orchagent crashes during initialization

#### Describe the results you expected
The device successfully performs the reload and stays up.


#### Additional information you deem important (e.g. issue happens only occasionally)
The update_sonic_environment method is currently only called in `load_minigraph`: https://github.com/Azure/sonic-utilities/blob/56db1623407bd2ebc198b6df88fc3ada624c793e/config/main.py#L858

Calling this method during `config reload` should alleviate the issue.


#### Output of `show version`

```
(paste your output here)
```

<!--
     Also attach debug file produced by `sudo generate_dump`
-->




Discussion:

Resolving patch:
diff --git a/config/main.py b/config/main.py
--- a/config/main.py
+++ b/config/main.py
@@ -1310,6 +1310,9 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach
                 command = "{} -o migrate -n {}".format(db_migrator, namespace)
             clicommon.run_command(command, display_cmd=True)
 
+    # Re-generate the environment variable in case config_db.json was edited
+    update_sonic_environment()
+
     # We first run "systemctl reset-failed" to remove the "failed"
     # status from all services before we attempt to restart them
     if not no_service_restart:


Test patch: