forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create HostnameCallableRule to ease upgrade to Airflow 2.0 (apache#12743
) Creates a rule to ensure users have a 2.0 compatible hostname_callable configuration in their airflow.cfg closes apache#11044 Co-authored-by: Ash Berlin-Taylor <[email protected]> Co-authored-by: Kaxil Naik <[email protected]>
- Loading branch information
1 parent
0dcf33a
commit 9257b1c
Showing
4 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters