You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bo...@apache.org on 2017/09/19 13:34:22 UTC

incubator-airflow git commit: [AIRFLOW-1591] Avoid attribute error when rendering logging filename

Repository: incubator-airflow
Updated Branches:
  refs/heads/master ec33ff8f0 -> 6e520704f


[AIRFLOW-1591] Avoid attribute error when rendering logging filename

Closes #2578 from mrkm4ntr/airflow-1564


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/6e520704
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/6e520704
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/6e520704

Branch: refs/heads/master
Commit: 6e520704f6a5d105c95fcb8e5a7ec06b61e0f002
Parents: ec33ff8
Author: Shintaro Murakami <mr...@gmail.com>
Authored: Tue Sep 19 15:34:06 2017 +0200
Committer: Bolke de Bruin <bo...@xs4all.nl>
Committed: Tue Sep 19 15:34:06 2017 +0200

----------------------------------------------------------------------
 .gitignore                                      |  2 +-
 airflow/www/views.py                            |  1 +
 .../2017-09-01T00:00:00/1.log                   |  1 +
 tests/www/test_views.py                         | 75 +++++++++++++++++++-
 4 files changed, 76 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/6e520704/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 8efe3ae..254ad15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,7 +68,7 @@ coverage.xml
 *.pot
 
 # Django stuff:
-*.log
+# *.log
 local_settings.py
 
 # Flask stuff:

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/6e520704/airflow/www/views.py
----------------------------------------------------------------------
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 829167f..e879922 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -706,6 +706,7 @@ class Airflow(BaseView):
             handler = next((handler for handler in logger.handlers
                             if handler.name == task_log_reader), None)
             try:
+                ti.task = dag.get_task(ti.task_id)
                 logs = handler.read(ti)
             except AttributeError as e:
                 logs = ["Task log handler {} does not support read logs.\n{}\n" \

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/6e520704/tests/www/test_logs/dag_for_testing_log_view/task_for_testing_log_view/2017-09-01T00:00:00/1.log
----------------------------------------------------------------------
diff --git a/tests/www/test_logs/dag_for_testing_log_view/task_for_testing_log_view/2017-09-01T00:00:00/1.log b/tests/www/test_logs/dag_for_testing_log_view/task_for_testing_log_view/2017-09-01T00:00:00/1.log
new file mode 100644
index 0000000..bc10ef7
--- /dev/null
+++ b/tests/www/test_logs/dag_for_testing_log_view/task_for_testing_log_view/2017-09-01T00:00:00/1.log
@@ -0,0 +1 @@
+Log for testing.

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/6e520704/tests/www/test_views.py
----------------------------------------------------------------------
diff --git a/tests/www/test_views.py b/tests/www/test_views.py
index 9147b22..83bdc44 100644
--- a/tests/www/test_views.py
+++ b/tests/www/test_views.py
@@ -13,11 +13,17 @@
 # limitations under the License.
 
 import unittest
+import logging.config
+import os
+import copy
+from datetime import datetime
 
-from airflow import configuration
-from airflow import models
+from airflow import models, configuration, settings
+from airflow.models import DAG, TaskInstance
 from airflow.settings import Session
 from airflow.www import app as application
+from airflow.operators.dummy_operator import DummyOperator
+from airflow.config_templates.default_airflow_logging import DEFAULT_LOGGING_CONFIG
 
 
 class TestChartModelView(unittest.TestCase):
@@ -288,5 +294,70 @@ class TestPoolModelView(unittest.TestCase):
         self.assertEqual(self.session.query(models.Pool).count(), 0)
 
 
+class TestLogView(unittest.TestCase):
+
+    DAG_ID = 'dag_for_testing_log_view'
+    TASK_ID = 'task_for_testing_log_view'
+    DEFAULT_DATE = datetime(2017, 9, 1)
+    ENDPOINT = '/admin/airflow/log?dag_id={dag_id}&task_id={task_id}&execution_date={execution_date}'.format(
+        dag_id=DAG_ID,
+        task_id=TASK_ID,
+        execution_date=DEFAULT_DATE,
+    )
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestLogView, cls).setUpClass()
+        session = Session()
+        session.query(TaskInstance).filter(
+            TaskInstance.dag_id == cls.DAG_ID and
+            TaskInstance.task_id == cls.TASK_ID and
+            TaskInstance.execution_date == cls.DEFAULT_DATE).delete()
+        session.commit()
+        session.close()
+
+    def setUp(self):
+        super(TestLogView, self).setUp()
+
+        configuration.load_test_config()
+        logging_config = copy.deepcopy(DEFAULT_LOGGING_CONFIG)
+        current_dir = os.path.dirname(os.path.abspath(__file__))
+        logging_config['handlers']['file.task']['base_log_folder'] = os.path.normpath(
+            os.path.join(current_dir, 'test_logs'))
+        logging.config.dictConfig(logging_config)
+
+        app = application.create_app(testing=True)
+        self.app = app.test_client()
+        self.session = Session()
+        from airflow.www.views import dagbag
+        dag = DAG(self.DAG_ID, start_date=self.DEFAULT_DATE)
+        task = DummyOperator(task_id=self.TASK_ID, dag=dag)
+        dagbag.bag_dag(dag, parent_dag=dag, root_dag=dag)
+        ti = TaskInstance(task=task, execution_date=self.DEFAULT_DATE)
+        ti.try_number = 1
+        self.session.merge(ti)
+        self.session.commit()
+
+    def tearDown(self):
+        logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
+        dagbag = models.DagBag(settings.DAGS_FOLDER)
+        self.session.query(TaskInstance).filter(
+            TaskInstance.dag_id == self.DAG_ID and
+            TaskInstance.task_id == self.TASK_ID and
+            TaskInstance.execution_date == self.DEFAULT_DATE).delete()
+        self.session.commit()
+        self.session.close()
+        super(TestLogView, self).tearDown()
+
+    def test_get_file_task_log(self):
+        response = self.app.get(
+            TestLogView.ENDPOINT,
+            follow_redirects=True,
+        )
+        self.assertEqual(response.status_code, 200)
+        self.assertIn('<pre id="attempt-1">*** Reading local log.\nLog for testing.\n</pre>',
+                      response.data.decode('utf-8'))
+
+
 if __name__ == '__main__':
     unittest.main()