def test_incorrect_definitions(self):

        # Test missing definitions
        try:
            RDS(self.incorrect_particle_definition)
        except pcf_exceptions.InvalidUniqueKeysException:
            assert True
        else:
            assert False

        # Test Missing DBInstanceIdentifier

        self.incorrect_particle_definition["aws_resource"] = {}
        try:
            RDS(self.incorrect_particle_definition)
        except pcf_exceptions.InvalidUniqueKeysException:
            assert True
        else:
            assert False
    def test_get_status(self):
        vpc_conn = boto3.client('ec2', 'us-east-1')
        vpc = vpc_conn.create_vpc(CidrBlock='10.0.0.0/16')['Vpc']
        subnet1 = vpc_conn.create_subnet(VpcId=vpc['VpcId'],
                                         CidrBlock='10.1.0.0/24')['Subnet']
        subnet2 = vpc_conn.create_subnet(VpcId=vpc['VpcId'],
                                         CidrBlock='10.1.0.0/26')['Subnet']

        subnet_ids = [subnet1['SubnetId'], subnet2['SubnetId']]
        rds_conn = boto3.client('rds', region_name='us-east-1')
        rds_conn.create_db_subnet_group(
            DBSubnetGroupName='test-subnet',
            DBSubnetGroupDescription='my db subnet',
            SubnetIds=subnet_ids)

        test_def = self.particle_definition['aws_resource']
        rds_conn.create_db_instance(**test_def)

        particle = RDS(self.particle_definition)
        status = particle.get_status()

        assert status['DBInstanceIdentifier'] == 'test-instance'
    def test_apply_states(self):
        #Mock VPC and Subnet Group first to mock RDS successfully.
        vpc_conn = boto3.client('ec2', 'us-east-1')
        vpc = vpc_conn.create_vpc(CidrBlock='10.0.0.0/16')['Vpc']
        subnet1 = vpc_conn.create_subnet(VpcId=vpc['VpcId'],
                                         CidrBlock='10.1.0.0/24')['Subnet']
        subnet2 = vpc_conn.create_subnet(VpcId=vpc['VpcId'],
                                         CidrBlock='10.1.0.0/26')['Subnet']

        subnet_ids = [subnet1['SubnetId'], subnet2['SubnetId']]
        rds_conn = boto3.client('rds', region_name='us-east-1')
        rds_conn.create_db_subnet_group(
            DBSubnetGroupName='test-subnet',
            DBSubnetGroupDescription='my db subnet',
            SubnetIds=subnet_ids)

        particle = RDS(self.particle_definition)

        # Test start
        particle.set_desired_state(State.running)
        self.particle_definition["aws_resource"]["ApplyImmediately"] = True
        self.particle_definition["aws_resource"]["SkipFinalSnapshot"] = True
        particle.apply(sync=False)

        assert particle.get_state() == State.running

        # Test Update
        self.particle_definition["aws_resource"]["EngineVersion"] = "9.5.0"

        particle = RDS(self.particle_definition)
        particle.set_desired_state(State.running)
        particle.apply(sync=True)

        assert particle.get_state() == State.running
        assert particle.current_state_definition[
            'EngineVersion'] == particle.desired_state_definition[
                'EngineVersion']
        assert particle.is_state_definition_equivalent() is True

        # Test Terminate
        particle.set_desired_state(State.terminated)
        particle.apply()

        assert particle.get_state() == State.terminated
    def test_get_current_def(self):
        rds = RDS(self.particle_definition)
        des_def = rds.desired_state_definition

        assert self.particle_definition['aws_resource'] == des_def
示例#5
0
        True,
        "DBParameterGroupName":
        "isrm-postgres96",
        "Tags": [{
            "Key": "email",
            "Value": "*****@*****.**"
        }, {
            "Key": "name",
            "Value": "John Doe"
        }],
        "SkipFinalSnapshot":
        True
    }
}

rds = RDS(particle_definition)

status = rds.get_status()

#Example for creating RDS instance
rds.set_desired_state(State.running)
rds.apply(sync=False)

#Example for updating RDS instance. RDS updates will happen during the maintenance window unless 'ApplyImmediately' field is set to true.
updated_def = particle_definition['aws_resource']['EngineVersion'] = "9.6.3"
rds = RDS(updated_def)
rds.set_desired_state(State.running)
rds.apply(sync=False)

#Example for deleting RDS instance
rds.set_desired_state(State.terminated)