def test_write_raises(self):
        handler = WasbTaskHandler(
            self.local_log_location, self.wasb_log_folder, self.container_name, self.filename_template, True
        )
        with mock.patch.object(handler.log, 'error') as mock_error:
            with mock.patch("airflow.providers.microsoft.azure.hooks.wasb.WasbHook") as mock_hook:
                mock_hook.return_value.load_string.side_effect = AzureHttpError("failed to connect", 404)

                handler.wasb_write('text', self.remote_log_location, append=False)

            mock_error.assert_called_once_with(
                'Could not write logs to %s', 'remote/log/location/1.log', exc_info=True
            )
    def test_hook_raises(self):
        handler = WasbTaskHandler(
            self.local_log_location, self.wasb_log_folder, self.container_name, self.filename_template, True
        )
        with mock.patch.object(handler.log, 'error') as mock_error:
            with mock.patch("airflow.providers.microsoft.azure.hooks.wasb.WasbHook") as mock_hook:
                mock_hook.side_effect = AzureHttpError("failed to connect", 404)
                # Initialize the hook
                handler.hook

            mock_error.assert_called_once_with(
                'Could not create an WasbHook with connection id "%s". '
                'Please make sure that airflow[azure] is installed and '
                'the Wasb connection exists.',
                "wasb_default",
            )
Ejemplo n.º 3
0
    def test_wasb_read_raises(self):
        handler = WasbTaskHandler(self.local_log_location,
                                  self.wasb_log_folder, self.container_name,
                                  self.filename_template, True)
        with mock.patch.object(handler.log, 'error') as mock_error:
            with mock.patch(
                    "airflow.providers.microsoft.azure.hooks.wasb.WasbHook"
            ) as mock_hook:
                mock_hook.return_value.read_file.side_effect = AzureHttpError(
                    "failed to connect", 404)

                handler.wasb_read(self.remote_log_location, return_error=True)
            mock_error.assert_called_once_with(
                "Message: '%s', exception '%s'",
                'Could not read logs from remote/log/location/1.log',
                ANY,
                exc_info=True,
            )
    def setUp(self):
        super().setUp()
        self.wasb_log_folder = 'wasb://container/remote/log/location'
        self.remote_log_location = 'remote/log/location/1.log'
        self.local_log_location = 'local/log/location'
        self.container_name = "wasb-container"
        self.filename_template = '{try_number}.log'
        self.wasb_task_handler = WasbTaskHandler(
            base_log_folder=self.local_log_location,
            wasb_log_folder=self.wasb_log_folder,
            wasb_container=self.container_name,
            filename_template=self.filename_template,
            delete_local_copy=True,
        )

        date = datetime(2020, 8, 10)
        self.dag = DAG('dag_for_testing_file_task_handler', start_date=date)
        task = DummyOperator(task_id='task_for_testing_file_log_handler', dag=self.dag)
        self.ti = TaskInstance(task=task, execution_date=date)
        self.ti.try_number = 1
        self.ti.state = State.RUNNING
        self.addCleanup(self.dag.clear)