You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/03/23 12:29:49 UTC

[airflow] branch v1-10-stable updated: Upgrade rule to suggest to rename max_threads to parsing_processes (#14913)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-stable
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v1-10-stable by this push:
     new 42dafd2  Upgrade rule to suggest to rename max_threads to parsing_processes (#14913)
42dafd2 is described below

commit 42dafd2b018713abdb7af5f288ff6cc11bc06d8d
Author: Marian Cepok <ma...@gmail.com>
AuthorDate: Tue Mar 23 13:29:28 2021 +0100

    Upgrade rule to suggest to rename max_threads to parsing_processes (#14913)
    
    This adds an upgrade rule as described in #12672 to rename the max_threads configuration to parsing_processes.
    
    I created this rule on the example of the LoggingConfigurationRule, which doesn't suggest any changes if the old configuration exists but has the default value. I assume, that the idea behind this is, that if the configuration is not set by the user, a default configuration is taken. However, if a user explicitly copied the default configuration in his or her own configuration, in my opinion, a change should be suggested but isn't. But maybe I misunderstood something.
    
    closes #12672
---
 .../rules/parsing_processes_configuration_rule.py  | 41 ++++++++++++++++++
 .../test_parsing_processes_configuration_rule.py   | 50 ++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/airflow/upgrade/rules/parsing_processes_configuration_rule.py b/airflow/upgrade/rules/parsing_processes_configuration_rule.py
new file mode 100644
index 0000000..9ba3c86
--- /dev/null
+++ b/airflow/upgrade/rules/parsing_processes_configuration_rule.py
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import absolute_import
+
+from airflow.configuration import conf
+from airflow.upgrade.rules.base_rule import BaseRule
+
+
+class ParsingProcessesConfigurationRule(BaseRule):
+    title = "Rename max_threads to parsing_processes"
+
+    description = "The max_threads configuration in the [scheduler] section was renamed to parsing_processes."
+
+    def check(self):
+        default = 2
+
+        old_config_exists = conf.has_option("scheduler", "max_threads")
+        new_config_exists = conf.has_option("scheduler", "parsing_processes")
+
+        if old_config_exists and not new_config_exists:
+            old_config_value = conf.get("scheduler", "max_threads")
+            if old_config_value == default:
+                return None
+            return ["Please rename the max_threads configuration in the "
+                    "[scheduler] section to parsing_processes."]
+        return None
diff --git a/tests/upgrade/rules/test_parsing_processes_configuration_rule.py b/tests/upgrade/rules/test_parsing_processes_configuration_rule.py
new file mode 100644
index 0000000..8e27eb8
--- /dev/null
+++ b/tests/upgrade/rules/test_parsing_processes_configuration_rule.py
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from unittest import TestCase
+from unittest.mock import patch
+
+from airflow.upgrade.rules.parsing_processes_configuration_rule import ParsingProcessesConfigurationRule
+
+
+class TestParsingProcessesConfigurationRule(TestCase):
+    @patch('airflow.configuration.conf.has_option')
+    def test_check_new_config(self, conf_has_option):
+        rule = ParsingProcessesConfigurationRule()
+
+        assert isinstance(rule.description, str)
+        assert isinstance(rule.title, str)
+
+        conf_has_option.side_effect = [False, True]
+
+        response = rule.check()
+        assert response is None
+
+    @patch('airflow.configuration.conf.get')
+    @patch('airflow.configuration.conf.has_option')
+    def test_check_old_config(self, conf_has_option, conf_get):
+        rule = ParsingProcessesConfigurationRule()
+
+        assert isinstance(rule.description, str)
+        assert isinstance(rule.title, str)
+
+        conf_has_option.side_effect = [True, False]
+        conf_get.side_effect = ["DUMMY"]
+
+        response = rule.check()
+        assert response == \
+               ["Please rename the max_threads configuration in the "
+                "[scheduler] section to parsing_processes."]