Techdebt: Remove old/deprecated code (#7220)

This commit is contained in:
Bert Blommers 2024-01-17 10:05:37 +00:00
parent 16ba3de855
commit dea4a98b64
178 changed files with 331 additions and 327 deletions

View File

@ -10,7 +10,8 @@ from cryptography.hazmat.primitives import hashes, serialization
from cryptography.x509 import OID_COMMON_NAME, DNSName, NameOID
from moto import settings
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from .exceptions import (

View File

@ -9,7 +9,8 @@ from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.x509 import Certificate, NameOID, load_pem_x509_certificate
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time, utcnow
from moto.moto_api._internal import mock_random
from moto.utilities.tagging_service import TaggingService

View File

@ -2,7 +2,8 @@
from typing import Any, Callable, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.moto_api._internal import mock_random
from moto.utilities.paginator import paginate

View File

@ -19,7 +19,8 @@ except ImportError:
from openapi_spec_validator.validation.exceptions import OpenAPIValidationError
from moto.apigateway.exceptions import MethodNotFoundException
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import path_url
from moto.moto_api._internal import mock_random as random

View File

@ -2,7 +2,7 @@
from collections import defaultdict
from typing import Any, Dict
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.utils import unix_time

View File

@ -5,7 +5,8 @@ from typing import Any, Dict, List, Optional, Union
import yaml
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.moto_api._internal import mock_random as random
from moto.utilities.tagging_service import TaggingService

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, Iterable, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random
from moto.utilities.tagging_service import TaggingService

View File

@ -3,7 +3,8 @@ from collections import OrderedDict
from enum import Enum, unique
from typing import Dict, List, Optional, Tuple, Union
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.ecs import ecs_backends
from moto.moto_api._internal import mock_random

View File

@ -3,7 +3,8 @@ import json
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, Iterable, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.moto_api._internal import mock_random
from moto.utilities.tagging_service import TaggingService

View File

@ -2,7 +2,8 @@ import time
from datetime import datetime
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random
from moto.utilities.paginator import paginate

View File

@ -2,7 +2,8 @@ import itertools
from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import camelcase_to_underscores
from moto.ec2 import ec2_backends
from moto.ec2.exceptions import InvalidInstanceIdError
@ -805,7 +806,7 @@ class FakeAutoScalingGroup(CloudFormationModel):
if self.launch_config
else None
)
reservation = self.autoscaling_backend.ec2_backend.add_instances(
reservation = self.autoscaling_backend.ec2_backend.run_instances(
self.image_id,
count_needed,
self.user_data,

View File

@ -23,7 +23,8 @@ import requests.exceptions
from moto import settings
from moto.awslambda.policy import Policy
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.exceptions import RESTError
from moto.core.utils import iso_8601_datetime_with_nanoseconds, unix_time_millis, utcnow
from moto.dynamodb import dynamodb_backends
@ -149,7 +150,7 @@ class _DockerDataVolumeContext:
try:
with zip2tar(self._lambda_func.code_bytes) as stream:
container.put_archive(settings.LAMBDA_DATA_DIR, stream)
if settings.test_proxy_mode():
if settings.is_test_proxy_mode():
ca_cert = load_resource_as_bytes(__name__, "../moto_proxy/ca.crt")
with file2tar(ca_cert, "ca.crt") as cert_stream:
container.put_archive(settings.LAMBDA_DATA_DIR, cert_stream)
@ -968,7 +969,7 @@ class LambdaFunction(CloudFormationModel, DockerModel):
env_vars["MOTO_PORT"] = moto_port
env_vars["MOTO_HTTP_ENDPOINT"] = f'{env_vars["MOTO_HOST"]}:{moto_port}'
if settings.test_proxy_mode():
if settings.is_test_proxy_mode():
env_vars["HTTPS_PROXY"] = env_vars["MOTO_HTTP_ENDPOINT"]
env_vars["AWS_CA_BUNDLE"] = "/var/task/ca.crt"

View File

@ -1,7 +1,7 @@
from typing import Any, Optional, Union
from ..awslambda.models import LambdaBackend
from ..core import BackendDict
from moto.awslambda.models import LambdaBackend
from moto.core.base_backend import BackendDict
class LambdaSimpleBackend(LambdaBackend):

View File

@ -33,7 +33,7 @@ if TYPE_CHECKING:
from moto.cognitoidp.models import CognitoIdpBackend
from moto.comprehend.models import ComprehendBackend
from moto.config.models import ConfigBackend
from moto.core import SERVICE_BACKEND, BackendDict
from moto.core.base_backend import SERVICE_BACKEND, BackendDict
from moto.databrew.models import DataBrewBackend
from moto.datapipeline.models import DataPipelineBackend
from moto.datasync.models import DataSyncBackend

View File

@ -11,7 +11,8 @@ from typing import Any, Dict, List, Optional, Set, Tuple
import dateutil.parser
from moto import settings
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import unix_time_millis
from moto.ec2.exceptions import InvalidSubnetIdError
from moto.ec2.models import EC2Backend, ec2_backends
@ -1270,7 +1271,7 @@ class BatchBackend(BaseBackend):
subnet_cycle = cycle(compute_resources["subnets"])
for instance_type in needed_instance_types:
reservation = self.ec2_backend.add_instances(
reservation = self.ec2_backend.run_instances(
image_id="ami-03cf127a", # Todo import AMIs
count=1,
user_data=None,

View File

@ -3,13 +3,9 @@ from os import getenv
from time import sleep
from typing import Any, Dict, List, Optional, Tuple
from ..batch.models import (
BatchBackend,
ClientException,
Job,
batch_backends,
)
from ..core import BackendDict
from moto.batch.exceptions import ClientException
from moto.batch.models import BatchBackend, Job, batch_backends
from moto.core.base_backend import BackendDict
class BatchSimpleBackend(BatchBackend):

View File

@ -3,7 +3,8 @@ from copy import deepcopy
from datetime import datetime
from typing import Any, Dict, Iterable, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from .exceptions import BudgetMissingLimit, DuplicateRecordException, NotFoundException

View File

@ -3,7 +3,8 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds
from moto.moto_api._internal import mock_random
from moto.utilities.tagging_service import TaggingService

View File

@ -4,7 +4,7 @@ from typing import Any, Dict
from moto import settings
from moto.awslambda import lambda_backends
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.moto_api._internal import mock_random

View File

@ -7,7 +7,8 @@ import yaml
from yaml.parser import ParserError # pylint:disable=c-extension-no-member
from yaml.scanner import ScannerError # pylint:disable=c-extension-no-member
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import (
iso_8601_datetime_with_milliseconds,
iso_8601_datetime_without_milliseconds,

View File

@ -35,7 +35,7 @@ from moto.cloudformation.custom_model import CustomModel
from moto.cloudwatch import models as cw_models # noqa # pylint: disable=all
# End ugly list of imports
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.datapipeline import models as data_models # noqa # pylint: disable=all
from moto.dynamodb import models as ddb_models # noqa # pylint: disable=all
from moto.ec2 import models as ec2_models

View File

@ -1,7 +1,8 @@
import string
from typing import Any, Dict, Iterable, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.moto_api._internal import mock_random as random
from moto.moto_api._internal.managed_state_model import ManagedState

View File

@ -3,7 +3,8 @@ import time
from datetime import datetime
from typing import Any, Dict, Iterable, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds, utcnow
from moto.utilities.tagging_service import TaggingService

View File

@ -5,7 +5,8 @@ from typing import Any, Dict, Iterable, List, Optional, SupportsFloat, Tuple
from dateutil import parser
from dateutil.tz import tzutc
from moto.core import BackendDict, BaseBackend, BaseModel, CloudWatchMetricProvider
from moto.core.base_backend import BaseBackend
from moto.core.common_models import BackendDict, BaseModel, CloudWatchMetricProvider
from moto.core.utils import (
iso_8601_datetime_with_nanoseconds,
iso_8601_datetime_without_milliseconds,

View File

@ -4,7 +4,8 @@ from typing import Any, Dict, List, Optional
from dateutil import parser
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.moto_api._internal import mock_random

View File

@ -1,6 +1,7 @@
from typing import Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.moto_api._internal import mock_random

View File

@ -8,7 +8,8 @@ from moto.codepipeline.exceptions import (
ResourceNotFoundException,
TooManyTagsException,
)
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow
from moto.iam.exceptions import IAMNotFoundException
from moto.iam.models import IAMBackend, iam_backends

View File

@ -4,7 +4,8 @@ import re
from collections import OrderedDict
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from .exceptions import InvalidNameException, ResourceNotFoundError

View File

@ -10,7 +10,8 @@ from typing import Any, Dict, List, Optional, Set, Tuple
from jose import jws
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from moto.moto_api._internal import mock_random as random
from moto.utilities.paginator import paginate

View File

@ -2,7 +2,8 @@
from typing import Any, Dict, Iterable, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.utilities.tagging_service import TaggingService
from .exceptions import (

View File

@ -48,8 +48,8 @@ from moto.config.exceptions import (
TooManyTags,
ValidationException,
)
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.common_models import ConfigQueryModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, ConfigQueryModel
from moto.core.responses import AWSServiceSpec
from moto.core.utils import utcnow
from moto.iam.config import policy_config_query, role_config_query

View File

@ -1,7 +1,4 @@
from .models import DEFAULT_ACCOUNT_ID # noqa
from .base_backend import BaseBackend, BackendDict, SERVICE_BACKEND # noqa
from .common_models import BaseModel # noqa
from .common_models import CloudFormationModel, CloudWatchMetricProvider # noqa
from .models import patch_client, patch_resource # noqa
from .responses import ActionAuthenticatorMixin

View File

@ -29,7 +29,7 @@ def mock_aws(
clss = (
ServerModeMockAWS
if settings.TEST_SERVER_MODE
else (ProxyModeMockAWS if settings.test_proxy_mode() else MockAWS)
else (ProxyModeMockAWS if settings.is_test_proxy_mode() else MockAWS)
)
if func is not None:
return clss().__call__(func=func)

View File

@ -5,7 +5,8 @@ from copy import deepcopy
from datetime import datetime
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import camelcase_to_pascal, underscores_to_camelcase
from moto.utilities.paginator import paginate

View File

@ -2,7 +2,8 @@ import datetime
from collections import OrderedDict
from typing import Any, Dict, Iterable, List
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import utcnow
from .utils import get_random_pipeline_id, remove_capitalization_of_dict_keys

View File

@ -1,7 +1,8 @@
from collections import OrderedDict
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from .exceptions import InvalidRequestException

View File

@ -1,7 +1,8 @@
"""DAXBackend class with methods for supported APIs."""
from typing import Any, Dict, Iterable, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.moto_api._internal import mock_random as random
from moto.moto_api._internal.managed_state_model import ManagedState

View File

@ -1,7 +1,8 @@
from datetime import datetime
from typing import Any, Dict, Iterable, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from .exceptions import (

View File

@ -2,7 +2,8 @@
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.ds.exceptions import (
ClientException,
DirectoryLimitExceededException,

View File

@ -3,7 +3,7 @@ import re
from collections import OrderedDict
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.exceptions import JsonRESTError
from moto.core.utils import unix_time
from moto.dynamodb.comparisons import get_expected, get_filter_expression

View File

@ -6,7 +6,7 @@ from typing import Any, Dict, List, Optional, Union
from boto3.dynamodb.types import TypeDeserializer, TypeSerializer
from botocore.utils import merge_dicts
from moto.core import BaseModel
from moto.core.common_models import BaseModel
from moto.dynamodb.exceptions import (
EmptyKeyAttributeException,
IncorrectDataType,

View File

@ -2,7 +2,7 @@ import copy
from collections import defaultdict
from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple
from moto.core import BaseModel, CloudFormationModel
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import unix_time, unix_time_millis, utcnow
from moto.dynamodb.comparisons import get_expected, get_filter_expression
from moto.dynamodb.exceptions import (

View File

@ -2,7 +2,8 @@ import json
from collections import OrderedDict, defaultdict
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time, utcnow
from .comparisons import get_comparison_func

View File

@ -3,7 +3,8 @@ import json
import os
from typing import Any, Dict, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.dynamodb.models import DynamoDBBackend, dynamodb_backends
from moto.dynamodb.models.table import StreamShard, Table
from moto.dynamodb.models.utilities import DynamoJsonEncoder

View File

@ -2,7 +2,8 @@
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.ec2.models import EC2Backend, ec2_backends
from moto.ec2.models.elastic_block_store import Snapshot

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from ..exceptions import (
EC2ClientError,

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import BaseModel
from moto.core.common_models import BaseModel
from ..exceptions import FilterNotImplementedError

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, Iterable, List, Optional, Set
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.packages.boto.ec2.blockdevicemapping import BlockDeviceType
from ..exceptions import (

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
FilterNotImplementedError,

View File

@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import InvalidNetworkAttachmentIdError, InvalidNetworkInterfaceIdError
from .core import TaggedEC2Resource

View File

@ -158,7 +158,7 @@ class Fleet(TaggedEC2Resource):
def create_on_demand_requests(self, weight_to_add: float) -> None:
weight_map, added_weight = self.get_launch_spec_counts(weight_to_add)
for launch_spec, count in weight_map.items():
reservation = self.ec2_backend.add_instances(
reservation = self.ec2_backend.run_instances(
image_id=launch_spec.image_id,
count=count,
instance_type=launch_spec.instance_type,

View File

@ -1,7 +1,7 @@
import itertools
from typing import Any, Dict, List, Optional, Tuple
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
FlowLogAlreadyExists,

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional, Tuple
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.ec2.models.instances import Instance
from moto.iam.models import InstanceProfile

View File

@ -1,11 +1,10 @@
import contextlib
import copy
import warnings
from collections import OrderedDict
from typing import Any, Dict, ItemsView, List, Optional, Set, Tuple
from moto import settings
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.core.utils import camelcase_to_underscores, utcnow
from moto.ec2.models.elastic_network_interfaces import NetworkInterface
from moto.ec2.models.fleets import Fleet
@ -139,15 +138,6 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
amis = self.ec2_backend.describe_images(filters={"image-id": self.image_id})
ami = amis[0] if amis else None
if ami is None:
warnings.warn(
f"Could not find AMI with image-id:{self.image_id}, "
"in the near future this will "
"cause an error.\n"
"Use ec2_backend.describe_images() to "
"find suitable image for your test",
PendingDeprecationWarning,
)
self.platform = ami.platform if ami else None
self.virtualization_type = ami.virtualization_type if ami else "paravirtual"
@ -300,7 +290,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
for group_id in security_group_ids
]
reservation = ec2_backend.add_instances(
reservation = ec2_backend.run_instances(
image_id=properties["ImageId"],
user_data=properties.get("UserData"),
count=1,
@ -622,7 +612,7 @@ class InstanceBackend:
return instance
raise InvalidInstanceIdError(instance_id)
def add_instances(
def run_instances(
self,
image_id: str,
count: int,
@ -630,6 +620,18 @@ class InstanceBackend:
security_group_names: List[str],
**kwargs: Any,
) -> Reservation:
"""
The Placement-parameter is validated to verify the availability-zone exists for the current region.
The InstanceType-parameter can be validated, to see if it is a known instance-type.
Enable this validation by setting the environment variable `MOTO_EC2_ENABLE_INSTANCE_TYPE_VALIDATION=true`
The ImageId-parameter can be validated, to see if it is a known AMI.
Enable this validation by setting the environment variable `MOTO_ENABLE_AMI_VALIDATION=true`
The KeyPair-parameter can be validated, to see if it is a known key-pair.
Enable this validation by setting the environment variable `MOTO_ENABLE_KEYPAIR_VALIDATION=true`
"""
location_type = "availability-zone" if kwargs.get("placement") else "region"
default_region = "us-east-1"
if settings.ENABLE_KEYPAIR_VALIDATION:
@ -737,23 +739,6 @@ class InstanceBackend:
return new_reservation
def run_instances(self) -> None:
"""
The Placement-parameter is validated to verify the availability-zone exists for the current region.
The InstanceType-parameter can be validated, to see if it is a known instance-type.
Enable this validation by setting the environment variable `MOTO_EC2_ENABLE_INSTANCE_TYPE_VALIDATION=true`
The ImageId-parameter can be validated, to see if it is a known AMI.
Enable this validation by setting the environment variable `MOTO_ENABLE_AMI_VALIDATION=true`
The KeyPair-parameter can be validated, to see if it is a known key-pair.
Enable this validation by setting the environment variable `MOTO_ENABLE_KEYPAIR_VALIDATION=true`
"""
# Logic resides in add_instances
# Fake method here to make implementation coverage script aware that this method is implemented
pass
def start_instances(
self, instance_ids: List[str]
) -> List[Tuple[Instance, InstanceState]]:

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
DependencyViolationError,

View File

@ -1,7 +1,7 @@
from collections import OrderedDict
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
InvalidLaunchTemplateNameAlreadyExistsError,

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow
from ..utils import random_nat_gateway_id, random_private_ip

View File

@ -1,7 +1,7 @@
import ipaddress
from typing import Any, Dict, List, Optional, Set
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.ec2.models.carrier_gateways import CarrierGateway
from moto.ec2.models.elastic_network_interfaces import NetworkInterface
from moto.ec2.models.instances import Instance

View File

@ -4,7 +4,7 @@ import json
from collections import defaultdict
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BaseModel, CloudFormationModel
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import aws_api_matches
from ..exceptions import (

View File

@ -125,7 +125,7 @@ class SpotInstanceRequest(TaggedEC2Resource):
return super().get_filter_value(filter_name, "DescribeSpotInstanceRequests")
def launch_instance(self) -> "Instance":
reservation = self.ec2_backend.add_instances(
reservation = self.ec2_backend.run_instances(
image_id=self.launch_specification.image_id,
count=1,
user_data=self.user_data,

View File

@ -3,7 +3,7 @@ import itertools
from collections import defaultdict
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
if TYPE_CHECKING:
from moto.ec2.models.instances import Instance

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow
from moto.utilities.utils import filter_resources, merge_multiple_dicts

View File

@ -2,7 +2,7 @@ import weakref
from collections import defaultdict
from typing import Any, Dict, Iterator, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
InvalidVPCPeeringConnectionIdError,

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from moto.moto_api._internal import mock_random
from ..exceptions import UnknownVpcEndpointService

View File

@ -5,7 +5,7 @@ from collections import defaultdict
from operator import itemgetter
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import (
CidrLimitExceeded,

View File

@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional
from moto.core import CloudFormationModel
from moto.core.common_models import CloudFormationModel
from ..exceptions import InvalidVpnGatewayAttachmentError, InvalidVpnGatewayIdError
from ..utils import generic_filter, random_vpn_gateway_id

View File

@ -1,4 +1,4 @@
from moto.core import BaseModel
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random as random

View File

@ -103,7 +103,7 @@ class InstanceResponse(EC2BaseResponse):
iam_instance_profile_name = kwargs.get("iam_instance_profile_name")
iam_instance_profile_arn = kwargs.get("iam_instance_profile_arn")
if iam_instance_profile_arn or iam_instance_profile_name:
# Validate the profile exists, before we error_on_dryrun and add_instances
# Validate the profile exists, before we error_on_dryrun and run_instances
filter_iam_instance_profiles(
self.current_account,
iam_instance_profile_arn=iam_instance_profile_arn,
@ -112,7 +112,7 @@ class InstanceResponse(EC2BaseResponse):
self.error_on_dryrun()
new_reservation = self.ec2_backend.add_instances(
new_reservation = self.ec2_backend.run_instances(
image_id, min_count, user_data, security_group_names, **kwargs
)
if iam_instance_profile_name:

View File

@ -1,6 +1,6 @@
import json
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
class Ec2InstanceConnectBackend(BaseBackend):

View File

@ -7,7 +7,8 @@ from typing import Any, Dict, Iterable, List, Optional, Tuple
from botocore.exceptions import ParamValidationError
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import iso_8601_datetime_without_milliseconds, utcnow
from moto.ecr.exceptions import (
ImageAlreadyExistsException,

View File

@ -5,7 +5,8 @@ from os import getenv
from typing import Any, Dict, Iterator, List, Optional, Tuple
from moto import settings
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.exceptions import JsonRESTError
from moto.core.utils import pascal_to_camelcase, remap_nested_keys, unix_time
from moto.ec2 import ec2_backends

View File

@ -9,7 +9,8 @@ import time
from copy import deepcopy
from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import camelcase_to_underscores, underscores_to_camelcase
from moto.ec2 import ec2_backends
from moto.ec2.exceptions import InvalidSubnetIdError

View File

@ -1,7 +1,7 @@
from datetime import datetime
from typing import Any, Dict, Iterator, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.utils import iso_8601_datetime_without_milliseconds
from moto.moto_api._internal import mock_random as random

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from ..moto_api._internal import mock_random

View File

@ -1,7 +1,8 @@
import weakref
from typing import Dict, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from .exceptions import (
ApplicationNotFound,

View File

@ -1,7 +1,8 @@
import string
from typing import Any, Dict, List, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random as random

View File

@ -2,7 +2,8 @@ import datetime
from collections import OrderedDict
from typing import Any, Dict, Iterable, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.ec2.exceptions import InvalidInstanceIdError
from moto.ec2.models import ec2_backends
from moto.moto_api._internal import mock_random

View File

@ -5,7 +5,8 @@ from typing import Any, Dict, Iterable, List, Optional
from botocore.exceptions import ParamValidationError
from jinja2 import Template
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.exceptions import RESTError
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.ec2.models import ec2_backends

View File

@ -1,10 +1,10 @@
import warnings
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional, Tuple
from dateutil.parser import parse as dtparse
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.emr.exceptions import (
InvalidRequestException,
ResourceNotFoundException,
@ -436,7 +436,7 @@ class ElasticMapReduceBackend(BaseBackend):
result_groups.append(group)
return result_groups
def add_instances(
def run_instances(
self,
cluster_id: str,
instances: Dict[str, Any],
@ -444,7 +444,7 @@ class ElasticMapReduceBackend(BaseBackend):
) -> None:
cluster = self.clusters[cluster_id]
instances["is_instance_type_default"] = not instances.get("instance_type")
response = self.ec2_backend.add_instances(
response = self.ec2_backend.run_instances(
EXAMPLE_AMI_ID, instances["instance_count"], "", [], **instances
)
for instance in response.instances:
@ -648,13 +648,6 @@ class ElasticMapReduceBackend(BaseBackend):
try:
subnet = self.ec2_backend.get_subnet(ec2_subnet_id)
except InvalidSubnetIdError:
warnings.warn(
f"Could not find Subnet with id: {ec2_subnet_id}\n"
"In the near future, this will raise an error.\n"
"Use ec2.describe_subnets() to find a suitable id "
"for your test.",
PendingDeprecationWarning,
)
return default_return_value
manager = EmrSecurityGroupManager(self.ec2_backend, subnet.vpc_id)

View File

@ -402,7 +402,7 @@ class ElasticMapReduceResponse(BaseResponse):
cluster.id, instance_groups
)
for i in range(0, len(instance_group_result)):
self.backend.add_instances(
self.backend.run_instances(
cluster.id, instance_groups[i], instance_group_result[i]
)

View File

@ -3,7 +3,8 @@ import re
from datetime import datetime
from typing import Any, Dict, Iterator, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds
from ..config.exceptions import ValidationException

View File

@ -4,7 +4,8 @@ import re
from datetime import datetime
from typing import Any, Dict, Iterator, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds
from moto.emrcontainers.utils import get_partition, paginated_list

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random
from .exceptions import DomainNotFound

View File

@ -13,7 +13,8 @@ from typing import Any, Dict, List, Optional, Tuple
import requests
from moto import settings
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.exceptions import JsonRESTError
from moto.core.utils import (
iso_8601_datetime_without_milliseconds,

View File

@ -22,7 +22,8 @@ from typing import Any, Dict, List, Optional, Tuple
import requests
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from moto.firehose.exceptions import (
ConcurrentModificationException,

View File

@ -2,7 +2,7 @@ import re
from datetime import datetime
from typing import Dict, List, Optional
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.utils import iso_8601_datetime_without_milliseconds
from .exceptions import (

View File

@ -2,7 +2,8 @@ import datetime
import hashlib
from typing import Any, Dict, List, Optional, Union
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.exceptions import JsonRESTError
from moto.utilities.utils import md5_hash

View File

@ -5,7 +5,8 @@ from collections import OrderedDict
from datetime import datetime
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time, utcnow
from moto.moto_api._internal import mock_random
from moto.moto_api._internal.managed_state_model import ManagedState

View File

@ -4,7 +4,8 @@ from collections import OrderedDict
from datetime import datetime
from typing import Any, Dict, Iterable, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow
from moto.moto_api._internal import mock_random

View File

@ -1,7 +1,8 @@
from datetime import datetime
from typing import Any, Dict, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.moto_api._internal import mock_random
from .exceptions import DetectorNotFoundException, FilterNotFoundException

View File

@ -11,13 +11,9 @@ from cryptography import x509
from cryptography.hazmat.backends import default_backend
from jinja2 import Template
from moto.core import (
DEFAULT_ACCOUNT_ID,
BackendDict,
BaseBackend,
BaseModel,
CloudFormationModel,
)
from moto.core import DEFAULT_ACCOUNT_ID
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.exceptions import RESTError
from moto.core.utils import (
iso_8601_datetime_with_milliseconds,

View File

@ -1,9 +1,9 @@
import warnings
from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional, Tuple
from botocore.exceptions import ParamValidationError
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BaseBackend
from moto.core.models import BackendDict
from moto.moto_api._internal import mock_random
from moto.utilities.paginator import paginate
@ -134,6 +134,9 @@ class IdentityStoreBackend(BaseBackend):
def get_group_id(
self, identity_store_id: str, alternate_identifier: Dict[str, Any]
) -> Tuple[str, str]:
"""
The ExternalId alternate identifier is not yet implemented
"""
identity_store = self.__get_identity_store(identity_store_id)
if "UniqueAttribute" in alternate_identifier:
if (
@ -147,8 +150,6 @@ class IdentityStoreBackend(BaseBackend):
== alternate_identifier["UniqueAttribute"]["AttributeValue"]
):
return g.GroupId, identity_store_id
elif "ExternalId" in alternate_identifier:
warnings.warn("ExternalId has not been implemented.")
raise ResourceNotFoundException(
message="GROUP not found.", resource_type="GROUP"

View File

@ -1,7 +1,8 @@
import json
from typing import Any, Dict, Iterable, List, Optional
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import unix_time
from moto.moto_api._internal import mock_random
from moto.utilities.tagging_service import TaggingService

View File

@ -1,4 +1,4 @@
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
class InstanceMetadataBackend(BaseBackend):

View File

@ -11,7 +11,8 @@ from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from moto.moto_api._internal import mock_random as random
from moto.utilities.paginator import paginate

View File

@ -4,7 +4,8 @@ from typing import Any, Dict, List, Optional, Tuple
import jsondiff
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import merge_dicts
from moto.iot.models import IoTBackend, iot_backends

View File

@ -1,7 +1,7 @@
"""IVSBackend class with methods for supported APIs."""
from typing import Any, Dict, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.ivs.exceptions import ResourceNotFoundException
from moto.moto_api._internal import mock_random
from moto.utilities.paginator import paginate

View File

@ -9,7 +9,8 @@ from gzip import GzipFile
from operator import attrgetter
from typing import Any, Dict, Iterable, List, Optional, Tuple
from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel, CloudFormationModel
from moto.core.utils import unix_time, utcnow
from moto.moto_api._internal import mock_random as random
from moto.utilities.paginator import paginate

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, List
from moto.core import BackendDict, BaseBackend, BaseModel
from moto.core.base_backend import BackendDict, BaseBackend
from moto.core.common_models import BaseModel
from moto.core.utils import utcnow
from moto.moto_api._internal import mock_random as random

View File

@ -1,6 +1,6 @@
from typing import Tuple
from moto.core import BackendDict, BaseBackend
from moto.core.base_backend import BackendDict, BaseBackend
from moto.kinesisvideo.models import KinesisVideoBackend, kinesisvideo_backends
from moto.sts.utils import random_session_token

Some files were not shown because too many files have changed in this diff Show More