code: def _test_master_restart_ok(managed_cluster: Cluster) -> None:
      # - Kill master
      # - Restart master
      # - Schedule something.
      # Do it twice to ensure nothing gets stuck.
      try:
          for i in range(3):
              print("test_master_restart_ok stage %s start" % i)
              cmd_ids = [run_command(1, slots) for slots in [0, 1]]
  
              for cmd_id in cmd_ids:
                  wait_for_command_state(cmd_id, "TERMINATED", 300)
                  assert_command_succeeded(cmd_id)
  
              managed_cluster.kill_master()
              managed_cluster.restart_master()
  
              print("test_master_restart_ok stage %s done" % i)
      except Exception:
          managed_cluster.restart_master()
          managed_cluster.restart_agent()
          raise
  
imports: import logging
  import subprocess
  import time
  import docker
  import pytest
  import requests
  from determined.common import constants
  from determined.common.api import authentication, task_is_ready, task_logs
  from determined.common.api.bindings import experimentv1State
  from tests import api_utils
  from tests import command
  from tests import config
  from tests import experiment
  from tests.cluster.test_users import det_spawn
  from .abstract_cluster import Cluster
  from .managed_cluster import ManagedCluster, get_agent_data
  from .managed_cluster_k8s import ManagedK8sCluster
  from .test_groups import det_cmd, det_cmd_json
  from .utils import assert_command_succeeded, run_command, wait_for_command_state, wait_for_task_state
label_desc: Use image node_id 3 for calling a global function with example usage: _test_master_restart_ok(managed_cluster) without return types