Skip to content

Commit 5509bb8

Browse files
authored
Merge pull request #2050 from peterhorsley/exec-provider-exception
Fix exception in ExecProvider when no console is attached.
2 parents ca4bfe5 + b5b39b3 commit 5509bb8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

kubernetes/base/config/exec_provider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def __init__(self, exec_config, cwd):
5353
value = item['value']
5454
additional_vars[name] = value
5555
self.env.update(additional_vars)
56-
56+
5757
self.cwd = cwd or None
5858

5959
def run(self, previous_response=None):
60-
is_interactive = sys.stdout.isatty()
60+
is_interactive = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
6161
kubernetes_exec_info = {
6262
'apiVersion': self.api_version,
6363
'kind': 'ExecCredential',

kubernetes/base/config/exec_provider_test.py

+13
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ def test_run_in_dir(self, mock):
149149
ep.run()
150150
self.assertEqual(mock.call_args[1]['cwd'], '/some/directory')
151151

152+
@mock.patch('subprocess.Popen')
153+
def test_ok_no_console_attached(self, mock):
154+
instance = mock.return_value
155+
instance.wait.return_value = 0
156+
instance.communicate.return_value = (self.output_ok, '')
157+
mock_stdout = unittest.mock.patch(
158+
'sys.stdout', new=None) # Simulate detached console
159+
with mock_stdout:
160+
ep = ExecProvider(self.input_ok, None)
161+
result = ep.run()
162+
self.assertTrue(isinstance(result, dict))
163+
self.assertTrue('token' in result)
164+
152165

153166
if __name__ == '__main__':
154167
unittest.main()

0 commit comments

Comments
 (0)