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

dimberman pushed a commit to branch hostname-callable-rule
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit b00dcea2acc659e97f8e5147e13f5f3d3e5771a5
Author: Daniel Imberman <[email protected]>
AuthorDate: Tue Dec 1 10:09:32 2020 -0800

    Create HostnameCallableRule to ease upgrade to Airflow 2.0
    
    Creates a rule to ensure users have a 2.0 compatible hostname_callable
    configuration in their airflow.cfg
    
    addresses https://github.com/apache/airflow/issues/11044
---
 airflow/upgrade/rules/hostname_callable_rule.py    | 38 ++++++++++++++++++++++
 tests/upgrade/rules/test_hostname_callable_rule.py | 36 ++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/airflow/upgrade/rules/hostname_callable_rule.py 
b/airflow/upgrade/rules/hostname_callable_rule.py
new file mode 100644
index 0000000..537db5a
--- /dev/null
+++ b/airflow/upgrade/rules/hostname_callable_rule.py
@@ -0,0 +1,38 @@
+# 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 HostnameCallable(BaseRule):
+    title = "Unify hostname_callable option in core section"
+
+    description = ""
+
+    def check(self):
+        hostname_callable_conf = conf.get("core", "hostname_callable")
+        if ":" in hostname_callable_conf:
+            return (
+                "Error: hostname_callable {} "
+                "contains a colon instead of a dot. please change to 
{}".format(
+                    hostname_callable_conf, 
hostname_callable_conf.replace(":", ".")
+                )
+            )
+        return None
diff --git a/tests/upgrade/rules/test_hostname_callable_rule.py 
b/tests/upgrade/rules/test_hostname_callable_rule.py
new file mode 100644
index 0000000..e0cad7b
--- /dev/null
+++ b/tests/upgrade/rules/test_hostname_callable_rule.py
@@ -0,0 +1,36 @@
+# 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 airflow.upgrade.rules.hostname_callable_rule import HostnameCallable
+from tests.test_utils.config import conf_vars
+
+
+class TestFernetEnabledRule(TestCase):
+    @conf_vars({("core", "hostname_callable"): "dummyhostname:function"})
+    def test_incorrect_hostname(self):
+        result = HostnameCallable().check()
+        self.assertEqual(
+            result,
+            "Error: hostname_callable dummyhostname:function "
+            "contains a colon instead of a dot. please change to 
dummyhostname.function",
+        )
+
+    @conf_vars({("core", "hostname_callable"): "dummyhostname.function"})
+    def test_correct_hostname(self):
+        result = HostnameCallable().check()
+        self.assertEqual(result, None)

Reply via email to