@@ -89,6 +89,22 @@ def mock_run_command_side_effect(*args, **kwargs):
89
89
else :
90
90
return ''
91
91
92
+ def mock_run_command_side_effect_gnmi (* args , ** kwargs ):
93
+ command = args [0 ]
94
+
95
+ if kwargs .get ('display_cmd' ):
96
+ click .echo (click .style ("Running command: " , fg = 'cyan' ) + click .style (command , fg = 'green' ))
97
+
98
+ if kwargs .get ('return_cmd' ):
99
+ if command == "systemctl list-dependencies --plain sonic-delayed.target | sed '1d'" :
100
+ return 'gnmi.timer'
101
+ elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'" :
102
+ return 'swss'
103
+ elif command == "systemctl is-enabled gnmi.timer" :
104
+ return 'enabled'
105
+ else :
106
+ return ''
107
+
92
108
93
109
# Load sonic-cfggen from source since /usr/local/bin/sonic-cfggen does not have .py extension.
94
110
sonic_cfggen = load_module_from_source ('sonic_cfggen' , '/usr/local/bin/sonic-cfggen' )
@@ -168,6 +184,22 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
168
184
mock_run_command .assert_any_call ('systemctl reset-failed snmp' )
169
185
assert mock_run_command .call_count == 11
170
186
187
+ def test_load_minigraph_with_gnmi_timer (self , get_cmd_module , setup_single_broadcom_asic ):
188
+ with mock .patch ("utilities_common.cli.run_command" , mock .MagicMock (side_effect = mock_run_command_side_effect_gnmi )) as mock_run_command :
189
+ (config , show ) = get_cmd_module
190
+ runner = CliRunner ()
191
+ result = runner .invoke (config .config .commands ["load_minigraph" ], ["-y" ])
192
+ print (result .exit_code )
193
+ print (result .output )
194
+ traceback .print_tb (result .exc_info [2 ])
195
+ assert result .exit_code == 0
196
+ assert "\n " .join ([l .rstrip () for l in result .output .split ('\n ' )]) == load_minigraph_command_output
197
+ # Verify "systemctl reset-failed" is called for services under sonic.target
198
+ mock_run_command .assert_any_call ('systemctl reset-failed swss' )
199
+ # Verify "systemctl reset-failed" is called for services under sonic-delayed.target
200
+ mock_run_command .assert_any_call ('systemctl reset-failed gnmi' )
201
+ assert mock_run_command .call_count == 11
202
+
171
203
def test_load_minigraph_with_port_config_bad_format (self , get_cmd_module , setup_single_broadcom_asic ):
172
204
with mock .patch (
173
205
"utilities_common.cli.run_command" ,
0 commit comments