Skip to content

Commit

Permalink
Fix sonic-installer and 'show version' command crash when database do…
Browse files Browse the repository at this point in the history
…cker not running issue. (#2183)

Fix sonic-installer and 'show version' command crash when database docker not running issue.

#### Description
    Global variable utilies_common.cli.iface_alias_converter will connect to config DB when initialize itself. If database docker not running, the initialize code will crash. 
    To fix this issue, change the variable to lazy initialize variable with lazy_object_proxy.

#### Motivation and Context

Fix this issue: sonic-net/sonic-buildimage#10434

#### How Has This Been Tested?
    Pass all UT and sonic-buildimage E2E test.

#### Additional Information (Optional)
  • Loading branch information
liuh-80 authored May 30, 2022
1 parent 4ad70b9 commit 9e310e5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
'toposort==1.6',
'www-authenticate==0.9.2',
'xmltodict==0.12.0',
'lazy-object-proxy',
],
setup_requires= [
'pytest-runner',
Expand Down
5 changes: 3 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

import click
import lazy_object_proxy
import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
import utilities_common.multi_asic as multi_asic_util
Expand Down Expand Up @@ -126,8 +127,8 @@ def run_command(command, display_cmd=False, return_cmd=False):
if rc != 0:
sys.exit(rc)

# Global class instance for SONiC interface name to alias conversion
iface_alias_converter = clicommon.InterfaceAliasConverter()
# Lazy global class instance for SONiC interface name to alias conversion
iface_alias_converter = lazy_object_proxy.Proxy(lambda: clicommon.InterfaceAliasConverter())

#
# Display all storm-control data
Expand Down
5 changes: 3 additions & 2 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import click
import json
import lazy_object_proxy
import netaddr

from natsort import natsorted
Expand Down Expand Up @@ -183,8 +184,8 @@ def alias_to_name(self, interface_alias):
# interface_alias not in port_dict. Just return interface_alias
return interface_alias if sub_intf_sep_idx == -1 else interface_alias + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id

# Global class instance for SONiC interface name to alias conversion
iface_alias_converter = InterfaceAliasConverter()
# Lazy global class instance for SONiC interface name to alias conversion
iface_alias_converter = lazy_object_proxy.Proxy(lambda: InterfaceAliasConverter())

def get_interface_naming_mode():
mode = os.getenv('SONIC_CLI_IFACE_MODE')
Expand Down

0 comments on commit 9e310e5

Please sign in to comment.