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_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)
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 pytest.raises(AirflowException, match=exception_msg): op.execute(None)
from airflow.operators.dummy_operator import DummyOperator from airflow.providers.microsoft.winrm.hooks.winrm import WinRMHook from airflow.providers.microsoft.winrm.operators.winrm import WinRMOperator from airflow.utils.dates import days_ago default_args = { 'owner': 'airflow', } with DAG( dag_id='POC_winrm_parallel', default_args=default_args, schedule_interval='0 0 * * *', start_date=days_ago(2), dagrun_timeout=timedelta(minutes=60), tags=['example'], ) 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