Skip to content

Commit 9e310e5

Browse files
authored
Fix sonic-installer and 'show version' command crash when database docker 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: #10434 #### How Has This Been Tested? Pass all UT and sonic-buildimage E2E test. #### Additional Information (Optional)
1 parent 4ad70b9 commit 9e310e5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
'toposort==1.6',
217217
'www-authenticate==0.9.2',
218218
'xmltodict==0.12.0',
219+
'lazy-object-proxy',
219220
],
220221
setup_requires= [
221222
'pytest-runner',

show/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66

77
import click
8+
import lazy_object_proxy
89
import utilities_common.cli as clicommon
910
from sonic_py_common import multi_asic
1011
import utilities_common.multi_asic as multi_asic_util
@@ -126,8 +127,8 @@ def run_command(command, display_cmd=False, return_cmd=False):
126127
if rc != 0:
127128
sys.exit(rc)
128129

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

132133
#
133134
# Display all storm-control data

utilities_common/cli.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import click
99
import json
10+
import lazy_object_proxy
1011
import netaddr
1112

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

186-
# Global class instance for SONiC interface name to alias conversion
187-
iface_alias_converter = InterfaceAliasConverter()
187+
# Lazy global class instance for SONiC interface name to alias conversion
188+
iface_alias_converter = lazy_object_proxy.Proxy(lambda: InterfaceAliasConverter())
188189

189190
def get_interface_naming_mode():
190191
mode = os.getenv('SONIC_CLI_IFACE_MODE')

0 commit comments

Comments
 (0)