Exemplo n.º 1
0
    def test_kube_kwargs_value_is_replaced(self, kube_secret, api_client):
        task = PatchNamespacedPod(body={"test": "a"},
                                  kube_kwargs={"test": "a"},
                                  pod_name="test")

        task.run(kube_kwargs={"test": "b"})
        assert api_client.patch_namespaced_pod.call_args[1]["test"] == "b"
Exemplo n.º 2
0
    def test_empty_body_value_is_updated(self, kube_secret, api_client):
        task = PatchNamespacedPod(pod_name="test")

        task.run(body={"test": "a"})
        assert api_client.patch_namespaced_pod.call_args[1]["body"] == {
            "test": "a"
        }
Exemplo n.º 3
0
    def test_body_value_is_appended(self, kube_secret, api_client):
        task = PatchNamespacedPod(body={"test": "a"}, pod_name="test")

        task.run(body={"a": "test"})
        assert api_client.patch_namespaced_pod.call_args[1]["body"] == {
            "a": "test",
            "test": "a",
        }
Exemplo n.º 4
0
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = PatchNamespacedPod(body={"test": "test"}, pod_name="test")
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.pod.client", client)

        conf_call = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.pod.client.Configuration", conf_call)
        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(KUBERNETES_API_KEY="test_key")):
                task.run()
        assert conf_call.called
Exemplo n.º 5
0
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = PatchNamespacedPod(body={"test": "test"}, pod_name="test")
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.pod.client", client)

        api_key = {}
        conf_call = MagicMock()
        conf_call.return_value.api_key = api_key
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.pod.client.Configuration", conf_call)
        task.run()
        assert api_key == {"authorization": "test_key"}
Exemplo n.º 6
0
    def test_empty_kube_kwargs_value_is_updated(self, monkeypatch):
        task = PatchNamespacedPod(body={"test": "a"}, pod_name="test")

        config = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config)

        coreapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.pod.client",
            MagicMock(CoreV1Api=MagicMock(return_value=coreapi)),
        )

        task.run(kube_kwargs={"test": "a"})
        assert coreapi.patch_namespaced_pod.call_args[1]["test"] == "a"
Exemplo n.º 7
0
    def test_body_value_is_replaced(self, monkeypatch, kube_secret):
        task = PatchNamespacedPod(body={"test": "a"}, pod_name="test")

        config = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config)

        coreapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.pod.client",
            MagicMock(CoreV1Api=MagicMock(return_value=coreapi)),
        )

        task.run(body={"test": "b"})
        assert coreapi.patch_namespaced_pod.call_args[1]["body"] == {"test": "b"}
Exemplo n.º 8
0
 def test_empty_initialization(self):
     task = PatchNamespacedPod()
     assert not task.pod_name
     assert task.body == {}
     assert task.namespace == "default"
     assert task.kube_kwargs == {}
     assert task.kubernetes_api_key_secret == "KUBERNETES_API_KEY"
Exemplo n.º 9
0
    def test_kube_config_in_cluster(self, monkeypatch):
        config = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config)

        coreapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.pod.client",
            MagicMock(CoreV1Api=MagicMock(return_value=coreapi)),
        )

        task = PatchNamespacedPod(
            body={"test": "a"}, pod_name="test", kubernetes_api_key_secret=None
        )

        task.run(body={"test": "b"})
        assert config.load_incluster_config.called
Exemplo n.º 10
0
 def test_filled_initialization(self):
     task = PatchNamespacedPod(
         pod_name="test",
         body={"test": "test"},
         namespace="test",
         kube_kwargs={"test": "test"},
         kubernetes_api_key_secret="test",
     )
     assert task.pod_name == "test"
     assert task.body == {"test": "test"}
     assert task.namespace == "test"
     assert task.kube_kwargs == {"test": "test"}
     assert task.kubernetes_api_key_secret == "test"
Exemplo n.º 11
0
 def test_invalid_pod_name_raises_error(self):
     task = PatchNamespacedPod()
     with pytest.raises(ValueError):
         task.run(body={"test": "test"}, pod_name=None)
Exemplo n.º 12
0
 def test_invalid_body_raises_error(self):
     task = PatchNamespacedPod()
     with pytest.raises(ValueError):
         task.run(body=None)
Exemplo n.º 13
0
 def test_empty_body_raises_error(self):
     task = PatchNamespacedPod()
     with pytest.raises(ValueError):
         task.run()