code: def restart_agent(
      self, wait_for_amnesia: bool = True, wait_for_agent: bool = True
  ) -> None:
      agent_data = get_agent_data(conf.make_master_url())
      if len(agent_data) == 1 and agent_data[0]["enabled"]:
          return
  
      if wait_for_amnesia:
          print(f"Agent is in state {agent_data}, waiting for amnesia")
          # Currently, we've got to wait for master to "forget" the agent before reconnecting.
          WAIT_FOR_AMNESIA = 60
          for _i in range(WAIT_FOR_AMNESIA):
              agent_data = get_agent_data(conf.make_master_url())
              if len(agent_data) == 0:
                  break
              time.sleep(1)
          else:
              pytest.fail(
                  f"Agent is still not forgotten after {WAIT_FOR_AMNESIA} seconds"
              )
  
      self.dc.restart_stage("agent1", wait=wait_for_agent, timeout=10)
  
      WAIT_FOR_STARTUP = 10
      if wait_for_agent:
          self.wait_for_agent_ok(WAIT_FOR_STARTUP)
  
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 8 for calling the ManagedCluster obj's underlying member method code with example usage: obj.restart_agent(wait_for_amnesia, wait_for_agent) without return types