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
示例#2
0
        "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)
rds.apply(sync=False)
print(rds.get_state())