code: def test_non_default_ports_visible_on_init(shutdown_only):
      import subprocess
  
      ports = {
          "dashboard_agent_grpc_port": get_current_unused_port(),
          "metrics_export_port": get_current_unused_port(),
          "dashboard_agent_listen_port": get_current_unused_port(),
          "port": get_current_unused_port(),  # gcs_server_port
          "node_manager_port": get_current_unused_port(),
      }
      # Start a ray head node with customized ports.
      cmd = "ray start --head --block".split(" ")
      for port_name, port in ports.items():
          # replace "_" with "-"
          port_name = port_name.replace("_", "-")
          cmd += ["--" + port_name, str(port)]
  
      print(" ".join(cmd))
      proc = subprocess.Popen(cmd)
  
      # From the connected node
      def verify():
          # Connect to the node and check ports
          print(ray.init("auto", ignore_reinit_error=True))
  
          node = ray.worker.global_worker.node
          assert (
              node.metrics_agent_port
              == ports["dashboard_agent_grpc_port"]
          )
          assert (
              node.metrics_export_port == ports["metrics_export_port"]
          )
          assert (
              node.dashboard_agent_listen_port
              == ports["dashboard_agent_listen_port"]
          )
          assert str(ports["port"]) in node.gcs_address
          assert node.node_manager_port == ports["node_manager_port"]
          return True
  
      try:
          wait_for_condition(verify, timeout=15, retry_interval_ms=2000)
      finally:
          proc.terminate()
          proc.wait()
          subprocess.check_output("ray stop --force", shell=True)
  
imports: import logging
  import os
  import sys
  import unittest.mock
  import tempfile
  import shutil
  from unittest.mock import patch
  import pytest
  import ray
  from ray._private.ray_constants import RAY_OVERRIDE_DASHBOARD_URL, DEFAULT_RESOURCES
  from ray.air.util.node import _get_node_id_from_node_ip
  import ray._private.services
  from ray._private.services import get_node_ip_address
  from ray.dashboard.utils import ray_address_to_api_server_url
  from ray._private.test_utils import get_current_unused_port, run_string_as_driver, wait_for_condition
  from ray.util.client.ray_client_helpers import ray_start_client_server
label_desc: Use image node_id 14 for calling a global function with example usage: test_non_default_ports_visible_on_init(shutdown_only) and returns: True