本文整理汇总了Python中airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator.execute方法的典型用法代码示例。如果您正苦于以下问题:Python KubernetesPodOperator.execute方法的具体用法?Python KubernetesPodOperator.execute怎么用?Python KubernetesPodOperator.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator
的用法示例。
在下文中一共展示了KubernetesPodOperator.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_volume_mount
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_volume_mount():
with mock.patch.object(PodLauncher, 'log') as mock_logger:
volume_mount = VolumeMount('test-volume',
mount_path='/root/mount_file',
sub_path=None,
read_only=True)
volume_config = {
'persistentVolumeClaim':
{
'claimName': 'test-volume'
}
}
volume = Volume(name='test-volume', configs=volume_config)
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["cat /root/mount_file/test.txt"],
labels={"foo": "bar"},
volume_mounts=[volume_mount],
volumes=[volume],
name="test",
task_id="task"
)
k.execute(None)
mock_logger.info.assert_any_call(b"retrieved from mount\n")
示例2: test_pod_affinity
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_pod_affinity():
affinity = {
'nodeAffinity': {
'requiredDuringSchedulingIgnoredDuringExecution': {
'nodeSelectorTerms': [
{
'matchExpressions': [
{
'key': 'beta.kubernetes.io/os',
'operator': 'In',
'values': ['linux']
}
]
}
]
}
}
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
affinity=affinity,
executor_config={'KubernetesExecutor': {'affinity': affinity}}
)
k.execute(None)
示例3: test_working_pod
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_working_pod():
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task"
)
k.execute(None)
示例4: test_logging
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_logging(self):
with mock.patch.object(PodLauncher, 'log') as mock_logger:
k = KubernetesPodOperator(namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
get_logs=True
)
k.execute(None)
mock_logger.info.assert_any_call("+ echo\n")
示例5: test_faulty_image
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_faulty_image(self):
bad_image_name = "foobar"
k = KubernetesPodOperator(
namespace='default',
image=bad_image_name,
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
startup_timeout_seconds=5
)
with self.assertRaises(AirflowException):
k.execute(None)
示例6: test_faulty_service_account
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_faulty_service_account(self):
bad_service_account_name = "foobar"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
startup_timeout_seconds=5,
service_account_name=bad_service_account_name
)
with self.assertRaises(ApiException):
k.execute(None)
示例7: test_config_path_move
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_config_path_move():
new_config_path = '/tmp/kube_config'
old_config_path = os.path.expanduser('~/.kube/config')
shutil.copy(old_config_path, new_config_path)
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
config_file=new_config_path
)
k.execute(None)
示例8: test_pod_failure
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_pod_failure(self):
"""
Tests that the task fails when a pod reports a failure
"""
bad_internal_command = "foobar"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=[bad_internal_command + " 10"],
labels={"foo": "bar"},
name="test",
task_id="task"
)
with self.assertRaises(AirflowException):
k.execute(None)
示例9: test_pod_node_selectors
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_pod_node_selectors():
node_selectors = {
'beta.kubernetes.io/os': 'linux'
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
node_selectors=node_selectors,
executor_config={'KubernetesExecutor': {'node_selectors': node_selectors}}
)
k.execute(None)
示例10: test_pod_delete_even_on_launcher_error
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_pod_delete_even_on_launcher_error(self, client_mock, delete_pod_mock, run_pod_mock):
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
in_cluster=False,
cluster_context='default',
is_delete_operator_pod=True
)
run_pod_mock.side_effect = AirflowException('fake failure')
with self.assertRaises(AirflowException):
k.execute(None)
assert delete_pod_mock.called
示例11: test_envs_from_secrets
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_envs_from_secrets(self, client_mock, launcher_mock):
# GIVEN
from airflow.utils.state import State
secrets = [Secret('env', None, "secret_name")]
# WHEN
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
secrets=secrets,
labels={"foo": "bar"},
name="test",
task_id="task",
)
# THEN
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
self.assertEqual(launcher_mock.call_args[0][0].secrets, secrets)
示例12: test_fs_group
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_fs_group():
security_context = {
'securityContext': {
'fsGroup': 1000,
}
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
security_context=security_context,
executor_config={'KubernetesExecutor': {'securityContext': security_context}}
)
k.execute(None)
示例13: test_image_pull_secrets_correctly_set
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_image_pull_secrets_correctly_set(self, client_mock, launcher_mock):
from airflow.utils.state import State
fake_pull_secrets = "fakeSecret"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
image_pull_secrets=fake_pull_secrets,
in_cluster=False,
cluster_context='default'
)
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
self.assertEqual(launcher_mock.call_args[0][0].image_pull_secrets,
fake_pull_secrets)
示例14: test_config_path
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_config_path(self, client_mock, launcher_mock):
from airflow.utils.state import State
file_path = "/tmp/fake_file"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
config_file=file_path,
in_cluster=False,
cluster_context='default'
)
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
client_mock.assert_called_with(in_cluster=False,
cluster_context='default',
config_file=file_path)
示例15: test_xcom_push
# 需要导入模块: from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator [as 别名]
# 或者: from airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator import execute [as 别名]
def test_xcom_push(self):
return_value = '{"foo": "bar"\n, "buzz": 2}'
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=['echo \'{}\' > /airflow/xcom/return.json'.format(return_value)],
labels={"foo": "bar"},
name="test",
task_id="task",
do_xcom_push=True
)
self.assertEqual(k.execute(None), json.loads(return_value))