У меня есть эта задача в потоке воздуха:
def bcp_in(**kwargs):
files = []
for file in glob.glob(Variable.get("temp_directory") + "FILEGROUP1/FILE*.csv"):
files.append(file)
print("LOCAL FILES {}".format(files))
for file in files:
print('Importing File {}'.format(file))
cmd = '/opt/mssql-tools/bin/bcp db1.dbo.table1 IN "{file}" -F2 -Utheuser -Pmypassword -Sserver1 -t"~" -c'.format(file=file)
print(subprocess.check_output(cmd))
BCP_Import_Files = PythonOperator(
task_id='BCP_Import_Files_to_DB3_Staging',
python_callable=bcp_in,
dag=dag
)
при условии, что пользователь, под которым работает поток воздуха, равен airflow
, я без проблем проверил bcp под этим пользователем в командной строке.
однако, когда я запускаю это при нормальных операциях с воздушным потоком, задача завершается с ошибкой:
2020-01-27 20:18:28,731] {taskinstance.py:1051} ERROR - [Errno 2] No such file or directory: '/opt/mssql-tools/bin/bcp db1.dbo.table1 IN "file1" -F2 -Utheuser -Pmypassword -Sserver1 -t"~" -c': '/opt/mssql-tools/bin/bcp db1.dbo.table1 IN "file1" -F2 -Utheuser -Pmypassword -Sserver1 -t"~" -c'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 926, in _run_raw_task
result = task_copy.execute(context=context)
File "/usr/local/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 113, in execute
return_value = self.execute_callable()
File "/usr/local/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 118, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/home/airflow/airflow/dags/BCP_TEST_NOT_PROD.py", line 30, in bcp_in
print(subprocess.check_output(cmd))
File "/usr/local/lib/python3.7/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/usr/local/lib/python3.7/subprocess.py", line 472, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/opt/mssql-tools/bin/bcp db1.dbo.table1 IN "file1" -F2 -Utheuser -Pmypassword -Sserver1 -t"~" -c': '/opt/mssql-tools/bin/bcp db1.dbo.table1 IN "file1.csv" -F2 -Utheuser -Pmypassword -Sserver1 -t"~" -c'