code: def restartable_managed_cluster(
      managed_cluster_restarts: ManagedCluster,
  ) -> Iterator[ManagedCluster]:
      managed_cluster_restarts.wait_for_agent_ok(20)
      try:
          yield managed_cluster_restarts
          managed_cluster_restarts.wait_for_agent_ok(20)
      except Exception:
          managed_cluster_restarts.restart_master()
          managed_cluster_restarts.restart_agent()
          raise
  
imports: import json
  import os
  import subprocess
  import time
  from typing import Any, Dict, Iterator, List, Union, cast
  import pytest
  from tests import config
  from .abstract_cluster import Cluster
  from .test_users import logged_in_user
  from .utils import now_ts, set_master_port
label_desc: Use image node_id 6 for calling a global function with example usage: restartable_managed_cluster(managed_cluster_restarts) without return types