From 54922366f472bf2891648ff479feb1b681ec593a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Tue, 7 Jul 2020 10:48:02 +0200 Subject: [PATCH 1/4] Fix warning about incompatible plugins --- airflow/plugins_manager.py | 2 +- tests/plugins/test_plugins_manager.py | 134 +++++++++++++++++++------- 2 files changed, 98 insertions(+), 38 deletions(-) diff --git a/airflow/plugins_manager.py b/airflow/plugins_manager.py index 8232c5599486e..21af5f1c48ffe 100644 --- a/airflow/plugins_manager.py +++ b/airflow/plugins_manager.py @@ -273,7 +273,7 @@ def initialize_web_ui_plugins(): 'blueprint': bp } for bp in plugin.flask_blueprints]) - if (admin_views and not flask_appbuilder_views) or (menu_links and flask_appbuilder_menu_links): + if (admin_views and not flask_appbuilder_views) or (menu_links and not flask_appbuilder_menu_links): log.warning( "Plugin \'%s\' may not be compatible with the current Airflow version. " "Please contact the author of the plugin.", diff --git a/tests/plugins/test_plugins_manager.py b/tests/plugins/test_plugins_manager.py index 253278960cccd..9f81482fdb47f 100644 --- a/tests/plugins/test_plugins_manager.py +++ b/tests/plugins/test_plugins_manager.py @@ -21,6 +21,7 @@ from airflow.hooks.base_hook import BaseHook from airflow.plugins_manager import AirflowPlugin from airflow.www import app as application +from tests.test_utils.mock_plugins import mock_plugin_manager class TestPluginsRBAC(unittest.TestCase): @@ -94,59 +95,53 @@ def test_entrypoint_plugin_errors_dont_raise_exceptions(self, mock_ep_plugins): class TestPluginsManager(unittest.TestCase): - class AirflowTestPropertyPlugin(AirflowPlugin): - name = "test_property_plugin" + def test_should_load_plugins_from_property(self): + class AirflowTestPropertyPlugin(AirflowPlugin): + name = "test_property_plugin" + + @property + def operators(self): + from airflow.models.baseoperator import BaseOperator - @property - def operators(self): - from airflow.models.baseoperator import BaseOperator + class PluginPropertyOperator(BaseOperator): + pass - class PluginPropertyOperator(BaseOperator): + return [PluginPropertyOperator] + + class TestNonPropertyHook(BaseHook): pass - return [PluginPropertyOperator] + hooks = [TestNonPropertyHook] - class TestNonPropertyHook(BaseHook): - pass + with mock_plugin_manager(plugins=[AirflowTestPropertyPlugin()]): + from airflow import plugins_manager + plugins_manager.integrate_dag_plugins() - hooks = [TestNonPropertyHook] + self.assertIn('AirflowTestPropertyPlugin', str(plugins_manager.plugins)) + self.assertIn('PluginPropertyOperator', str(plugins_manager.operators_modules[0].__dict__)) + self.assertIn("TestNonPropertyHook", str(plugins_manager.hooks_modules[0].__dict__)) - @mock.patch('airflow.plugins_manager.plugins', [AirflowTestPropertyPlugin()]) - @mock.patch('airflow.plugins_manager.operators_modules', None) - @mock.patch('airflow.plugins_manager.sensors_modules', None) - @mock.patch('airflow.plugins_manager.hooks_modules', None) - @mock.patch('airflow.plugins_manager.macros_modules', None) - def test_should_load_plugins_from_property(self): - from airflow import plugins_manager - plugins_manager.integrate_dag_plugins() - self.assertIn('TestPluginsManager.AirflowTestPropertyPlugin', str(plugins_manager.plugins)) - self.assertIn('PluginPropertyOperator', str(plugins_manager.operators_modules[0].__dict__)) - self.assertIn("TestNonPropertyHook", str(plugins_manager.hooks_modules[0].__dict__)) - - @mock.patch('airflow.plugins_manager.plugins', []) - @mock.patch('airflow.plugins_manager.admin_views', None) - @mock.patch('airflow.plugins_manager.flask_blueprints', None) - @mock.patch('airflow.plugins_manager.menu_links', None) - @mock.patch('airflow.plugins_manager.flask_appbuilder_views', None) - @mock.patch('airflow.plugins_manager.flask_appbuilder_menu_links', None) + @mock_plugin_manager(plugins=[]) def test_should_warning_about_incompatible_plugins(self): - class AirflowDeprecatedAdminViewsPlugin(AirflowPlugin): + class AirflowAdminViewsPlugin(AirflowPlugin): name = "test_admin_views_plugin" admin_views = [mock.MagicMock()] - class AirflowDeprecatedAdminMenuLinksPlugin(AirflowPlugin): + class AirflowAdminMenuLinksPlugin(AirflowPlugin): name = "test_menu_links_plugin" menu_links = [mock.MagicMock()] - from airflow import plugins_manager - plugins_manager.plugins = [ - AirflowDeprecatedAdminViewsPlugin(), - AirflowDeprecatedAdminMenuLinksPlugin() - ] - with self.assertLogs(plugins_manager.log) as cm: - plugins_manager.initialize_web_ui_plugins() + with mock_plugin_manager(plugins=[ + AirflowAdminViewsPlugin(), + AirflowAdminMenuLinksPlugin() + ]): + from airflow import plugins_manager + + # assert not logs + with self.assertLogs(plugins_manager.log) as cm: + plugins_manager.initialize_web_ui_plugins() self.assertEqual(cm.output, [ 'WARNING:airflow.plugins_manager:Plugin \'test_admin_views_plugin\' may not be ' @@ -156,3 +151,68 @@ class AirflowDeprecatedAdminMenuLinksPlugin(AirflowPlugin): 'compatible with the current Airflow version. Please contact the author of ' 'the plugin.' ]) + + def test_should_not_warning_about_compatible_plugins(self): + class AirflowAdminViewsPlugin(AirflowPlugin): + name = "test_admin_views_plugin" + + appbuilder_views = [mock.MagicMock()] + + class AirflowAdminMenuLinksPlugin(AirflowPlugin): + name = "test_menu_links_plugin" + + appbuilder_menu_items = [mock.MagicMock()] + + with mock_plugin_manager(plugins=[ + AirflowAdminViewsPlugin(), + AirflowAdminMenuLinksPlugin() + ]): + from airflow import plugins_manager + + # assert not logs + with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): + plugins_manager.initialize_web_ui_plugins() + + def test_should_not_warning_about_fab_plugins(self): + class AirflowAdminViewsPlugin(AirflowPlugin): + name = "test_admin_views_plugin" + + appbuilder_views = [mock.MagicMock()] + + class AirflowAdminMenuLinksPlugin(AirflowPlugin): + name = "test_menu_links_plugin" + + appbuilder_menu_items = [mock.MagicMock()] + + with mock_plugin_manager(plugins=[ + AirflowAdminViewsPlugin(), + AirflowAdminMenuLinksPlugin() + ]): + from airflow import plugins_manager + + # assert not logs + with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): + plugins_manager.initialize_web_ui_plugins() + + def test_should_not_warning_about_fab_and_flask_admin_plugins(self): + class AirflowAdminViewsPlugin(AirflowPlugin): + name = "test_admin_views_plugin" + + admin_views = [mock.MagicMock()] + appbuilder_views = [mock.MagicMock()] + + class AirflowAdminMenuLinksPlugin(AirflowPlugin): + name = "test_menu_links_plugin" + + menu_links = [mock.MagicMock()] + appbuilder_menu_items = [mock.MagicMock()] + + with mock_plugin_manager(plugins=[ + AirflowAdminViewsPlugin(), + AirflowAdminMenuLinksPlugin() + ]): + from airflow import plugins_manager + + # assert not logs + with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): + plugins_manager.initialize_web_ui_plugins() From 6e9738f4fae67619b11acc1fb3d258fbd360e5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Tue, 7 Jul 2020 10:58:22 +0200 Subject: [PATCH 2/4] fixup! Fix warning about incompatible plugins --- tests/plugins/test_plugins_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/test_plugins_manager.py b/tests/plugins/test_plugins_manager.py index 9f81482fdb47f..2ecfd8189bf87 100644 --- a/tests/plugins/test_plugins_manager.py +++ b/tests/plugins/test_plugins_manager.py @@ -152,7 +152,7 @@ class AirflowAdminMenuLinksPlugin(AirflowPlugin): 'the plugin.' ]) - def test_should_not_warning_about_compatible_plugins(self): + def test_should_not_warning_about_fab_plugins(self): class AirflowAdminViewsPlugin(AirflowPlugin): name = "test_admin_views_plugin" From a37798992d4b74ccd4d341e322c37ab3115211d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Tue, 7 Jul 2020 11:20:10 +0200 Subject: [PATCH 3/4] fixup! fixup! Fix warning about incompatible plugins --- tests/plugins/test_plugins_manager.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/plugins/test_plugins_manager.py b/tests/plugins/test_plugins_manager.py index 2ecfd8189bf87..ea8a1328092a8 100644 --- a/tests/plugins/test_plugins_manager.py +++ b/tests/plugins/test_plugins_manager.py @@ -173,27 +173,6 @@ class AirflowAdminMenuLinksPlugin(AirflowPlugin): with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): plugins_manager.initialize_web_ui_plugins() - def test_should_not_warning_about_fab_plugins(self): - class AirflowAdminViewsPlugin(AirflowPlugin): - name = "test_admin_views_plugin" - - appbuilder_views = [mock.MagicMock()] - - class AirflowAdminMenuLinksPlugin(AirflowPlugin): - name = "test_menu_links_plugin" - - appbuilder_menu_items = [mock.MagicMock()] - - with mock_plugin_manager(plugins=[ - AirflowAdminViewsPlugin(), - AirflowAdminMenuLinksPlugin() - ]): - from airflow import plugins_manager - - # assert not logs - with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): - plugins_manager.initialize_web_ui_plugins() - def test_should_not_warning_about_fab_and_flask_admin_plugins(self): class AirflowAdminViewsPlugin(AirflowPlugin): name = "test_admin_views_plugin" From 7cf6ec055cb55e767cf87bbe74a32c1f96162079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Thu, 9 Jul 2020 14:07:09 +0200 Subject: [PATCH 4/4] fixup! fixup! fixup! Fix warning about incompatible plugins --- tests/plugins/test_plugins_manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/plugins/test_plugins_manager.py b/tests/plugins/test_plugins_manager.py index ea8a1328092a8..8184f8c1079ac 100644 --- a/tests/plugins/test_plugins_manager.py +++ b/tests/plugins/test_plugins_manager.py @@ -121,7 +121,6 @@ class TestNonPropertyHook(BaseHook): self.assertIn('PluginPropertyOperator', str(plugins_manager.operators_modules[0].__dict__)) self.assertIn("TestNonPropertyHook", str(plugins_manager.hooks_modules[0].__dict__)) - @mock_plugin_manager(plugins=[]) def test_should_warning_about_incompatible_plugins(self): class AirflowAdminViewsPlugin(AirflowPlugin): name = "test_admin_views_plugin"