From a1990a5153230ae7aea9bac3d06df99b9b58b8e4 Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Sat, 30 Jan 2016 22:26:53 -0500 Subject: [PATCH] issue #95 - convert RDS to boto3 --- awslimitchecker/services/rds.py | 256 ++--- .../tests/services/result_fixtures.py | 1016 +++++++++-------- awslimitchecker/tests/services/test_rds.py | 312 ++--- 3 files changed, 724 insertions(+), 860 deletions(-) diff --git a/awslimitchecker/services/rds.py b/awslimitchecker/services/rds.py index 48d41b85..903f782a 100644 --- a/awslimitchecker/services/rds.py +++ b/awslimitchecker/services/rds.py @@ -38,13 +38,10 @@ """ import abc # noqa -import boto -import boto.rds2 import logging from .base import _AwsService from ..limit import AwsLimit -from ..utils import boto_query_wrapper logger = logging.getLogger(__name__) @@ -57,10 +54,8 @@ def connect(self): """Connect to API if not already connected; set self.conn.""" if self.conn is not None: return - elif self.region: - self.conn = self.connect_via(boto.rds2.connect_to_region) else: - self.conn = boto.connect_rds2() + self.conn = self.connect_client('rds') def find_usage(self): """ @@ -85,40 +80,25 @@ def find_usage(self): def _find_usage_instances(self): """find usage for DB Instances and related limits""" - # instance count - instances = boto_query_wrapper( - self.conn.describe_db_instances, - alc_marker_path=[ - 'DescribeDBInstancesResponse', - 'DescribeDBInstancesResult', - 'Marker' - ], - alc_data_path=[ - 'DescribeDBInstancesResponse', - 'DescribeDBInstancesResult', - 'DBInstances' - ], - alc_marker_param='marker' - ) - instances = instances[ - 'DescribeDBInstancesResponse'][ - 'DescribeDBInstancesResult']['DBInstances'] + count = 0 + allocated_gb = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_db_instances') + for page in paginator.paginate(): + for instance in page['DBInstances']: + count += 1 + allocated_gb += instance['AllocatedStorage'] + self.limits['Read replicas per master']._add_current_usage( + len(instance['ReadReplicaDBInstanceIdentifiers']), + aws_type='AWS::RDS::DBInstance', + resource_id=instance['DBInstanceIdentifier'] + ) + self.limits['DB instances']._add_current_usage( - len(instances), + count, aws_type='AWS::RDS::DBInstance' ) - # per-instance limits - allocated_gb = 0 - for i in instances: - allocated_gb += i['AllocatedStorage'] - self.limits['Read replicas per master']._add_current_usage( - len(i['ReadReplicaDBInstanceIdentifiers']), - aws_type='AWS::RDS::DBInstance', - resource_id=i['DBInstanceIdentifier'] - ) - - # overall storage quota self.limits['Storage quota (GB)']._add_current_usage( allocated_gb, aws_type='AWS::RDS::DBInstance' @@ -126,108 +106,57 @@ def _find_usage_instances(self): def _find_usage_reserved_instances(self): """find usage for reserved instances""" - reserved = boto_query_wrapper( - self.conn.describe_reserved_db_instances, - alc_marker_path=[ - 'DescribeReservedDBInstancesResponse', - 'DescribeReservedDBInstancesResult', - "Marker" - ], - alc_data_path=[ - 'DescribeReservedDBInstancesResponse', - 'DescribeReservedDBInstancesResult', - 'ReservedDBInstances' - ], - alc_marker_param='marker' - )[ - 'DescribeReservedDBInstancesResponse'][ - 'DescribeReservedDBInstancesResult'][ - 'ReservedDBInstances'] + count = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_reserved_db_instances') + for page in paginator.paginate(): + for inst in page['ReservedDBInstances']: + count += 1 self.limits['Reserved Instances']._add_current_usage( - len(reserved), + count, aws_type='AWS::RDS::DBInstance' ) def _find_usage_snapshots(self): """find usage for (manual) DB snapshots""" - snaps = boto_query_wrapper( - self.conn.describe_db_snapshots, - alc_marker_path=[ - "DescribeDBSnapshotsResponse", - "DescribeDBSnapshotsResult", - 'Marker' - ], - alc_data_path=[ - "DescribeDBSnapshotsResponse", - "DescribeDBSnapshotsResult", - "DBSnapshots" - ], - alc_marker_param='marker' - ) - snaps = snaps[ - "DescribeDBSnapshotsResponse"]["DescribeDBSnapshotsResult"][ - "DBSnapshots"] - num_manual_snaps = 0 - for snap in snaps: - if snap['SnapshotType'] == 'manual': - num_manual_snaps += 1 + count = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_db_snapshots') + for page in paginator.paginate(): + for snap in page['DBSnapshots']: + if snap['SnapshotType'] == 'manual': + count += 1 self.limits['DB snapshots per user']._add_current_usage( - num_manual_snaps, + count, aws_type='AWS::RDS::DBSnapshot' ) def _find_usage_param_groups(self): """find usage for parameter groups""" - params = boto_query_wrapper( - self.conn.describe_db_parameter_groups, - alc_marker_path=[ - "DescribeDBParameterGroupsResponse", - "DescribeDBParameterGroupsResult", - 'Marker' - ], - alc_data_path=[ - "DescribeDBParameterGroupsResponse", - "DescribeDBParameterGroupsResult", - "DBParameterGroups" - ], - alc_marker_param='marker' - ) - params = params[ - "DescribeDBParameterGroupsResponse"][ - "DescribeDBParameterGroupsResult"][ - "DBParameterGroups"] + count = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_db_parameter_groups') + for page in paginator.paginate(): + for group in page['DBParameterGroups']: + count += 1 self.limits['DB parameter groups']._add_current_usage( - len(params), + count, aws_type='AWS::RDS::DBParameterGroup' ) def _find_usage_subnet_groups(self): """find usage for subnet groups""" - groups = boto_query_wrapper( - self.conn.describe_db_subnet_groups, - alc_marker_path=[ - "DescribeDBSubnetGroupsResponse", - "DescribeDBSubnetGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeDBSubnetGroupsResponse", - "DescribeDBSubnetGroupsResult", - "DBSubnetGroups" - ], - alc_marker_param='marker' - )[ - "DescribeDBSubnetGroupsResponse"][ - "DescribeDBSubnetGroupsResult"][ - "DBSubnetGroups"] count = 0 - for group in groups: - count += 1 - self.limits['Subnets per Subnet Group']._add_current_usage( - len(group['Subnets']), - aws_type='AWS::RDS::DBSubnetGroup', - resource_id=group["DBSubnetGroupName"], - ) + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_db_subnet_groups') + for page in paginator.paginate(): + for group in page['DBSubnetGroups']: + count += 1 + self.limits['Subnets per Subnet Group']._add_current_usage( + len(group['Subnets']), + aws_type='AWS::RDS::DBSubnetGroup', + resource_id=group["DBSubnetGroupName"], + ) self.limits['Subnet Groups']._add_current_usage( count, aws_type='AWS::RDS::DBSubnetGroup', @@ -235,82 +164,47 @@ def _find_usage_subnet_groups(self): def _find_usage_option_groups(self): """find usage for option groups""" - groups = boto_query_wrapper( - self.conn.describe_option_groups, - alc_marker_path=[ - "DescribeOptionGroupsResponse", - "DescribeOptionGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeOptionGroupsResponse", - "DescribeOptionGroupsResult", - "OptionGroupsList" - ], - alc_marker_param='marker' - )[ - "DescribeOptionGroupsResponse"][ - "DescribeOptionGroupsResult"]["OptionGroupsList"] + count = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_option_groups') + for page in paginator.paginate(): + for group in page['OptionGroupsList']: + count += 1 self.limits['Option Groups']._add_current_usage( - len(groups), + count, aws_type='AWS::RDS::DBOptionGroup', ) def _find_usage_event_subscriptions(self): """find usage for event subscriptions""" - subs = boto_query_wrapper( - self.conn.describe_event_subscriptions, - alc_marker_path=[ - "DescribeEventSubscriptionsResponse", - "DescribeEventSubscriptionsResult", - "Marker" - ], - alc_data_path=[ - "DescribeEventSubscriptionsResponse", - "DescribeEventSubscriptionsResult", - "EventSubscriptionsList" - ], - alc_marker_param='marker' - )[ - "DescribeEventSubscriptionsResponse"][ - "DescribeEventSubscriptionsResult"][ - "EventSubscriptionsList"] + count = 0 + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_event_subscriptions') + for page in paginator.paginate(): + for group in page['EventSubscriptionsList']: + count += 1 self.limits['Event Subscriptions']._add_current_usage( - len(subs), + count, aws_type='AWS::RDS::EventSubscription', ) def _find_usage_security_groups(self): """find usage for security groups""" - groups = boto_query_wrapper( - self.conn.describe_db_security_groups, - alc_marker_path=[ - "DescribeDBSecurityGroupsResponse", - "DescribeDBSecurityGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeDBSecurityGroupsResponse", - "DescribeDBSecurityGroupsResult", - "DBSecurityGroups" - ], - alc_marker_param='marker' - )[ - "DescribeDBSecurityGroupsResponse"][ - "DescribeDBSecurityGroupsResult"][ - "DBSecurityGroups"] vpc_count = 0 classic_count = 0 - for group in groups: - if group['VpcId'] is None: - classic_count += 1 - else: - vpc_count += 1 - self.limits['Max auths per security group']._add_current_usage( - len(group["EC2SecurityGroups"]) + len(group["IPRanges"]), - aws_type='AWS::RDS::DBSecurityGroup', - resource_id=group['DBSecurityGroupName'] - ) + # this boto3 class has a paginator, so no need for boto_query_wrapper + paginator = self.conn.get_paginator('describe_db_security_groups') + for page in paginator.paginate(): + for group in page['DBSecurityGroups']: + if 'VpcId' not in group or group['VpcId'] is None: + classic_count += 1 + else: + vpc_count += 1 + self.limits['Max auths per security group']._add_current_usage( + len(group["EC2SecurityGroups"]) + len(group["IPRanges"]), + aws_type='AWS::RDS::DBSecurityGroup', + resource_id=group['DBSecurityGroupName'] + ) self.limits['DB security groups']._add_current_usage( classic_count, diff --git a/awslimitchecker/tests/services/result_fixtures.py b/awslimitchecker/tests/services/result_fixtures.py index 7629aff4..c97b6e00 100644 --- a/awslimitchecker/tests/services/result_fixtures.py +++ b/awslimitchecker/tests/services/result_fixtures.py @@ -357,530 +357,596 @@ class VPC(object): class RDS(object): - test_find_usage_instances = [ - { - 'PubliclyAccessible': False, - 'MasterUsername': 'myuser', - 'LicenseModel': 'general-public-license', - 'VpcSecurityGroups': [ - { - 'Status': 'active', - 'VpcSecurityGroupId': 'sg-aaaaaaaa' - } - ], - 'InstanceCreateTime': 1429910904.366, - 'OptionGroupMemberships': [ - { - 'Status': 'in-sync', - 'OptionGroupName': 'default:mysql-5-6' - } - ], - 'PendingModifiedValues': { - 'MultiAZ': None, - 'MasterUserPassword': None, - 'Port': None, - 'Iops': None, - 'AllocatedStorage': None, - 'EngineVersion': None, - 'BackupRetentionPeriod': None, - 'DBInstanceClass': None, - 'DBInstanceIdentifier': None - }, - 'Engine': 'mysql', - 'MultiAZ': True, - 'LatestRestorableTime': 1435966800.0, - 'DBSecurityGroups': [ - { - 'Status': 'active', - 'DBSecurityGroupName': 'mydb-dbsecuritygroup-aaaa' - } - ], - 'DBParameterGroups': [ - { - 'DBParameterGroupName': 'default.mysql5.6', - 'ParameterApplyStatus': 'in-sync' - } - ], - 'ReadReplicaSourceDBInstanceIdentifier': None, - 'AutoMinorVersionUpgrade': True, - 'PreferredBackupWindow': '07:00-08:00', - 'DBSubnetGroup': { - 'VpcId': 'vpc-abcdef01', - 'Subnets': [ + test_find_usage_instances = [] + # first result page + test_find_usage_instances.append({ + 'DBInstances': [ + { + 'PubliclyAccessible': False, + 'MasterUsername': 'myuser', + 'LicenseModel': 'general-public-license', + 'VpcSecurityGroups': [ { - 'SubnetStatus': 'Active', - 'SubnetIdentifier': 'subnet-aaaaaaaa', - 'SubnetAvailabilityZone': { - 'Name': 'us-east-1d', - 'ProvisionedIopsCapable': False - } - }, + 'Status': 'active', + 'VpcSecurityGroupId': 'sg-aaaaaaaa' + } + ], + 'InstanceCreateTime': 1429910904.366, + 'OptionGroupMemberships': [ { - 'SubnetStatus': 'Active', - 'SubnetIdentifier': 'subnet-22222222', - 'SubnetAvailabilityZone': { - 'Name': 'us-east-1a', - 'ProvisionedIopsCapable': False - } + 'Status': 'in-sync', + 'OptionGroupName': 'default:mysql-5-6' } ], - 'DBSubnetGroupName': 'mydb-dbsubnetgroup-abcd', - 'SubnetGroupStatus': 'Complete', - 'DBSubnetGroupDescription': 'Subnet group for RDS instance' - }, - 'SecondaryAvailabilityZone': 'us-east-1a', - 'ReadReplicaDBInstanceIdentifiers': [], - 'AllocatedStorage': 200, - 'BackupRetentionPeriod': 7, - 'DBName': 'wordpress', - 'PreferredMaintenanceWindow': 'tue:08:00-tue:09:00', - 'Endpoint': { - 'Port': 3306, - 'Address': 'foo.bar.us-east-1.rds.amazonaws.com' - }, - 'DBInstanceStatus': 'available', - 'StatusInfos': None, - 'EngineVersion': '5.6.22', - 'CharacterSetName': None, - 'AvailabilityZone': 'us-east-1d', - 'Iops': None, - 'DBInstanceClass': 'db.t2.small', - 'DBInstanceIdentifier': 'foo' - }, - { - 'PubliclyAccessible': False, - 'MasterUsername': 'myuser2', - 'LicenseModel': 'postgresql-license', - 'VpcSecurityGroups': [ - { - 'Status': 'active', - 'VpcSecurityGroupId': 'sg-12345678' - } - ], - 'InstanceCreateTime': 1432238504.239, - 'OptionGroupMemberships': [ - { - 'Status': 'in-sync', - 'OptionGroupName': 'default:postgres-9-3' - } - ], - 'PendingModifiedValues': { - 'MultiAZ': None, - 'MasterUserPassword': None, - 'Port': None, - 'Iops': None, - 'AllocatedStorage': None, - 'EngineVersion': None, - 'BackupRetentionPeriod': None, - 'DBInstanceClass': None, - 'DBInstanceIdentifier': None - }, - 'Engine': 'postgres', - 'MultiAZ': False, - 'LatestRestorableTime': 1435966550.0, - 'DBSecurityGroups': [ - { - 'Status': 'active', - 'DBSecurityGroupName': 'sg1234-dbsecuritygroup-abcd' - } - ], - 'DBParameterGroups': [ - { - 'DBParameterGroupName': 'default.postgres9.3', - 'ParameterApplyStatus': 'in-sync' - } - ], - 'ReadReplicaSourceDBInstanceIdentifier': None, - 'AutoMinorVersionUpgrade': True, - 'PreferredBackupWindow': '03:09-03:39', - 'DBSubnetGroup': { - 'VpcId': 'vpc-87654321', - 'Subnets': [ + 'PendingModifiedValues': { + 'MultiAZ': None, + 'MasterUserPassword': None, + 'Port': None, + 'Iops': None, + 'AllocatedStorage': None, + 'EngineVersion': None, + 'BackupRetentionPeriod': None, + 'DBInstanceClass': None, + 'DBInstanceIdentifier': None + }, + 'Engine': 'mysql', + 'MultiAZ': True, + 'LatestRestorableTime': 1435966800.0, + 'DBSecurityGroups': [ { - 'SubnetStatus': 'Active', - 'SubnetIdentifier': 'subnet-a1234567', - 'SubnetAvailabilityZone': { - 'Name': 'us-east-1e', - 'ProvisionedIopsCapable': False - } - }, + 'Status': 'active', + 'DBSecurityGroupName': 'mydb-dbsecuritygroup-aaaa' + } + ], + 'DBParameterGroups': [ { - 'SubnetStatus': 'Active', - 'SubnetIdentifier': 'subnet-b1234567', - 'SubnetAvailabilityZone': { - 'Name': 'us-east-1a', - 'ProvisionedIopsCapable': False + 'DBParameterGroupName': 'default.mysql5.6', + 'ParameterApplyStatus': 'in-sync' + } + ], + 'ReadReplicaSourceDBInstanceIdentifier': None, + 'AutoMinorVersionUpgrade': True, + 'PreferredBackupWindow': '07:00-08:00', + 'DBSubnetGroup': { + 'VpcId': 'vpc-abcdef01', + 'Subnets': [ + { + 'SubnetStatus': 'Active', + 'SubnetIdentifier': 'subnet-aaaaaaaa', + 'SubnetAvailabilityZone': { + 'Name': 'us-east-1d', + 'ProvisionedIopsCapable': False + } + }, + { + 'SubnetStatus': 'Active', + 'SubnetIdentifier': 'subnet-22222222', + 'SubnetAvailabilityZone': { + 'Name': 'us-east-1a', + 'ProvisionedIopsCapable': False + } } - }, + ], + 'DBSubnetGroupName': 'mydb-dbsubnetgroup-abcd', + 'SubnetGroupStatus': 'Complete', + 'DBSubnetGroupDescription': 'Subnet group for RDS instance' + }, + 'SecondaryAvailabilityZone': 'us-east-1a', + 'ReadReplicaDBInstanceIdentifiers': [], + 'AllocatedStorage': 200, + 'BackupRetentionPeriod': 7, + 'DBName': 'wordpress', + 'PreferredMaintenanceWindow': 'tue:08:00-tue:09:00', + 'Endpoint': { + 'Port': 3306, + 'Address': 'foo.bar.us-east-1.rds.amazonaws.com' + }, + 'DBInstanceStatus': 'available', + 'StatusInfos': None, + 'EngineVersion': '5.6.22', + 'CharacterSetName': None, + 'AvailabilityZone': 'us-east-1d', + 'Iops': None, + 'DBInstanceClass': 'db.t2.small', + 'DBInstanceIdentifier': 'foo' + }, + ], + 'NextToken': 'string' + }) + # second result page + test_find_usage_instances.append({ + 'DBInstances': [ + { + 'PubliclyAccessible': False, + 'MasterUsername': 'myuser2', + 'LicenseModel': 'postgresql-license', + 'VpcSecurityGroups': [ { - 'SubnetStatus': 'Active', - 'SubnetIdentifier': 'subnet-c1234567', - 'SubnetAvailabilityZone': { - 'Name': 'us-east-1d', - 'ProvisionedIopsCapable': False - } + 'Status': 'active', + 'VpcSecurityGroupId': 'sg-12345678' } ], - 'DBSubnetGroupName': 'mydb-dbsubnetgroup-abcdef', - 'SubnetGroupStatus': 'Complete', - 'DBSubnetGroupDescription': 'Subnet group for RDS instance' - }, - 'SecondaryAvailabilityZone': None, - 'ReadReplicaDBInstanceIdentifiers': ['db-123', 'db-456'], - 'AllocatedStorage': 50, - 'BackupRetentionPeriod': 1, - 'DBName': 'mydbname', - 'PreferredMaintenanceWindow': 'mon:05:11-mon:05:41', - 'Endpoint': { - 'Port': 5432, - 'Address': 'baz.blam.us-east-1.rds.amazonaws.com' - }, - 'DBInstanceStatus': 'available', - 'StatusInfos': None, - 'EngineVersion': '9.3.6', - 'CharacterSetName': None, - 'AvailabilityZone': 'us-east-1a', - 'Iops': None, - 'DBInstanceClass': 'db.t2.small', - 'DBInstanceIdentifier': 'baz' - } - ] - - test_find_usage_snapshots = { - "DescribeDBSnapshotsResponse": { - "DescribeDBSnapshotsResult": { - "DBSnapshots": [ + 'InstanceCreateTime': 1432238504.239, + 'OptionGroupMemberships': [ { - "AllocatedStorage": 100, - "AvailabilityZone": "us-east-1a", - "DBInstanceIdentifier": "foo-db", - "DBSnapshotIdentifier": "foo-db-final-snapshot", - "Engine": "postgres", - "EngineVersion": "9.3.3", - "InstanceCreateTime": 1408035263.101, - "Iops": 1000, - "LicenseModel": "postgresql-license", - "MasterUsername": "dbfoouser", - "OptionGroupName": "default:postgres-9-3", - "PercentProgress": 100, - "Port": 5432, - "SnapshotCreateTime": 1408454469.536, - "SnapshotType": "manual", - "SourceRegion": None, - "Status": "available", - "VpcId": None - }, + 'Status': 'in-sync', + 'OptionGroupName': 'default:postgres-9-3' + } + ], + 'PendingModifiedValues': { + 'MultiAZ': None, + 'MasterUserPassword': None, + 'Port': None, + 'Iops': None, + 'AllocatedStorage': None, + 'EngineVersion': None, + 'BackupRetentionPeriod': None, + 'DBInstanceClass': None, + 'DBInstanceIdentifier': None + }, + 'Engine': 'postgres', + 'MultiAZ': False, + 'LatestRestorableTime': 1435966550.0, + 'DBSecurityGroups': [ { - "AllocatedStorage": 50, - "AvailabilityZone": "us-east-1d", - "DBInstanceIdentifier": "bd1t3lf90p3lqdx", - "DBSnapshotIdentifier": - "rds:bd1t3lf90p3lqdx-2015-06-29-07-02", - "Engine": "mysql", - "EngineVersion": "5.6.22", - "InstanceCreateTime": 1429910904.366, - "Iops": None, - "LicenseModel": "general-public-license", - "MasterUsername": "dbuser3", - "OptionGroupName": "default:mysql-5-6", - "PercentProgress": 100, - "Port": 3306, - "SnapshotCreateTime": 1435561349.441, - "SnapshotType": "automated", - "SourceRegion": None, - "Status": "available", - "VpcId": "vpc-1ee8937b" - }, + 'Status': 'active', + 'DBSecurityGroupName': 'sg1234-dbsecuritygroup-abcd' + } + ], + 'DBParameterGroups': [ { - "AllocatedStorage": 25, - "AvailabilityZone": "us-east-1d", - "DBInstanceIdentifier": "md1e8qwtegkjdgy", - "DBSnapshotIdentifier": - "rds:md1e8qwtegkjdgy-2015-06-29-07-06", - "Engine": "postgres", - "EngineVersion": "9.3.6", - "InstanceCreateTime": 1433883813.314, - "Iops": None, - "LicenseModel": "postgresql-license", - "MasterUsername": "dbuser4", - "OptionGroupName": "default:postgres-9-3", - "PercentProgress": 100, - "Port": 5432, - "SnapshotCreateTime": 1435561593.669, - "SnapshotType": "automated", - "SourceRegion": None, - "Status": "available", - "VpcId": "vpc-1ee8937b" - }, + 'DBParameterGroupName': 'default.postgres9.3', + 'ParameterApplyStatus': 'in-sync' + } ], - "Marker": - "YXJuOmF3czpyZHM6dXMtZWFzdC0xOjkzNDQ0NjIwOTU0MTpzbm" - "Fwc2hvdDpyZHM6bWQxZThxd3RlZ2tqZGd5LTIwMTUtMDctMDEt" - "MDctMDc=" + 'ReadReplicaSourceDBInstanceIdentifier': None, + 'AutoMinorVersionUpgrade': True, + 'PreferredBackupWindow': '03:09-03:39', + 'DBSubnetGroup': { + 'VpcId': 'vpc-87654321', + 'Subnets': [ + { + 'SubnetStatus': 'Active', + 'SubnetIdentifier': 'subnet-a1234567', + 'SubnetAvailabilityZone': { + 'Name': 'us-east-1e', + 'ProvisionedIopsCapable': False + } + }, + { + 'SubnetStatus': 'Active', + 'SubnetIdentifier': 'subnet-b1234567', + 'SubnetAvailabilityZone': { + 'Name': 'us-east-1a', + 'ProvisionedIopsCapable': False + } + }, + { + 'SubnetStatus': 'Active', + 'SubnetIdentifier': 'subnet-c1234567', + 'SubnetAvailabilityZone': { + 'Name': 'us-east-1d', + 'ProvisionedIopsCapable': False + } + } + ], + 'DBSubnetGroupName': 'mydb-dbsubnetgroup-abcdef', + 'SubnetGroupStatus': 'Complete', + 'DBSubnetGroupDescription': 'Subnet group for RDS instance' + }, + 'SecondaryAvailabilityZone': None, + 'ReadReplicaDBInstanceIdentifiers': ['db-123', 'db-456'], + 'AllocatedStorage': 50, + 'BackupRetentionPeriod': 1, + 'DBName': 'mydbname', + 'PreferredMaintenanceWindow': 'mon:05:11-mon:05:41', + 'Endpoint': { + 'Port': 5432, + 'Address': 'baz.blam.us-east-1.rds.amazonaws.com' + }, + 'DBInstanceStatus': 'available', + 'StatusInfos': None, + 'EngineVersion': '9.3.6', + 'CharacterSetName': None, + 'AvailabilityZone': 'us-east-1a', + 'Iops': None, + 'DBInstanceClass': 'db.t2.small', + 'DBInstanceIdentifier': 'baz' + } + ] + }) + + test_find_usage_snapshots = [] + # first result page + test_find_usage_snapshots.append({ + "DBSnapshots": [ + { + "AllocatedStorage": 100, + "AvailabilityZone": "us-east-1a", + "DBInstanceIdentifier": "foo-db", + "DBSnapshotIdentifier": "foo-db-final-snapshot", + "Engine": "postgres", + "EngineVersion": "9.3.3", + "InstanceCreateTime": 1408035263.101, + "Iops": 1000, + "LicenseModel": "postgresql-license", + "MasterUsername": "dbfoouser", + "OptionGroupName": "default:postgres-9-3", + "PercentProgress": 100, + "Port": 5432, + "SnapshotCreateTime": 1408454469.536, + "SnapshotType": "manual", + "SourceRegion": None, + "Status": "available", + "VpcId": None }, - "ResponseMetadata": { - "RequestId": "5fe976b3-2499-11e5-ad5a-1fed04d9fd3d" + { + "AllocatedStorage": 50, + "AvailabilityZone": "us-east-1d", + "DBInstanceIdentifier": "bd1t3lf90p3lqdx", + "DBSnapshotIdentifier": + "rds:bd1t3lf90p3lqdx-2015-06-29-07-02", + "Engine": "mysql", + "EngineVersion": "5.6.22", + "InstanceCreateTime": 1429910904.366, + "Iops": None, + "LicenseModel": "general-public-license", + "MasterUsername": "dbuser3", + "OptionGroupName": "default:mysql-5-6", + "PercentProgress": 100, + "Port": 3306, + "SnapshotCreateTime": 1435561349.441, + "SnapshotType": "automated", + "SourceRegion": None, + "Status": "available", + "VpcId": "vpc-1ee8937b" + }, + ], + 'NextToken': 'string' + }) + test_find_usage_snapshots.append({ + 'DBSnapshots': [ + { + "AllocatedStorage": 25, + "AvailabilityZone": "us-east-1d", + "DBInstanceIdentifier": "md1e8qwtegkjdgy", + "DBSnapshotIdentifier": + "rds:md1e8qwtegkjdgy-2015-06-29-07-06", + "Engine": "postgres", + "EngineVersion": "9.3.6", + "InstanceCreateTime": 1433883813.314, + "Iops": None, + "LicenseModel": "postgresql-license", + "MasterUsername": "dbuser4", + "OptionGroupName": "default:postgres-9-3", + "PercentProgress": 100, + "Port": 5432, + "SnapshotCreateTime": 1435561593.669, + "SnapshotType": "automated", + "SourceRegion": None, + "Status": "available", + "VpcId": "vpc-1ee8937b" + }, + ], + }) + + test_find_usage_param_groups = [] + test_find_usage_param_groups.append({ + "DBParameterGroups": [ + { + "DBParameterGroupFamily": "mysql5.6", + "DBParameterGroupName": "default.mysql5.6", + "Description": + "Default parameter group for mysql5.6" + }, + ], + 'NextToken': 'string' + }) + test_find_usage_param_groups.append({ + 'DBParameterGroups': [ + { + "DBParameterGroupFamily": "postgres9.3", + "DBParameterGroupName": "default.postgres9.3", + "Description": + "Default parameter group for postgres9.3" } - } - } + ] + }) - test_find_usage_param_groups = { - "DescribeDBParameterGroupsResponse": { - "DescribeDBParameterGroupsResult": { - "DBParameterGroups": [ + test_find_usage_subnet_groups = [] + test_find_usage_subnet_groups.append({ + "DBSubnetGroups": [ + { + "DBSubnetGroupDescription": + "Subnet group for CloudFormation RDS instance", + "DBSubnetGroupName": + "SubnetGroup1", + "SubnetGroupStatus": "Complete", + "Subnets": [ { - "DBParameterGroupFamily": "mysql5.6", - "DBParameterGroupName": "default.mysql5.6", - "Description": - "Default parameter group for mysql5.6" + "SubnetAvailabilityZone": { + "Name": "us-east-1d", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-38e87861", + "SubnetStatus": "Active" }, { - "DBParameterGroupFamily": "postgres9.3", - "DBParameterGroupName": "default.postgres9.3", - "Description": - "Default parameter group for postgres9.3" + "SubnetAvailabilityZone": { + "Name": "us-east-1a", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-4f027f38", + "SubnetStatus": "Active" } ], - "Marker": None + "VpcId": "vpc-1ee8937b" }, - "ResponseMetadata": { - "RequestId": "xxxxxxxxxxxxxxx" - } - } - } - - test_find_usage_subnet_groups = { - "DescribeDBSubnetGroupsResponse": { - "DescribeDBSubnetGroupsResult": { - "DBSubnetGroups": [ + ], + 'NextToken': 'string' + }) + test_find_usage_subnet_groups.append({ + 'DBSubnetGroups': [ + { + "DBSubnetGroupDescription": + "Created from the RDS Management Console", + "DBSubnetGroupName": "default", + "SubnetGroupStatus": "Complete", + "Subnets": [ { - "DBSubnetGroupDescription": - "Subnet group for CloudFormation RDS instance", - "DBSubnetGroupName": - "SubnetGroup1", - "SubnetGroupStatus": "Complete", - "Subnets": [ - { - "SubnetAvailabilityZone": { - "Name": "us-east-1d", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-38e87861", - "SubnetStatus": "Active" - }, - { - "SubnetAvailabilityZone": { - "Name": "us-east-1a", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-4f027f38", - "SubnetStatus": "Active" - } - ], - "VpcId": "vpc-1ee8937b" + "SubnetAvailabilityZone": { + "Name": "us-east-1e", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-49071f61", + "SubnetStatus": "Active" }, { - "DBSubnetGroupDescription": - "Created from the RDS Management Console", - "DBSubnetGroupName": "default", - "SubnetGroupStatus": "Complete", - "Subnets": [ - { - "SubnetAvailabilityZone": { - "Name": "us-east-1e", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-49071f61", - "SubnetStatus": "Active" - }, - { - "SubnetAvailabilityZone": { - "Name": "us-east-1a", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-6fe23c18", - "SubnetStatus": "Active" - }, - { - "SubnetAvailabilityZone": { - "Name": "us-east-1d", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-a9b54df0", - "SubnetStatus": "Active" - } - ], - "VpcId": "vpc-c300b9a6" + "SubnetAvailabilityZone": { + "Name": "us-east-1a", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-6fe23c18", + "SubnetStatus": "Active" }, { - "DBSubnetGroupDescription": - "Subnet group for CloudFormation RDS instance", - "DBSubnetGroupName": - "SubnetGroup2", - "SubnetGroupStatus": "Complete", - "Subnets": [ - { - "SubnetAvailabilityZone": { - "Name": "us-east-1a", - "ProvisionedIopsCapable": False - }, - "SubnetIdentifier": "subnet-0b037e7c", - "SubnetStatus": "Active" - } - ], - "VpcId": "vpc-73ec9716" - }, + "SubnetAvailabilityZone": { + "Name": "us-east-1d", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-a9b54df0", + "SubnetStatus": "Active" + } ], - "Marker": None + "VpcId": "vpc-c300b9a6" }, - "ResponseMetadata": { - "RequestId": "7cd7ed68-2499-11e5-ad44-cdf98c606d42" - } - } - } - - test_find_usage_option_groups = { - "DescribeOptionGroupsResponse": { - "DescribeOptionGroupsResult": { - "Marker": None, - "OptionGroupsList": [ - { - "AllowsVpcAndNonVpcInstanceMemberships": True, - "EngineName": "mysql", - "MajorEngineVersion": "5.6", - "OptionGroupDescription": - "Default option group for mysql 5.6", - "OptionGroupName": "default:mysql-5-6", - "Options": [], - "VpcId": None - }, + { + "DBSubnetGroupDescription": + "Subnet group for CloudFormation RDS instance", + "DBSubnetGroupName": + "SubnetGroup2", + "SubnetGroupStatus": "Complete", + "Subnets": [ { - "AllowsVpcAndNonVpcInstanceMemberships": True, - "EngineName": "postgres", - "MajorEngineVersion": "9.3", - "OptionGroupDescription": - "Default option group for postgres 9.3", - "OptionGroupName": "default:postgres-9-3", - "Options": [], - "VpcId": None + "SubnetAvailabilityZone": { + "Name": "us-east-1a", + "ProvisionedIopsCapable": False + }, + "SubnetIdentifier": "subnet-0b037e7c", + "SubnetStatus": "Active" } - ] + ], + "VpcId": "vpc-73ec9716" }, - "ResponseMetadata": { - "RequestId": "8725ddc9-2499-11e5-9ed1-d5a3270e57f9" - } - } - } + ], + }) - # @TODO update this with realistic test data - test_find_usage_event_subscriptions = { - "DescribeEventSubscriptionsResponse": { - "DescribeEventSubscriptionsResult": { - "EventSubscriptionsList": ['a'], - "Marker": None + test_find_usage_option_groups = [] + test_find_usage_option_groups.append({ + "OptionGroupsList": [ + { + "AllowsVpcAndNonVpcInstanceMemberships": True, + "EngineName": "mysql", + "MajorEngineVersion": "5.6", + "OptionGroupDescription": + "Default option group for mysql 5.6", + "OptionGroupName": "default:mysql-5-6", + "Options": [], + "VpcId": None }, - "ResponseMetadata": { - "RequestId": "91c0b568-2499-11e5-8440-1fb643a72e45" + ], + 'NextToken': 'string' + }) + test_find_usage_option_groups.append({ + 'OptionGroupsList': [ + { + "AllowsVpcAndNonVpcInstanceMemberships": True, + "EngineName": "postgres", + "MajorEngineVersion": "9.3", + "OptionGroupDescription": + "Default option group for postgres 9.3", + "OptionGroupName": "default:postgres-9-3", + "Options": [], + "VpcId": None } - } - } + ] + }) + + test_find_usage_event_subscriptions = [] + test_find_usage_event_subscriptions.append({ + "EventSubscriptionsList": [ + { + 'CustomerAwsId': 'string', + 'CustSubscriptionId': 'string', + 'SnsTopicArn': 'string', + 'Status': 'string', + 'SubscriptionCreationTime': 'string', + 'SourceType': 'string', + 'SourceIdsList': [ + 'string', + ], + 'EventCategoriesList': [ + 'string', + ], + 'Enabled': True + } + ], + "NextToken": 'string' + }) + test_find_usage_event_subscriptions.append({ + "EventSubscriptionsList": [ + { + 'CustomerAwsId': 'string', + 'CustSubscriptionId': 'string', + 'SnsTopicArn': 'string', + 'Status': 'string', + 'SubscriptionCreationTime': 'string', + 'SourceType': 'string', + 'SourceIdsList': [ + 'string', + ], + 'EventCategoriesList': [ + 'string', + ], + 'Enabled': False + } + ] + }) - test_find_usage_security_groups = { - "DescribeDBSecurityGroupsResponse": { - "DescribeDBSecurityGroupsResult": { - "DBSecurityGroups": [ + test_find_usage_security_groups = [] + test_find_usage_security_groups.append({ + "DBSecurityGroups": [ + { + "DBSecurityGroupDescription": "Frontend Access", + "DBSecurityGroupName": + "SecurityGroup1", + "EC2SecurityGroups": [ { - "DBSecurityGroupDescription": "Frontend Access", - "DBSecurityGroupName": - "SecurityGroup1", - "EC2SecurityGroups": [ - { - "EC2SecurityGroupId": "sg-c6dd95a2", - "EC2SecurityGroupName": - "EC2SG1", - "EC2SecurityGroupOwnerId": None, - "Status": "authorized" - } - ], - "IPRanges": [], - "OwnerId": "123456789012", - "VpcId": None + "EC2SecurityGroupId": "sg-c6dd95a2", + "EC2SecurityGroupName": + "EC2SG1", + "EC2SecurityGroupOwnerId": None, + "Status": "authorized" + } + ], + "IPRanges": [], + "OwnerId": "123456789012", + "VpcId": None + }, + { + "DBSecurityGroupDescription": + "default:vpc-a926c2cc", + "DBSecurityGroupName": "default:vpc-a926c2cc", + "EC2SecurityGroups": [], + "IPRanges": [], + "OwnerId": "123456789012", + "VpcId": "vpc-a926c2cc" + }, + ], + 'NextToken': 'string' + }) + test_find_usage_security_groups.append({ + 'DBSecurityGroups': [ + { + "DBSecurityGroupDescription": "Frontend Access", + "DBSecurityGroupName": "SecurityGroup2", + "EC2SecurityGroups": [ + { + "EC2SecurityGroupId": "sg-aaaaaaaa", + "EC2SecurityGroupName": "SGName-aaaaaaaa", + "EC2SecurityGroupOwnerId": None, + "Status": "authorized" }, { - "DBSecurityGroupDescription": - "default:vpc-a926c2cc", - "DBSecurityGroupName": "default:vpc-a926c2cc", - "EC2SecurityGroups": [], - "IPRanges": [], - "OwnerId": "123456789012", - "VpcId": "vpc-a926c2cc" + "EC2SecurityGroupId": "sg-bbbbbbbb", + "EC2SecurityGroupName": "SGName-bbbbbbbb", + "EC2SecurityGroupOwnerId": None, + "Status": "authorized" }, { - "DBSecurityGroupDescription": "Frontend Access", - "DBSecurityGroupName": "SecurityGroup2", - "EC2SecurityGroups": [ - { - "EC2SecurityGroupId": "sg-aaaaaaaa", - "EC2SecurityGroupName": "SGName-aaaaaaaa", - "EC2SecurityGroupOwnerId": None, - "Status": "authorized" - }, - { - "EC2SecurityGroupId": "sg-bbbbbbbb", - "EC2SecurityGroupName": "SGName-bbbbbbbb", - "EC2SecurityGroupOwnerId": None, - "Status": "authorized" - }, - { - "EC2SecurityGroupId": "sg-cccccccc", - "EC2SecurityGroupName": "SGName-cccccccc", - "EC2SecurityGroupOwnerId": None, - "Status": "authorized" - }, - ], - "IPRanges": [], - "OwnerId": "123456789012", - "VpcId": "vpc-73ec9716" + "EC2SecurityGroupId": "sg-cccccccc", + "EC2SecurityGroupName": "SGName-cccccccc", + "EC2SecurityGroupOwnerId": None, + "Status": "authorized" }, + ], + "IPRanges": [], + "OwnerId": "123456789012", + "VpcId": "vpc-73ec9716" + }, + { + 'VpcId': None, + 'DBSecurityGroupDescription': + 'awslimitchecker test', + 'IPRanges': [ { - 'VpcId': None, - 'DBSecurityGroupDescription': - 'awslimitchecker test', - 'IPRanges': [ - { - 'Status': 'authorized', - 'CIDRIP': '76.122.124.15/32' - }, - { - 'Status': 'authorized', - 'CIDRIP': '66.6.152.59/32' - } - ], - 'OwnerId': '123456789012', - 'EC2SecurityGroups': [], - 'DBSecurityGroupName': 'alctest' + 'Status': 'authorized', + 'CIDRIP': '76.122.124.15/32' + }, + { + 'Status': 'authorized', + 'CIDRIP': '66.6.152.59/32' } ], - "Marker": None - }, - "ResponseMetadata": { - "RequestId": "9c78d95d-2499-11e5-9456-735a7f5001de" + 'OwnerId': '123456789012', + 'EC2SecurityGroups': [], + 'DBSecurityGroupName': 'alctest' } - } - } + ], + }) - # @TODO update this with realistic test data - test_find_usage_reserved_instances = { - 'DescribeReservedDBInstancesResponse': { - 'DescribeReservedDBInstancesResult': { - 'Marker': None, - 'ReservedDBInstances': [1, 2] + test_find_usage_reserved_instances = [] + test_find_usage_reserved_instances.append({ + 'ReservedDBInstances': [ + { + 'ReservedDBInstanceId': 'string', + 'ReservedDBInstancesOfferingId': 'string', + 'DBInstanceClass': 'string', + 'StartTime': datetime(2015, 1, 1), + 'Duration': 123, + 'FixedPrice': 123.0, + 'UsagePrice': 123.0, + 'CurrencyCode': 'string', + 'DBInstanceCount': 123, + 'ProductDescription': 'string', + 'OfferingType': 'string', + 'MultiAZ': False, + 'State': 'string', + 'RecurringCharges': [ + { + 'RecurringChargeAmount': 123.0, + 'RecurringChargeFrequency': 'string' + }, + ] }, - 'ResponseMetadata': { - 'RequestId': '75366d86-25a9-11e5-b6fa-c9da955772c6' - } - } - } + ], + 'NextToken': 'string' + }) + test_find_usage_reserved_instances.append({ + 'ReservedDBInstances': [ + { + 'ReservedDBInstanceId': 'string', + 'ReservedDBInstancesOfferingId': 'string', + 'DBInstanceClass': 'string', + 'StartTime': datetime(2015, 1, 1), + 'Duration': 123, + 'FixedPrice': 123.0, + 'UsagePrice': 123.0, + 'CurrencyCode': 'string', + 'DBInstanceCount': 123, + 'ProductDescription': 'string', + 'OfferingType': 'string', + 'MultiAZ': True, + 'State': 'string', + 'RecurringCharges': [ + { + 'RecurringChargeAmount': 123.0, + 'RecurringChargeFrequency': 'string' + }, + ] + }, + ], + }) class ELB(object): diff --git a/awslimitchecker/tests/services/test_rds.py b/awslimitchecker/tests/services/test_rds.py index 217f2e28..d81b6048 100644 --- a/awslimitchecker/tests/services/test_rds.py +++ b/awslimitchecker/tests/services/test_rds.py @@ -39,8 +39,6 @@ import sys import result_fixtures -from boto.rds2.layer1 import RDSConnection -from boto.rds2 import connect_to_region from awslimitchecker.services.rds import _RDSService # https://code.google.com/p/mock/issues/detail?id=249 @@ -70,48 +68,24 @@ def test_init(self): def test_connect(self): """test connect()""" mock_conn = Mock() - mock_conn_via = Mock() cls = _RDSService(21, 43) - with patch('%s.boto.connect_rds2' % self.pbm) as mock_rds: - with patch('%s.connect_via' % self.pb) as mock_connect_via: - mock_rds.return_value = mock_conn - mock_connect_via.return_value = mock_conn_via + with patch('%s.connect_client' % self.pb) as mock_connect_client: + mock_connect_client.return_value = mock_conn cls.connect() - assert mock_rds.mock_calls == [call()] assert mock_conn.mock_calls == [] - assert mock_connect_via.mock_calls == [] + assert mock_connect_client.mock_calls == [call('rds')] assert cls.conn == mock_conn - def test_connect_region(self): - """test connect()""" - mock_conn = Mock() - mock_conn_via = Mock() - cls = _RDSService(21, 43, region='foo') - with patch('%s.boto.connect_rds2' % self.pbm) as mock_rds: - with patch('%s.connect_via' % self.pb) as mock_connect_via: - mock_rds.return_value = mock_conn - mock_connect_via.return_value = mock_conn_via - cls.connect() - assert mock_rds.mock_calls == [] - assert mock_conn.mock_calls == [] - assert mock_connect_via.mock_calls == [ - call(connect_to_region) - ] - assert cls.conn == mock_conn_via - def test_connect_again(self): """make sure we re-use the connection""" mock_conn = Mock() cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('awslimitchecker.services.rds.boto.connect_rds2' - '') as mock_rds: - with patch('%s.connect_via' % self.pb) as mock_connect_via: - mock_rds.return_value = mock_conn + with patch('%s.connect_client' % self.pb) as mock_connect_client: + mock_connect_client.return_value = mock_conn cls.connect() - assert mock_rds.mock_calls == [] assert mock_conn.mock_calls == [] - assert mock_connect_via.mock_calls == [] + assert mock_connect_client.mock_calls == [] def test_get_limits(self): cls = _RDSService(21, 43) @@ -148,7 +122,7 @@ def test_get_limits_again(self): assert res == mock_limits def test_find_usage(self): - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() with patch('%s.connect' % self.pb) as mock_connect: with patch.multiple( @@ -188,38 +162,24 @@ def test_required_iam_permissions(self): ] def test_find_usage_instances(self): - mock_conn = Mock(spec_set=RDSConnection) + instances = result_fixtures.RDS.test_find_usage_instances + + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = instances + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - instances = result_fixtures.RDS.test_find_usage_instances - return_value = { - 'DescribeDBInstancesResponse': { - 'DescribeDBInstancesResult': { - 'DBInstances': instances - } - } - } - - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = return_value - cls._find_usage_instances() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_db_instances, - alc_marker_path=[ - 'DescribeDBInstancesResponse', - 'DescribeDBInstancesResult', - 'Marker' - ], - alc_data_path=[ - 'DescribeDBInstancesResponse', - 'DescribeDBInstancesResult', - 'DBInstances' - ], - alc_marker_param='marker' - ) + cls._find_usage_instances() + + assert mock_conn.mock_calls == [ + call.get_paginator('describe_db_instances'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['DB instances'].get_current_usage()) @@ -242,32 +202,24 @@ def test_find_usage_instances(self): assert usage[1].resource_id == 'baz' def test_find_usage_snapshots(self): - data = result_fixtures.RDS.test_find_usage_snapshots + response = result_fixtures.RDS.test_find_usage_snapshots + + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = response + mock_conn.get_paginator.return_value = mock_paginator - mock_conn = Mock(spec_set=RDSConnection) cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_snapshots() + cls._find_usage_snapshots() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_db_snapshots, - alc_marker_path=[ - "DescribeDBSnapshotsResponse", - "DescribeDBSnapshotsResult", - 'Marker' - ], - alc_data_path=[ - "DescribeDBSnapshotsResponse", - "DescribeDBSnapshotsResult", - "DBSnapshots" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_db_snapshots'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['DB snapshots per user'].get_current_usage()) @@ -278,30 +230,22 @@ def test_find_usage_snapshots(self): def test_find_usage_param_groups(self): data = result_fixtures.RDS.test_find_usage_param_groups - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_param_groups() + cls._find_usage_param_groups() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_db_parameter_groups, - alc_marker_path=[ - "DescribeDBParameterGroupsResponse", - "DescribeDBParameterGroupsResult", - 'Marker' - ], - alc_data_path=[ - "DescribeDBParameterGroupsResponse", - "DescribeDBParameterGroupsResult", - "DBParameterGroups" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_db_parameter_groups'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['DB parameter groups'].get_current_usage()) @@ -312,30 +256,22 @@ def test_find_usage_param_groups(self): def test_find_usage_subnet_groups(self): data = result_fixtures.RDS.test_find_usage_subnet_groups - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_subnet_groups() + cls._find_usage_subnet_groups() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_db_subnet_groups, - alc_marker_path=[ - "DescribeDBSubnetGroupsResponse", - "DescribeDBSubnetGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeDBSubnetGroupsResponse", - "DescribeDBSubnetGroupsResult", - "DBSubnetGroups" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_db_subnet_groups'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['Subnet Groups'].get_current_usage()) @@ -359,30 +295,22 @@ def test_find_usage_subnet_groups(self): def test_find_usage_option_groups(self): data = result_fixtures.RDS.test_find_usage_option_groups - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_option_groups() + cls._find_usage_option_groups() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_option_groups, - alc_marker_path=[ - "DescribeOptionGroupsResponse", - "DescribeOptionGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeOptionGroupsResponse", - "DescribeOptionGroupsResult", - "OptionGroupsList" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_option_groups'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['Option Groups'].get_current_usage()) @@ -393,64 +321,48 @@ def test_find_usage_option_groups(self): def test_find_usage_event_subscriptions(self): data = result_fixtures.RDS.test_find_usage_event_subscriptions - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_event_subscriptions() + cls._find_usage_event_subscriptions() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_event_subscriptions, - alc_marker_path=[ - "DescribeEventSubscriptionsResponse", - "DescribeEventSubscriptionsResult", - "Marker" - ], - alc_data_path=[ - "DescribeEventSubscriptionsResponse", - "DescribeEventSubscriptionsResult", - "EventSubscriptionsList" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_event_subscriptions'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['Event Subscriptions'].get_current_usage()) assert len(usage) == 1 - assert usage[0].get_value() == 1 + assert usage[0].get_value() == 2 assert usage[0].aws_type == 'AWS::RDS::EventSubscription' def test_find_usage_security_groups(self): data = result_fixtures.RDS.test_find_usage_security_groups - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_security_groups() + cls._find_usage_security_groups() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_db_security_groups, - alc_marker_path=[ - "DescribeDBSecurityGroupsResponse", - "DescribeDBSecurityGroupsResult", - "Marker" - ], - alc_data_path=[ - "DescribeDBSecurityGroupsResponse", - "DescribeDBSecurityGroupsResult", - "DBSecurityGroups" - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_db_security_groups'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['DB security groups'].get_current_usage()) @@ -482,30 +394,22 @@ def test_find_usage_security_groups(self): def test_find_usage_reserved_instances(self): data = result_fixtures.RDS.test_find_usage_reserved_instances - mock_conn = Mock(spec_set=RDSConnection) + mock_conn = Mock() + mock_paginator = Mock() + mock_paginator.paginate.return_value = data + mock_conn.get_paginator.return_value = mock_paginator + cls = _RDSService(21, 43) cls.conn = mock_conn - with patch('%s.boto_query_wrapper' % self.pbm) as mock_wrapper: - mock_wrapper.return_value = data - cls._find_usage_reserved_instances() + cls._find_usage_reserved_instances() - assert mock_conn.mock_calls == [] - assert mock_wrapper.mock_calls == [ - call( - mock_conn.describe_reserved_db_instances, - alc_marker_path=[ - 'DescribeReservedDBInstancesResponse', - 'DescribeReservedDBInstancesResult', - "Marker" - ], - alc_data_path=[ - 'DescribeReservedDBInstancesResponse', - 'DescribeReservedDBInstancesResult', - 'ReservedDBInstances' - ], - alc_marker_param='marker' - ) + assert mock_conn.mock_calls == [ + call.get_paginator('describe_reserved_db_instances'), + call.get_paginator().paginate() + ] + assert mock_paginator.mock_calls == [ + call.paginate() ] usage = sorted(cls.limits['Reserved Instances'].get_current_usage())