Repository: Azure/WALinuxAgent (python)

Issue:
Extension install failures timeout
The Windows GA reports a status which allows a fast failure, however the Linux GA just reports 'Not ready' which essentially waits for a CRP timeout. We should investigate if there is a substatus we are missing to allow a fast failure. 

Pull request description:
translate bad status values to a correct one
Closes #1002 

Patch:
diff --git a/azurelinuxagent/ga/exthandlers.py b/azurelinuxagent/ga/exthandlers.py
index 91285cf9..024c7f55 100644
--- a/azurelinuxagent/ga/exthandlers.py
+++ b/azurelinuxagent/ga/exthandlers.py
@@ -56,6 +56,7 @@ from azurelinuxagent.common.version import AGENT_NAME, CURRENT_VERSION
 # HandlerEnvironment.json schema version
 HANDLER_ENVIRONMENT_VERSION = 1.0
 
+EXTENSION_STATUS_ERROR = 'error'
 VALID_EXTENSION_STATUS = ['transitioning', 'error', 'success', 'warning']
 
 VALID_HANDLER_STATUS = ['Ready', 'NotReady', "Installing", "Unresponsive"]
@@ -107,14 +108,15 @@ def parse_ext_status(ext_status, data):
     validate_has_key(data, 'status', 'status')
     status_data = data['status']
     validate_has_key(status_data, 'status', 'status/status')
-    
-    validate_in_range(status_data['status'], VALID_EXTENSION_STATUS,
-                      'status/status')
+
+    status = status_data['status']
+    if status not in VALID_EXTENSION_STATUS:
+        status = EXTENSION_STATUS_ERROR
 
     applied_time = status_data.get('configurationAppliedTime')
     ext_status.configurationAppliedTime = applied_time
     ext_status.operation = status_data.get('operation')
-    ext_status.status = status_data.get('status')
+    ext_status.status = status
     ext_status.code = status_data.get('code', 0)
     formatted_message = status_data.get('formattedMessage')
     ext_status.message = parse_formatted_message(formatted_message)


Test patch:
diff --git a/tests/ga/test_exthandlers.py b/tests/ga/test_exthandlers.py
new file mode 100644
index 00000000..248750b1
--- /dev/null
+++ b/tests/ga/test_exthandlers.py
@@ -0,0 +1,74 @@
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the Apache License.
+import json
+
+from azurelinuxagent.common.protocol.restapi import ExtensionStatus
+from azurelinuxagent.ga.exthandlers import parse_ext_status
+from tests.tools import *
+
+
+class TestExtHandlers(AgentTestCase):
+    def test_parse_extension_status00(self):
+        """
+        Parse a status report for a successful execution of an extension.
+        """
+
+        s = '''[{
+    "status": {
+      "status": "success",
+      "formattedMessage": {
+        "lang": "en-US",
+        "message": "Command is finished."
+      },
+      "operation": "Daemon",
+      "code": "0",
+      "name": "Microsoft.OSTCExtensions.CustomScriptForLinux"
+    },
+    "version": "1.0",
+    "timestampUTC": "2018-04-20T21:20:24Z"
+  }
+]'''
+        ext_status = ExtensionStatus(seq_no=0)
+        parse_ext_status(ext_status, json.loads(s))
+
+        self.assertEqual('0', ext_status.code)
+        self.assertEqual(None, ext_status.configurationAppliedTime)
+        self.assertEqual('Command is finished.', ext_status.message)
+        self.assertEqual('Daemon', ext_status.operation)
+        self.assertEqual('success', ext_status.status)
+        self.assertEqual(0, ext_status.sequenceNumber)
+        self.assertEqual(0, len(ext_status.substatusList))
+
+    def test_parse_extension_status01(self):
+        """
+        Parse a status report for a failed execution of an extension.
+
+        The extension returned a bad status/status of failed.
+        The agent should handle this gracefully, and convert all unknown
+        status/status values into an error.
+        """
+
+        s = '''[{
+    "status": {
+      "status": "failed",
+      "formattedMessage": {
+        "lang": "en-US",
+        "message": "Enable failed: Failed with error: commandToExecute is empty or invalid ..."
+      },
+      "operation": "Enable",
+      "code": "0",
+      "name": "Microsoft.OSTCExtensions.CustomScriptForLinux"
+    },
+    "version": "1.0",
+    "timestampUTC": "2018-04-20T20:50:22Z"
+}]'''
+        ext_status = ExtensionStatus(seq_no=0)
+        parse_ext_status(ext_status, json.loads(s))
+
+        self.assertEqual('0', ext_status.code)
+        self.assertEqual(None, ext_status.configurationAppliedTime)
+        self.assertEqual('Enable failed: Failed with error: commandToExecute is empty or invalid ...', ext_status.message)
+        self.assertEqual('Enable', ext_status.operation)
+        self.assertEqual('error', ext_status.status)
+        self.assertEqual(0, ext_status.sequenceNumber)
+        self.assertEqual(0, len(ext_status.substatusList))