jedcunningham commented on code in PR #28808:
URL: https://github.com/apache/airflow/pull/28808#discussion_r1084275635


##########
kubernetes_tests/test_kubernetes_pod_operator.py:
##########
@@ -1153,3 +1153,134 @@ def test_using_resources(self):
                 do_xcom_push=False,
                 resources=resources,
             )
+
+    def test_changing_base_container_name_with_get_logs(self):
+        k = KubernetesPodOperator(
+            namespace="default",
+            image="ubuntu:16.04",
+            cmds=["bash", "-cx"],
+            arguments=["echo 10"],
+            labels=self.labels,
+            task_id=str(uuid4()),
+            in_cluster=False,
+            do_xcom_push=False,
+            get_logs=True,
+            base_container_name="apple-sauce",
+        )
+        assert k.base_container_name == "apple-sauce"
+        context = create_context(k)
+        with mock.patch.object(
+            k.pod_manager, "fetch_container_logs", 
wraps=k.pod_manager.fetch_container_logs
+        ) as mock_fetch_container_logs:
+            k.execute(context)
+
+        assert mock_fetch_container_logs.call_args[1]["container_name"] == 
"apple-sauce"
+        actual_pod = self.api_client.sanitize_for_serialization(k.pod)
+        self.expected_pod["spec"]["containers"][0]["name"] = "apple-sauce"
+        assert self.expected_pod["spec"] == actual_pod["spec"]
+
+    def test_changing_base_container_name_no_logs(self):
+        """
+        This test checks BOTH a modified base container name AND the 
get_logs=False flow..
+          and as a result, also checks that the flow works with fast containers
+          See #26796

Review Comment:
   ```suggestion
           This test checks BOTH a modified base container name AND the 
get_logs=False flow,
           and as a result, also checks that the flow works with fast containers
           See https://github.com/apache/airflow/issues/26796
   ```



##########
kubernetes_tests/test_kubernetes_pod_operator.py:
##########
@@ -1153,3 +1153,134 @@ def test_using_resources(self):
                 do_xcom_push=False,
                 resources=resources,
             )
+
+    def test_changing_base_container_name_with_get_logs(self):
+        k = KubernetesPodOperator(
+            namespace="default",
+            image="ubuntu:16.04",
+            cmds=["bash", "-cx"],
+            arguments=["echo 10"],
+            labels=self.labels,
+            task_id=str(uuid4()),
+            in_cluster=False,
+            do_xcom_push=False,
+            get_logs=True,
+            base_container_name="apple-sauce",
+        )
+        assert k.base_container_name == "apple-sauce"
+        context = create_context(k)
+        with mock.patch.object(
+            k.pod_manager, "fetch_container_logs", 
wraps=k.pod_manager.fetch_container_logs
+        ) as mock_fetch_container_logs:
+            k.execute(context)
+
+        assert mock_fetch_container_logs.call_args[1]["container_name"] == 
"apple-sauce"
+        actual_pod = self.api_client.sanitize_for_serialization(k.pod)
+        self.expected_pod["spec"]["containers"][0]["name"] = "apple-sauce"
+        assert self.expected_pod["spec"] == actual_pod["spec"]
+
+    def test_changing_base_container_name_no_logs(self):
+        """
+        This test checks BOTH a modified base container name AND the 
get_logs=False flow..
+          and as a result, also checks that the flow works with fast containers
+          See #26796
+        """
+        k = KubernetesPodOperator(
+            namespace="default",
+            image="ubuntu:16.04",
+            cmds=["bash", "-cx"],
+            arguments=["echo 10"],
+            labels=self.labels,
+            task_id=str(uuid4()),
+            in_cluster=False,
+            do_xcom_push=False,
+            get_logs=False,
+            base_container_name="apple-sauce",
+        )
+        assert k.base_container_name == "apple-sauce"
+        context = create_context(k)
+        with mock.patch.object(
+            k.pod_manager, "await_container_completion", 
wraps=k.pod_manager.await_container_completion
+        ) as mock_await_container_completion:
+            k.execute(context)
+
+        assert mock_await_container_completion.call_args[1]["container_name"] 
== "apple-sauce"
+        actual_pod = self.api_client.sanitize_for_serialization(k.pod)
+        self.expected_pod["spec"]["containers"][0]["name"] = "apple-sauce"
+        assert self.expected_pod["spec"] == actual_pod["spec"]
+
+    def test_changing_base_container_name_no_logs_long(self):
+        """
+        Similar to test_changing_base_container_name_no_logs, but ensures that
+        pods running longer than 1 second work too. See #26796

Review Comment:
   ```suggestion
           pods running longer than 1 second work too.
           See https://github.com/apache/airflow/issues/26796
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to