support - intial commit to kick off trusted advisor checks (#3685)
* support - intial commit to kick off trusted advisor checks * edit - expanded testing to include checking for expected check ids and check names. Added server testing added support resource json to manifest file and simplified support response return from reviewed comments * Streamline loading of resource files * edit - ensured regions are assigned in models Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
e8f1522d1a
commit
4d0ee82f98
14 changed files with 1690 additions and 8 deletions
|
|
@ -120,6 +120,7 @@ mock_kinesisvideoarchivedmedia = lazy_load(
|
|||
".kinesisvideoarchivedmedia", "mock_kinesisvideoarchivedmedia"
|
||||
)
|
||||
mock_medialive = lazy_load(".medialive", "mock_medialive")
|
||||
mock_support = lazy_load(".support", "mock_support")
|
||||
|
||||
# import logging
|
||||
# logging.getLogger('boto').setLevel(logging.CRITICAL)
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ BACKENDS = {
|
|||
"kinesisvideoarchivedmedia_backends",
|
||||
),
|
||||
"forecast": ("forecast", "forecast_backends"),
|
||||
"support": ("support", "support_backends"),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ from moto.core.utils import (
|
|||
)
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.kms import kms_backends
|
||||
from moto.utilities.utils import load_resource
|
||||
from os import listdir
|
||||
|
||||
from .exceptions import (
|
||||
|
|
@ -169,12 +170,7 @@ from .utils import (
|
|||
)
|
||||
|
||||
|
||||
def _load_resource(filename):
|
||||
with open(filename, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
INSTANCE_TYPES = _load_resource(
|
||||
INSTANCE_TYPES = load_resource(
|
||||
resource_filename(__name__, "resources/instance_types.json")
|
||||
)
|
||||
|
||||
|
|
@ -190,10 +186,10 @@ for location_type in listdir(resource_filename(__name__, offerings_path)):
|
|||
)
|
||||
INSTANCE_TYPE_OFFERINGS[location_type][
|
||||
region.replace(".json", "")
|
||||
] = _load_resource(full_path)
|
||||
] = load_resource(full_path)
|
||||
|
||||
|
||||
AMIS = _load_resource(
|
||||
AMIS = load_resource(
|
||||
os.environ.get("MOTO_AMIS_PATH")
|
||||
or resource_filename(__name__, "resources/amis.json"),
|
||||
)
|
||||
|
|
|
|||
6
moto/support/__init__.py
Normal file
6
moto/support/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from .models import support_backends
|
||||
from ..core.models import base_decorator
|
||||
|
||||
support_backend = support_backends["us-east-1"]
|
||||
mock_support = base_decorator(support_backends)
|
||||
1
moto/support/exceptions.py
Normal file
1
moto/support/exceptions.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from __future__ import unicode_literals
|
||||
37
moto/support/models.py
Normal file
37
moto/support/models.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from __future__ import unicode_literals
|
||||
from boto3 import Session
|
||||
from pkg_resources import resource_filename
|
||||
from moto.core import BaseBackend
|
||||
from moto.utilities.utils import load_resource
|
||||
|
||||
|
||||
checks_json = "resources/describe_trusted_advisor_checks.json"
|
||||
ADVISOR_CHECKS = load_resource(resource_filename(__name__, checks_json))
|
||||
|
||||
|
||||
class SupportBackend(BaseBackend):
|
||||
def __init__(self, region_name=None):
|
||||
super(SupportBackend, self).__init__()
|
||||
self.region_name = region_name
|
||||
|
||||
def reset(self):
|
||||
region_name = self.region_name
|
||||
self.__dict__ = {}
|
||||
self.__init__(region_name)
|
||||
|
||||
def describe_trusted_advisor_checks(self, language):
|
||||
# The checks are a static response
|
||||
checks = ADVISOR_CHECKS["checks"]
|
||||
return checks
|
||||
|
||||
|
||||
support_backends = {}
|
||||
|
||||
# Only currently supported in us-east-1
|
||||
support_backends["us-east-1"] = SupportBackend("us-east-1")
|
||||
for region in Session().get_available_regions("support"):
|
||||
support_backends[region] = SupportBackend(region)
|
||||
for region in Session().get_available_regions("support", partition_name="aws-us-gov"):
|
||||
support_backends[region] = SupportBackend(region)
|
||||
for region in Session().get_available_regions("support", partition_name="aws-cn"):
|
||||
support_backends[region] = SupportBackend(region)
|
||||
1491
moto/support/resources/describe_trusted_advisor_checks.json
Normal file
1491
moto/support/resources/describe_trusted_advisor_checks.json
Normal file
File diff suppressed because it is too large
Load diff
20
moto/support/responses.py
Normal file
20
moto/support/responses.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from __future__ import unicode_literals
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import support_backends
|
||||
import json
|
||||
|
||||
|
||||
class SupportResponse(BaseResponse):
|
||||
SERVICE_NAME = "support"
|
||||
|
||||
@property
|
||||
def support_backend(self):
|
||||
return support_backends[self.region]
|
||||
|
||||
def describe_trusted_advisor_checks(self):
|
||||
language = self._get_param("language")
|
||||
checks = self.support_backend.describe_trusted_advisor_checks(
|
||||
language=language,
|
||||
)
|
||||
|
||||
return json.dumps({"checks": checks})
|
||||
11
moto/support/urls.py
Normal file
11
moto/support/urls.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
from .responses import SupportResponse
|
||||
|
||||
url_bases = [
|
||||
"https?://support.(.+).amazonaws.com",
|
||||
]
|
||||
|
||||
|
||||
url_paths = {
|
||||
"{0}/$": SupportResponse.dispatch,
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
import random
|
||||
import string
|
||||
|
||||
|
|
@ -8,3 +9,14 @@ def random_string(length=None):
|
|||
[random.choice(string.ascii_letters + string.digits) for i in range(n)]
|
||||
)
|
||||
return random_str
|
||||
|
||||
|
||||
def load_resource(filename):
|
||||
"""
|
||||
Open a file, and return the contents as JSON.
|
||||
Usage:
|
||||
from pkg_resources import resource_filename
|
||||
load_resource(resource_filename(__name__, "resources/file.json"))
|
||||
"""
|
||||
with open(filename, "r") as f:
|
||||
return json.load(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue