diff --git a/package/cloudshell/cm/customscript/domain/linux_script_executor.py b/package/cloudshell/cm/customscript/domain/linux_script_executor.py index d26ef52..c6311c2 100644 --- a/package/cloudshell/cm/customscript/domain/linux_script_executor.py +++ b/package/cloudshell/cm/customscript/domain/linux_script_executor.py @@ -47,8 +47,10 @@ def connect(self): key_stream = StringIO(self.target_host.access_key) key_obj = RSAKey.from_private_key(key_stream) self.session.connect(self.target_host.ip, username=self.target_host.username, pkey=key_obj) - else: + elif self.target_host.username: raise Exception('Both password and access key are empty.') + else: + raise Exception('Machine credentials are empty.') except NoValidConnectionsError as e: error_code = next(e.errors.itervalues(), type('e', (object,), {'errno': 0})).errno raise ExcutorConnectionError(error_code, e) diff --git a/package/tests/test_linux_script_executor.py b/package/tests/test_linux_script_executor.py index 4014a93..454f7ad 100644 --- a/package/tests/test_linux_script_executor.py +++ b/package/tests/test_linux_script_executor.py @@ -64,6 +64,12 @@ def test_no_password_nor_pen_file(self): executor.connect() self.assertEqual('Both password and access key are empty.', e.exception.inner_error.message) + def test_no_password_no_pen_file_no_username(self): + executor = LinuxScriptExecutor(self.logger, self.host, self.cancel_sampler) + with self.assertRaises(Exception) as e: + executor.connect() + self.assertEqual('Machine credentials are empty.', e.exception.inner_error.message) + def test_create_temp_folder_success(self): self._mock_session_answer(0,'tmp123','') result = self.executor.create_temp_folder()