EMR: Allow CF deletion of Cluster, Create/Delete of SecurityConfig (#7432)
This commit is contained in:
parent
95e183b6af
commit
4c65c32d40
@ -449,13 +449,64 @@ class FakeCluster(CloudFormationModel):
|
|||||||
cluster.add_tags(tags)
|
cluster.add_tags(tags)
|
||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_from_cloudformation_json( # type: ignore[misc]
|
||||||
|
cls,
|
||||||
|
resource_name: str,
|
||||||
|
cloudformation_json: Dict[str, Any],
|
||||||
|
account_id: str,
|
||||||
|
region_name: str,
|
||||||
|
) -> None:
|
||||||
|
emr_backend: ElasticMapReduceBackend = emr_backends[account_id][region_name]
|
||||||
|
|
||||||
class FakeSecurityConfiguration(BaseModel):
|
emr_backend.terminate_job_flows([resource_name])
|
||||||
|
|
||||||
|
|
||||||
|
class FakeSecurityConfiguration(CloudFormationModel):
|
||||||
def __init__(self, name: str, security_configuration: str):
|
def __init__(self, name: str, security_configuration: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.security_configuration = security_configuration
|
self.security_configuration = security_configuration
|
||||||
self.creation_date_time = datetime.now(timezone.utc)
|
self.creation_date_time = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def physical_resource_id(self) -> str:
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def cloudformation_type() -> str:
|
||||||
|
return "AWS::EMR::SecurityConfiguration"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_from_cloudformation_json( # type: ignore[misc]
|
||||||
|
cls,
|
||||||
|
resource_name: str,
|
||||||
|
cloudformation_json: Any,
|
||||||
|
account_id: str,
|
||||||
|
region_name: str,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> "FakeSecurityConfiguration":
|
||||||
|
emr_backend: ElasticMapReduceBackend = emr_backends[account_id][region_name]
|
||||||
|
|
||||||
|
properties = cloudformation_json["Properties"]
|
||||||
|
return emr_backend.create_security_configuration(
|
||||||
|
name=properties.get("Name") or resource_name,
|
||||||
|
security_configuration=properties.get("SecurityConfiguration", {}),
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_from_cloudformation_json( # type: ignore[misc]
|
||||||
|
cls,
|
||||||
|
resource_name: str,
|
||||||
|
cloudformation_json: Dict[str, Any],
|
||||||
|
account_id: str,
|
||||||
|
region_name: str,
|
||||||
|
) -> None:
|
||||||
|
emr_backend: ElasticMapReduceBackend = emr_backends[account_id][region_name]
|
||||||
|
|
||||||
|
properties = cloudformation_json["Properties"]
|
||||||
|
name = properties.get("Name") or resource_name
|
||||||
|
emr_backend.delete_security_configuration(name)
|
||||||
|
|
||||||
|
|
||||||
class ElasticMapReduceBackend(BaseBackend):
|
class ElasticMapReduceBackend(BaseBackend):
|
||||||
def __init__(self, region_name: str, account_id: str):
|
def __init__(self, region_name: str, account_id: str):
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
|
import pytest
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
|
|
||||||
from moto import mock_aws
|
from moto import mock_aws
|
||||||
from tests import EXAMPLE_AMI_ID
|
from tests import EXAMPLE_AMI_ID
|
||||||
@ -496,6 +498,7 @@ template_with_kerberos_attrs = {
|
|||||||
"securityConfiguration": {
|
"securityConfiguration": {
|
||||||
"Type": "AWS::EMR::SecurityConfiguration",
|
"Type": "AWS::EMR::SecurityConfiguration",
|
||||||
"Properties": {
|
"Properties": {
|
||||||
|
"Name": "mysecconfig",
|
||||||
"SecurityConfiguration": {
|
"SecurityConfiguration": {
|
||||||
"AuthenticationConfiguration": {
|
"AuthenticationConfiguration": {
|
||||||
"KerberosConfiguration": {
|
"KerberosConfiguration": {
|
||||||
@ -511,7 +514,7 @@ template_with_kerberos_attrs = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"emrRole": {
|
"emrRole": {
|
||||||
@ -618,3 +621,14 @@ def test_create_cluster_with_kerberos_attrs():
|
|||||||
"KdcAdminPassword": "adminp2ss",
|
"KdcAdminPassword": "adminp2ss",
|
||||||
"CrossRealmTrustPrincipalPassword": "p2ss",
|
"CrossRealmTrustPrincipalPassword": "p2ss",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Verify everything can be deleted
|
||||||
|
cf.delete_stack(StackName="teststack")
|
||||||
|
|
||||||
|
cl = emr.describe_cluster(ClusterId=cluster_id)["Cluster"]
|
||||||
|
assert cl["Status"]["State"] == "TERMINATED"
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
emr.describe_security_configuration(Name="mysecconfig")
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
assert err["Code"] == "InvalidRequestException"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user