Fix:RDS:add DBParameterGroupArn in describe-db-parameter-groups & cre… (#3462)

* Fix:RDS:add DBParameterGroupArn in describe-db-parameter-groups & create-db-parameter-group

* Test change

* Fixed tests

* tests change acconutID

* linting

Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
usmangani1 2020-12-02 01:23:01 +05:30 committed by GitHub
parent 72e616cb48
commit b2adcdf518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -9,7 +9,8 @@ from boto3 import Session
from jinja2 import Template
from re import compile as re_compile
from moto.compat import OrderedDict
from moto.core import BaseBackend, BaseModel, CloudFormationModel
from moto.core import BaseBackend, BaseModel, CloudFormationModel, ACCOUNT_ID
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.ec2.models import ec2_backends
from .exceptions import (
@ -157,6 +158,7 @@ class Database(CloudFormationModel):
family=db_family,
description=description,
tags={},
region=self.region,
)
]
else:
@ -1172,7 +1174,7 @@ class RDS2Backend(BaseBackend):
"InvalidParameterValue",
"The parameter DBParameterGroupName must be provided and must not be blank.",
)
db_parameter_group_kwargs["region"] = self.region
db_parameter_group = DBParameterGroup(**db_parameter_group_kwargs)
self.db_parameter_groups[db_parameter_group_id] = db_parameter_group
return db_parameter_group
@ -1471,13 +1473,18 @@ class OptionGroupOptionSetting(object):
return template.render(option_group_option_setting=self)
def make_rds_arn(region, name):
return "arn:aws:rds:{0}:{1}:pg:{2}".format(region, ACCOUNT_ID, name)
class DBParameterGroup(CloudFormationModel):
def __init__(self, name, description, family, tags):
def __init__(self, name, description, family, tags, region):
self.name = name
self.description = description
self.family = family
self.tags = tags
self.parameters = defaultdict(dict)
self.arn = make_rds_arn(region, name)
def to_xml(self):
template = Template(
@ -1485,6 +1492,7 @@ class DBParameterGroup(CloudFormationModel):
<DBParameterGroupName>{{ param_group.name }}</DBParameterGroupName>
<DBParameterGroupFamily>{{ param_group.family }}</DBParameterGroupFamily>
<Description>{{ param_group.description }}</Description>
<DBParameterGroupArn>{{ param_group.arn }}</DBParameterGroupArn>
</DBParameterGroup>"""
)
return template.render(param_group=self)

View File

@ -4,6 +4,7 @@ from botocore.exceptions import ClientError, ParamValidationError
import boto3
import sure # noqa
from moto import mock_ec2, mock_kms, mock_rds2
from moto.core import ACCOUNT_ID
@mock_rds2
@ -1504,7 +1505,9 @@ def test_create_database_with_encrypted_storage():
@mock_rds2
def test_create_db_parameter_group():
conn = boto3.client("rds", region_name="us-west-2")
region = "us-west-2"
pg_name = "test"
conn = boto3.client("rds", region_name=region)
db_parameter_group = conn.create_db_parameter_group(
DBParameterGroupName="test",
DBParameterGroupFamily="mysql5.6",
@ -1518,6 +1521,9 @@ def test_create_db_parameter_group():
db_parameter_group["DBParameterGroup"]["Description"].should.equal(
"test parameter group"
)
db_parameter_group["DBParameterGroup"]["DBParameterGroupArn"].should.equal(
"arn:aws:rds:{0}:{1}:pg:{2}".format(region, ACCOUNT_ID, pg_name)
)
@mock_rds2
@ -1629,9 +1635,11 @@ def test_create_db_parameter_group_duplicate():
@mock_rds2
def test_describe_db_parameter_group():
conn = boto3.client("rds", region_name="us-west-2")
region = "us-west-2"
pg_name = "test"
conn = boto3.client("rds", region_name=region)
conn.create_db_parameter_group(
DBParameterGroupName="test",
DBParameterGroupName=pg_name,
DBParameterGroupFamily="mysql5.6",
Description="test parameter group",
)
@ -1639,6 +1647,9 @@ def test_describe_db_parameter_group():
db_parameter_groups["DBParameterGroups"][0]["DBParameterGroupName"].should.equal(
"test"
)
db_parameter_groups["DBParameterGroups"][0]["DBParameterGroupArn"].should.equal(
"arn:aws:rds:{0}:{1}:pg:{2}".format(region, ACCOUNT_ID, pg_name)
)
@mock_rds2