def test_faulty_service_account(self): """pod creation should fail when service account does not exist""" service_account = "foobar" namespace = "default" k = KubernetesPodOperator( namespace=namespace, image="ubuntu:16.04", cmds=["bash", "-cx"], arguments=["echo 10"], labels={"foo": "bar"}, name="test", task_id="task", in_cluster=False, do_xcom_push=False, startup_timeout_seconds=5, service_account_name=service_account, ) context = create_context(k) pod = k.build_pod_request_obj(context) with pytest.raises( ApiException, match= f"error looking up service account {namespace}/{service_account}" ): k.get_or_create_pod(pod, context)
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-" + str(random.randint(0, 1000000)), task_id="task" + self.get_current_task_name(), in_cluster=False, do_xcom_push=False, startup_timeout_seconds=5, service_account_name=bad_service_account_name, ) context = create_context(k) pod = k.build_pod_request_obj(context) with pytest.raises( ApiException, match="error looking up service account default/foobar"): k.get_or_create_pod(pod, context)