code: def test_use_subnets_in_only_one_vpc(
      iam_client_stub, ec2_client_stub
  ):
      """
      This test validates that when bootstrap_aws populates the SubnetIds field,
      all of the subnets used belong to the same VPC, and that a SecurityGroup
      in that VPC is correctly configured.
  
      Also validates that head IAM role is correctly filled.
      """
      stubs.configure_iam_role_default(iam_client_stub)
      stubs.configure_key_pair_default(ec2_client_stub)
  
      # Add a response with a thousand subnets all in different VPCs.
      # After filtering, only subnet in one particular VPC should remain.
      # Thus SubnetIds for each available node type should end up as
      # being length-one lists after the bootstrap_config.
      stubs.describe_a_thousand_subnets_in_different_vpcs(
          ec2_client_stub
      )
  
      # describe the subnet in use while determining its vpc
      stubs.describe_subnets_echo(ec2_client_stub, [DEFAULT_SUBNET])
      # given no existing security groups within the VPC...
      stubs.describe_no_security_groups(ec2_client_stub)
      # expect to create a security group on the VPC
      stubs.create_sg_echo(ec2_client_stub, DEFAULT_SG)
      # expect new security group details to be retrieved after creation
      stubs.describe_sgs_on_vpc(
          ec2_client_stub,
          [DEFAULT_SUBNET["VpcId"]],
          [DEFAULT_SG],
      )
  
      # given no existing default security group inbound rules...
      # expect to authorize all default inbound rules
      stubs.authorize_sg_ingress(
          ec2_client_stub,
          DEFAULT_SG_WITH_RULES,
      )
  
      # expect another call to describe the above security group while checking
      # a second time if it has ip_permissions set ("if not sg.ip_permissions")
      stubs.describe_an_sg_2(
          ec2_client_stub,
          DEFAULT_SG_WITH_RULES,
      )
  
      # given our mocks and an example config file as input...
      # expect the config to be loaded, validated, and bootstrapped successfully
      config = helpers.bootstrap_aws_example_config_file(
          "example-full.yaml"
      )
      _get_subnets_or_die.cache_clear()
  
      # We've filtered down to only one subnet id -- only one of the thousand
      # subnets generated by ec2.subnets.all() belongs to the right VPC.
      for node_type in config["available_node_types"].values():
          node_config = node_type["node_config"]
          assert node_config["SubnetIds"] == [
              DEFAULT_SUBNET["SubnetId"]
          ]
          assert node_config["SecurityGroupIds"] == [
              DEFAULT_SG["GroupId"]
          ]
  
imports: import copy
  from unittest.mock import Mock, patch
  import pytest
  from click.exceptions import ClickException
  import ray.tests.aws.utils.helpers
  import ray.tests.aws.utils.stubs
  from ray.autoscaler._private.aws.config import DEFAULT_AMI, _configure_subnet, _get_subnets_or_die, bootstrap_aws, log_to_cli
  from ray.autoscaler._private.aws.node_provider import AWSNodeProvider
  from ray.autoscaler._private.providers import _get_node_provider
  from ray.tests.aws.utils.constants import AUX_SG, AUX_SUBNET, CUSTOM_IN_BOUND_RULES, DEFAULT_CLUSTER_NAME, DEFAULT_INSTANCE_PROFILE, DEFAULT_KEY_PAIR, DEFAULT_LT, DEFAULT_SG, DEFAULT_SG_AUX_SUBNET, DEFAULT_SG_DUAL_GROUP_RULES, DEFAULT_SG_WITH_NAME, DEFAULT_SG_WITH_NAME_AND_RULES, DEFAULT_SG_WITH_RULES, DEFAULT_SG_WITH_RULES_AUX_SUBNET, DEFAULT_SUBNET
label_desc: Use image node_id 1 for calling a global function with example usage: test_use_subnets_in_only_one_vpc(iam_client_stub, ec2_client_stub) without return types