コード例 #1
0
def test_perform_fanout_all_regions_replication(mocker):
    """Test for method of the same name."""

    # make a dummy SNS topic
    mocks.create_sns_topic('ReplicationSnapshotTopic')
    expected_sns_topic = utils.get_topic_arn('ReplicationSnapshotTopic', 'us-east-1')

    dummy_regions = ['us-west-2', 'us-east-1']

    # make some dummy snapshots in two regions
    snapshot_map = {}
    for dummy_region in dummy_regions:
        client = boto3.client('ec2', region_name=dummy_region)
        volume = client.create_volume(Size=100, AvailabilityZone=dummy_region + "a")
        snapshot = client.create_snapshot(VolumeId=volume['VolumeId'])
        snapshot_map[snapshot['SnapshotId']] = dummy_region

    # patch the final message sender method
    ctx = utils.MockContext()
    mocker.patch('ebs_snapper.replication.send_fanout_message')
    replication.perform_fanout_all_regions(ctx)

    # fan out, and be sure we touched every instance we created before
    for r in dummy_regions:
        replication.send_fanout_message.assert_any_call(
            context=ctx,
            region=r,
            sns_topic=expected_sns_topic,
            cli=False)  # pylint: disable=E1103
コード例 #2
0
def test_get_topic_arn():
    """Test for method of the same name."""
    topic_name = 'please-dont-exist'

    # make an SNS topic
    mocks.create_sns_topic(topic_name, region_name='us-west-2')

    # see if our code can find it!
    found_arn = utils.get_topic_arn(topic_name, default_region='us-west-2')
    assert 'us-west-2' in found_arn
    assert topic_name in found_arn
コード例 #3
0
ファイル: test_clean.py プロジェクト: rscdupree/ebs_snapper
def test_send_fanout_message_clean(mocker):
    """Test for method of the same name."""

    mocks.create_sns_topic('testing-topic')
    expected_sns_topic = utils.get_topic_arn('testing-topic', 'us-east-1')
    ctx = utils.MockContext()

    mocker.patch('ebs_snapper.utils.sns_publish')
    clean.send_fanout_message(ctx, region='us-west-2', topic_arn=expected_sns_topic)
    utils.sns_publish.assert_any_call(  # pylint: disable=E1103
        TopicArn=expected_sns_topic,
        Message=json.dumps({'region': 'us-west-2'}))
コード例 #4
0
def perform_fanout_all_regions(context, cli=False):
    """For every region, run the supplied function"""
    # get regions, regardless of instances
    sns_topic = utils.get_topic_arn('CleanSnapshotTopic')
    LOG.debug('perform_fanout_all_regions using SNS topic %s', sns_topic)

    regions = utils.get_regions(must_contain_instances=True)
    for region in regions:
        sleep(5)  # API limit relief
        send_fanout_message(context,
                            region=region,
                            topic_arn=sns_topic,
                            cli=cli)

    LOG.info('Function clean_perform_fanout_all_regions completed')
コード例 #5
0
def perform_fanout_all_regions(context, cli=False):
    """For every region, send a message (lambda) or run replication (cli)"""

    sns_topic = utils.get_topic_arn('ReplicationSnapshotTopic')
    LOG.debug('perform_fanout_all_regions using SNS topic %s', sns_topic)

    # get regions with instances running or stopped
    regions = utils.get_regions(must_contain_snapshots=True)
    for region in regions:
        sleep(5)  # API rate limiting help

        send_fanout_message(context=context,
                            region=region,
                            sns_topic=sns_topic,
                            cli=cli)
コード例 #6
0
def perform_fanout_all_regions(context, cli=False):
    """For every region, run the supplied function"""

    sns_topic = utils.get_topic_arn('CreateSnapshotTopic')
    LOG.debug('perform_fanout_all_regions using SNS topic %s', sns_topic)

    # get regions with instances running or stopped
    regions = utils.get_regions(must_contain_instances=True)
    for region in regions:
        sleep(5)  # API rate limiting help

        send_fanout_message(context=context,
                            region=region,
                            sns_topic=sns_topic,
                            cli=cli)
コード例 #7
0
def test_perform_fanout_all_regions_snapshot(mocker):
    """Test for method of the same name."""

    # make a dummy SNS topic
    mocks.create_event_rule('ScheduledRuleReplicationFunction')
    mocks.create_sns_topic('CreateSnapshotTopic')
    expected_sns_topic = utils.get_topic_arn('CreateSnapshotTopic',
                                             'us-east-1')

    dummy_regions = ['us-west-2', 'us-east-1']

    # make some dummy instances in two regions
    instance_maps = {}
    for dummy_region in dummy_regions:
        client = boto3.client('ec2', region_name=dummy_region)
        create_results = client.run_instances(ImageId='ami-123abc',
                                              MinCount=5,
                                              MaxCount=5)
        for instance_data in create_results['Instances']:
            instance_maps[instance_data['InstanceId']] = dummy_region

    # need to filter instances, so need dynamodb present
    mocks.create_dynamodb('us-east-1')
    config_data = {
        "match": {
            "instance-id": instance_maps.keys()
        },
        "snapshot": {
            "retention": "3 days",
            "minimum": 4,
            "frequency": "11 hours"
        }
    }
    dynamo.store_configuration('us-east-1', 'some_unique_id', AWS_MOCK_ACCOUNT,
                               config_data)

    # patch the final message sender method
    ctx = utils.MockContext()
    mocker.patch('ebs_snapper.snapshot.send_fanout_message')
    snapshot.perform_fanout_all_regions(ctx)

    # fan out, and be sure we touched every instance we created before
    for r in dummy_regions:
        snapshot.send_fanout_message.assert_any_call(
            context=ctx, region=r, sns_topic=expected_sns_topic, cli=False)  # pylint: disable=E1103
コード例 #8
0
def perform_fanout_all_regions(context, cli=False, installed_region='us-east-1'):
    """For every region, send a message (lambda) or run snapshots (cli)"""

    sns_topic = utils.get_topic_arn('CreateSnapshotTopic')
    LOG.debug('perform_fanout_all_regions using SNS topic %s', sns_topic)

    # configure replication based on extant configs for snapshots
    if type(context) is not MockContext:  # don't do in unit tests
        ensure_cloudwatch_rule_for_replication(context, installed_region)

    # get regions with instances running or stopped
    regions = utils.get_regions(must_contain_instances=True)
    for region in regions:
        sleep(5)  # API rate limiting help

        send_fanout_message(
            context=context,
            region=region,
            sns_topic=sns_topic,
            cli=cli)
コード例 #9
0
ファイル: test_clean.py プロジェクト: rscdupree/ebs_snapper
def test_perform_fanout_all_regions_clean(mocker):
    """Test for method of the same name."""
    mocks.create_sns_topic('CleanSnapshotTopic')
    mocks.create_dynamodb()

    expected_regions = utils.get_regions()
    for r in expected_regions:  # must have an instance in the region to clean it
        mocks.create_instances(region=r)
    expected_sns_topic = utils.get_topic_arn('CleanSnapshotTopic', 'us-east-1')

    ctx = utils.MockContext()
    mocker.patch('ebs_snapper.clean.send_fanout_message')

    # fan out, and be sure we touched every region
    clean.perform_fanout_all_regions(ctx)
    for r in expected_regions:
        clean.send_fanout_message.assert_any_call(  # pylint: disable=E1103
            ctx,
            cli=False,
            region=r,
            topic_arn=expected_sns_topic)