airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@apache.org
Subject [1/2] incubator-airflow git commit: [AIRFLOW-1325] Add ElasticSearch log handler and reader
Date Fri, 13 Apr 2018 09:09:57 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 34f827f04 -> ec38ba959


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/ec38ba95/tests/utils/log/test_s3_task_handler.py
----------------------------------------------------------------------
diff --git a/tests/utils/log/test_s3_task_handler.py b/tests/utils/log/test_s3_task_handler.py
index 53c1e36..5908022 100644
--- a/tests/utils/log/test_s3_task_handler.py
+++ b/tests/utils/log/test_s3_task_handler.py
@@ -108,8 +108,8 @@ class TestS3TaskHandler(unittest.TestCase):
         self.conn.put_object(Bucket='bucket', Key=self.remote_log_key, Body=b'Log line\n')
         self.assertEqual(
             self.s3_task_handler.read(self.ti),
-            ['*** Reading remote log from s3://bucket/remote/log/location/1.log.\n'
-             'Log line\n\n']
+            (['*** Reading remote log from s3://bucket/remote/log/location/1.log.\n'
+             'Log line\n\n'], [{'end_of_log': True}])
         )
 
     def test_read_raises_return_error(self):
@@ -155,7 +155,7 @@ class TestS3TaskHandler(unittest.TestCase):
         boto3.resource('s3').Object('bucket', self.remote_log_key).get()
 
     def test_close_no_upload(self):
-        self.ti.is_raw = True
+        self.ti.raw = True
         self.s3_task_handler.set_context(self.ti)
         self.assertFalse(self.s3_task_handler.upload_on_close)
         self.s3_task_handler.close()

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/ec38ba95/tests/utils/test_log_handlers.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_log_handlers.py b/tests/utils/test_log_handlers.py
index b4a9ae2..6759074 100644
--- a/tests/utils/test_log_handlers.py
+++ b/tests/utils/test_log_handlers.py
@@ -91,10 +91,13 @@ class TestFileTaskLogHandler(unittest.TestCase):
         file_handler.close()
 
         self.assertTrue(hasattr(file_handler, 'read'))
-        # Return value of read must be a list.
-        logs = file_handler.read(ti)
+        # Return value of read must be a tuple of list and list.
+        logs, metadatas = file_handler.read(ti)
         self.assertTrue(isinstance(logs, list))
+        self.assertTrue(isinstance(metadatas, list))
         self.assertEqual(len(logs), 1)
+        self.assertEqual(len(logs), len(metadatas))
+        self.assertTrue(isinstance(metadatas[0], dict))
         target_re = r'\n\[[^\]]+\] {test_log_handlers.py:\d+} INFO - test\n'
 
         # We should expect our log line from the callable above to appear in
@@ -139,11 +142,15 @@ class TestFileTaskLogHandler(unittest.TestCase):
 
         logger.info("Test")
 
-        # Return value of read must be a list.
-        logs = file_handler.read(ti)
+        # Return value of read must be a tuple of list and list.
+        logs, metadatas = file_handler.read(ti)
         self.assertTrue(isinstance(logs, list))
         # Logs for running tasks should show up too.
+        self.assertTrue(isinstance(logs, list))
+        self.assertTrue(isinstance(metadatas, list))
         self.assertEqual(len(logs), 2)
+        self.assertEqual(len(logs), len(metadatas))
+        self.assertTrue(isinstance(metadatas[0], dict))
 
         # Remove the generated tmp log file.
         os.remove(log_filename)

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/ec38ba95/tests/www/test_views.py
----------------------------------------------------------------------
diff --git a/tests/www/test_views.py b/tests/www/test_views.py
index 9461f9f..b674352 100644
--- a/tests/www/test_views.py
+++ b/tests/www/test_views.py
@@ -20,7 +20,9 @@ import shutil
 import tempfile
 import unittest
 import sys
+import json
 
+from urllib.parse import quote_plus
 from werkzeug.test import Client
 
 from airflow import models, configuration, settings
@@ -377,9 +379,24 @@ class TestLogView(unittest.TestCase):
             follow_redirects=True,
         )
         self.assertEqual(response.status_code, 200)
-        self.assertIn('Log file does not exist',
+        self.assertIn('Log by attempts',
                       response.data.decode('utf-8'))
 
+    def test_get_logs_with_metadata(self):
+        url_template = "/admin/airflow/get_logs_with_metadata?dag_id={}&" \
+                       "task_id={}&execution_date={}&" \
+                       "try_number={}&metadata={}"
+        response = \
+            self.app.get(url_template.format(self.DAG_ID,
+                                             self.TASK_ID,
+                                             quote_plus(self.DEFAULT_DATE.isoformat()),
+                                             1,
+                                             json.dumps({})))
+
+        self.assertIn('"message":', response.data.decode('utf-8'))
+        self.assertIn('"metadata":', response.data.decode('utf-8'))
+        self.assertEqual(200, response.status_code)
+
 
 class TestVarImportView(unittest.TestCase):
 


Mime
View raw message