airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From san...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1121][AIRFLOW-1004] Fix `airflow webserver --pid` to write out pid file
Date Wed, 19 Apr 2017 19:32:04 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 0406462dc -> 8d643897c


[AIRFLOW-1121][AIRFLOW-1004] Fix `airflow webserver --pid` to write out pid file

After AIRFLOW-1004, --pid option is no longer
honored and
the pid file is not being written out. This PR
fixes it.

Closes #2249 from sekikn/AIRFLOW-1121


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

Branch: refs/heads/master
Commit: 8d643897cf6171d110e7139fb31c3d4d47c3acca
Parents: 0406462
Author: Kengo Seki <sekikn@apache.org>
Authored: Wed Apr 19 12:31:10 2017 -0700
Committer: Siddharth Anand <siddharthanand@yahoo.com>
Committed: Wed Apr 19 12:31:10 2017 -0700

----------------------------------------------------------------------
 airflow/bin/cli.py |  3 ++-
 tests/core.py      | 36 ++++++++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/8d643897/airflow/bin/cli.py
----------------------------------------------------------------------
diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py
index e4755c7..8e92ea1 100755
--- a/airflow/bin/cli.py
+++ b/airflow/bin/cli.py
@@ -776,6 +776,7 @@ def webserver(args):
             '-t', str(worker_timeout),
             '-b', args.hostname + ':' + str(args.port),
             '-n', 'airflow-webserver',
+            '-p', str(pid),
             '-c', 'airflow.www.gunicorn_config'
         ]
 
@@ -786,7 +787,7 @@ def webserver(args):
             run_args += ['--error-logfile', str(args.error_logfile)]
 
         if args.daemon:
-            run_args += ['-D', '-p', str(pid)]
+            run_args += ['-D']
 
         if ssl_cert:
             run_args += ['--certfile', ssl_cert, '--keyfile', ssl_key]

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/8d643897/tests/core.py
----------------------------------------------------------------------
diff --git a/tests/core.py b/tests/core.py
index 353b847..5b18a18 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -1431,6 +1431,14 @@ class CliTests(unittest.TestCase):
         os.remove('variables1.json')
         os.remove('variables2.json')
 
+    def _wait_pidfile(self, pidfile):
+        while True:
+            try:
+                with open(pidfile) as f:
+                    return int(f.read())
+            except:
+                sleep(1)
+
     def test_cli_webserver_foreground(self):
         import subprocess
 
@@ -1450,18 +1458,26 @@ class CliTests(unittest.TestCase):
 
     @unittest.skipIf("TRAVIS" in os.environ and bool(os.environ["TRAVIS"]),
                      "Skipping test due to lack of required file permission")
+    def test_cli_webserver_foreground_with_pid(self):
+        import subprocess
+
+        # Run webserver in foreground with --pid option
+        pidfile = tempfile.mkstemp()[1]
+        p = subprocess.Popen(["airflow", "webserver", "--pid", pidfile])
+
+        # Check the file specified by --pid option exists
+        self._wait_pidfile(pidfile)
+
+        # Terminate webserver
+        p.terminate()
+        p.wait()
+
+    @unittest.skipIf("TRAVIS" in os.environ and bool(os.environ["TRAVIS"]),
+                     "Skipping test due to lack of required file permission")
     def test_cli_webserver_background(self):
         import subprocess
         import psutil
 
-        def wait_pidfile(pidfile):
-            while True:
-                try:
-                    with open(pidfile) as f:
-                        return int(f.read())
-                except IOError:
-                    sleep(1)
-
         # Confirm that webserver hasn't been launched.
         self.assertEqual(1, subprocess.Popen(["pgrep", "-c", "airflow"]).wait())
         self.assertEqual(1, subprocess.Popen(["pgrep", "-c", "gunicorn"]).wait())
@@ -1469,7 +1485,7 @@ class CliTests(unittest.TestCase):
         # Run webserver in background.
         subprocess.Popen(["airflow", "webserver", "-D"])
         pidfile = cli.setup_locations("webserver")[0]
-        wait_pidfile(pidfile)
+        self._wait_pidfile(pidfile)
 
         # Assert that gunicorn and its monitor are launched.
         self.assertEqual(0, subprocess.Popen(["pgrep", "-c", "airflow"]).wait())
@@ -1477,7 +1493,7 @@ class CliTests(unittest.TestCase):
 
         # Terminate monitor process.
         pidfile = cli.setup_locations("webserver-monitor")[0]
-        pid = wait_pidfile(pidfile)
+        pid = self._wait_pidfile(pidfile)
         p = psutil.Process(pid)
         p.terminate()
         p.wait()


Mime
View raw message