class_docstr: e2e verification of autoscaling following the steps in the Ray documentation.
  kubectl is used throughout, as that reflects the instructions in the docs.
class_docstr_tok: ["e2e","verification","of","autoscaling","following","the","steps","in","the","Ray","documentation",".","kubectl","is","used","throughout",",","as","that","reflects","the","instructions","in","the","docs","."]
docstr: Apply Ray CR config yaml, with configurable replica fields for the cpu
  workerGroup.
  
  If the CR does not yet exist, `replicas` can be set as desired.
  If the CR does already exist, the recommended usage is this:
      (1) Set `cpu_replicas` and `gpu_replicas` to what we currently expect them
          to be.
      (2) Set `validate_replicas` to True. We will then check that the replicas
      set on the CR coincides with `replicas`.
docstr_tok: ["Apply","Ray","CR","config","yaml",",","with","configurable","replica","fields","for","the","cpu","workerGroup",".","If","the","CR","does","not","yet","exist",",","`","replicas","`","can","be","set","as","desired",".","If","the","CR","does","already","exist",",","the","recommended","usage","is","this",":","(","1",")","Set","`","cpu_replicas","`","and","`","gpu_replicas","`","to","what","we","currently","expect","them","to","be",".","(","2",")","Set","`","validate_replicas","`","to","True",".","We","will","then","check","that","the","replicas","set","on","the","CR","coincides","with","`","replicas","`","."]
code: def _apply_ray_cr(
      self,
      min_replicas=0,
      cpu_replicas=0,
      gpu_replicas=0,
      validate_replicas: bool = False,
  ) -> None:
      """Apply Ray CR config yaml, with configurable replica fields for the cpu
      workerGroup.
  
      If the CR does not yet exist, `replicas` can be set as desired.
      If the CR does already exist, the recommended usage is this:
          (1) Set `cpu_replicas` and `gpu_replicas` to what we currently expect them
              to be.
          (2) Set `validate_replicas` to True. We will then check that the replicas
          set on the CR coincides with `replicas`.
      """
      if validate_replicas:
          raycluster = get_raycluster(
              RAY_CLUSTER_NAME, namespace=RAY_CLUSTER_NAMESPACE
          )
          assert (
              raycluster["spec"]["workerGroupSpecs"][0]["replicas"]
              == cpu_replicas
          )
          assert (
              raycluster["spec"]["workerGroupSpecs"][1]["replicas"]
              == gpu_replicas
          )
          logger.info(
              f"Validated that cpu and gpu worker replicas for "
              f"{RAY_CLUSTER_NAME} are currently {cpu_replicas} and"
              f" {gpu_replicas}, respectively."
          )
      cr_config = self._get_ray_cr_config(
          min_replicas=min_replicas,
          cpu_replicas=cpu_replicas,
          gpu_replicas=gpu_replicas,
      )
  
      with tempfile.NamedTemporaryFile("w") as config_file:
          yaml.dump(cr_config, config_file)
          config_file.flush()
  
          subprocess.check_call(
              ["kubectl", "apply", "-f", config_file.name],
              stdout=sys.stdout,
              stderr=sys.stderr,
          )
  
file_path: ray/python/ray/tests/kuberay/test_autoscaling_e2e.py
imports: import base64
  import copy
  import logging
  import os
  import pytest
  import subprocess
  import sys
  import tempfile
  import unittest
  from typing import Any, Dict
  import yaml
  from ray.tests.kuberay.utils import get_pod, get_pod_names, get_raycluster, ray_client_port_forward, ray_job_submit, switch_to_ray_parent_dir, kubectl_exec_python_script, kubectl_logs, kubectl_delete, wait_for_pods, wait_for_pod_to_start, wait_for_ray_health
  from ray.tests.kuberay.scripts import gpu_actor_placement, gpu_actor_validation, non_terminated_nodes_count
label_desc: Use image node_id 2 for calling the KubeRayAutoscalingTest obj's underlying member method code with example usage: obj._apply_ray_cr(min_replicas, cpu_replicas, gpu_replicas, validate_replicas) without return types