Example #1
0
 def test_no_command(self, mock_hook):
     op = WinRMOperator(task_id='test_task_id',
                        winrm_hook=mock_hook,
                        command=None)
     exception_msg = "No command specified so nothing to execute here."
     with self.assertRaisesRegex(AirflowException, exception_msg):
         op.execute(None)
Example #2
0
 def test_no_winrm_hook_no_ssh_conn_id(self):
     op = WinRMOperator(task_id='test_task_id',
                        winrm_hook=None,
                        ssh_conn_id=None)
     exception_msg = "Cannot operate without winrm_hook or ssh_conn_id."
     with self.assertRaisesRegex(AirflowException, exception_msg):
         op.execute(None)
 def test_no_winrm_hook_no_ssh_conn_id(self):
     op = WinRMOperator(task_id='test_task_id',
                        winrm_hook=None,
                        ssh_conn_id=None)
     exception_msg = "Cannot operate without winrm_hook or ssh_conn_id."
     with self.assertRaisesRegexp(AirflowException, exception_msg):
         op.execute(None)
 def test_no_command(self, mock_hook):
     op = WinRMOperator(
         task_id='test_task_id',
         winrm_hook=mock_hook,
         command=None
     )
     exception_msg = "No command specified so nothing to execute here."
     with self.assertRaisesRegexp(AirflowException, exception_msg):
         op.execute(None)
Example #5
0
from airflow.operators.dummy_operator import DummyOperator

default_args = {
    'owner': 'airflow',
    'start_date': airflow.utils.dates.days_ago(2)
}

with DAG(dag_id='POC_winrm_parallel',
         default_args=default_args,
         schedule_interval='0 0 * * *',
         dagrun_timeout=timedelta(minutes=60)) as dag:

    cmd = 'ls -l'
    run_this_last = DummyOperator(task_id='run_this_last')

    winRMHook = WinRMHook(ssh_conn_id='ssh_POC1')

    t1 = WinRMOperator(task_id="wintask1",
                       command='ls -altr',
                       winrm_hook=winRMHook)

    t2 = WinRMOperator(task_id="wintask2",
                       command='sleep 60',
                       winrm_hook=winRMHook)

    t3 = WinRMOperator(task_id="wintask3",
                       command='echo \'luke test\' ',
                       winrm_hook=winRMHook)

    [t1, t2, t3] >> run_this_last
    'start_date': airflow.utils.dates.days_ago(2)
}

dag = DAG(
    dag_id='POC_winrm_parallel', default_args=args,
    schedule_interval='0 0 * * *',
    dagrun_timeout=timedelta(minutes=60))

cmd = 'ls -l'
run_this_last = DummyOperator(task_id='run_this_last', dag=dag)

winRMHook = WinRMHook(ssh_conn_id='ssh_POC1')

t1 = WinRMOperator(
    task_id="wintask1",
    command='ls -altr',
    winrm_hook=winRMHook,
    dag=dag)

t2 = WinRMOperator(
    task_id="wintask2",
    command='sleep 60',
    winrm_hook=winRMHook,
    dag=dag)

t3 = WinRMOperator(
    task_id="wintask3",
    command='echo \'luke test\' ',
    winrm_hook=winRMHook,
    dag=dag)