Update local runner to throw / return a user-friendly error message in
case invalid sudo password is provided or sudo is not configured for
that user.
# limitations under the License.
import os
+import re
import pwd
import uuid
import functools
@@ -200,6 +201,20 @@ class LocalShellRunner(ActionRunner, ShellRunnerMixin):
error = 'Action failed to complete in %s seconds' % (self._timeout)
exit_code = -1 * exit_code_constants.SIGKILL_EXIT_CODE
+ # Detect if user provided an invalid sudo password or sudo is not configured for that user
+ if self._sudo_password:
+ if re.search('sudo: \d+ incorrect password attempts', stderr):
+ match = re.search('\[sudo\] password for (.+?)\:', stderr)
+
+ if match:
+ username = match.groups()[0]
+ else:
+ username = 'unknown'
+
+ error = ('Invalid sudo password provided or sudo is not configured for this user '
+ '(%s)' % (username))
+ exit_code = -1
+
succeeded = (exit_code == exit_code_constants.SUCCESS_EXIT_CODE)
result = {
