@@ -33,6 +33,7 @@ def test_get_fact(self):
3333 print_input = False ,
3434 print_output = False ,
3535 shell_executable = 'sh' ,
36+ success_exit_codes = [0 ],
3637 su_user = None ,
3738 sudo = False ,
3839 sudo_user = None ,
@@ -72,6 +73,7 @@ def test_get_fact_current_op_meta(self):
7273 print_input = False ,
7374 print_output = False ,
7475 shell_executable = 'sh' ,
76+ success_exit_codes = [0 ],
7577 su_user = 'someuser' ,
7678 sudo = True ,
7779 sudo_user = 'someuser' ,
@@ -104,6 +106,7 @@ def test_get_fact_error(self):
104106 print_input = False ,
105107 print_output = False ,
106108 shell_executable = 'sh' ,
109+ success_exit_codes = [0 ],
107110 su_user = None ,
108111 sudo = False ,
109112 sudo_user = None ,
@@ -143,6 +146,39 @@ def test_get_fact_error_ignore(self):
143146 print_input = False ,
144147 print_output = False ,
145148 shell_executable = 'sh' ,
149+ success_exit_codes = [0 ],
150+ su_user = None ,
151+ sudo = False ,
152+ sudo_user = None ,
153+ timeout = None ,
154+ env = {},
155+ use_sudo_password = False ,
156+ return_combined_output = True ,
157+ )
158+
159+ def test_get_fact_with_list_of_success_codes (self ):
160+ inventory = make_inventory (hosts = ('anotherhost' ,))
161+ state = State (inventory , Config ())
162+
163+ anotherhost = inventory .get_host ('anotherhost' )
164+
165+ connect_all (state )
166+
167+ exit_codes = [1 , 2 , 3 ]
168+ with patch ('pyinfra.api.connectors.ssh.run_shell_command' ) as fake_run_command :
169+ fake_run_command .return_value = MagicMock (), [('stdout' , 'some-output' )]
170+ fact_data = get_facts (state , 'command' , ('yes' ,), {'success_exit_codes' : exit_codes })
171+
172+ assert fact_data == {anotherhost : 'some-output' }
173+
174+ fake_run_command .assert_called_with (
175+ state ,
176+ anotherhost ,
177+ 'yes' ,
178+ print_input = False ,
179+ print_output = False ,
180+ shell_executable = 'sh' ,
181+ success_exit_codes = exit_codes ,
146182 su_user = None ,
147183 sudo = False ,
148184 sudo_user = None ,
0 commit comments