Example #1
0
def test_prints_changes(logger):
    cf_client_mock = Mock()
    cf_client_mock.describe_change_set.return_value = CHANGESETCHANGES
    change_set = ChangeSet(STACK, cf_client_mock)

    change_set.describe()

    change_set_output = '\n'.join([call[1][0] for call in logger.info.mock_calls])

    to_search = []
    to_search.extend(CHANGE_SET_HEADER)
    to_search.extend(['Remove', 'Modify', 'Add'])
    to_search.extend(['DeploymentBucket', 'DeploymentBucket2', 'DeploymentBucket3'])
    to_search.extend(['simpleteststack-deploymentbucket-1l7p61v6fxpry ',
                      'simpleteststack-deploymentbucket2-11ngaeftydtn7 '])
    to_search.extend(['AWS::S3::Bucket'])
    to_search.extend(['True'])
    to_search.extend(['BucketName, Tags'])
    # Parameters
    to_search.extend(['bucketname=formicatestbucketname, bucketname2=formicatestbucketname2'])
    # Capabilities
    to_search.extend(['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'])
    # Stack Tags
    to_search.extend(['StackKey=StackValue, StackKey2=StackValue2'])
    for term in to_search:
        assert term in change_set_output

    assert 'None' not in change_set_output
Example #2
0
def test_only_prints_unique_changed_parameters(logger, client):
    client.describe_change_set.return_value = CHANGESETCHANGES_WITH_DUPLICATE_CHANGED_PARAMETER
    change_set = ChangeSet(STACK)

    change_set.describe()

    change_set_output = logger.info.call_args[0][0]

    assert change_set_output.count('BucketName') == 1
Example #3
0
def change(args):
    client = AWS.current_session().client('cloudformation')
    loader = Loader()
    loader.load()

    change_set = ChangeSet(stack=args.stack, client=client)
    change_set.create(template=loader.template(),
                      change_set_type='UPDATE',
                      parameters=args.parameters,
                      tags=args.tags,
                      capabilities=args.capabilities)
    change_set.describe()
Example #4
0
def new(args):
    client = AWS.current_session().client('cloudformation')
    loader = Loader()
    loader.load()
    logger.info('Creating change set for new stack, ...')
    change_set = ChangeSet(stack=args.stack, client=client)
    change_set.create(template=loader.template(),
                      change_set_type='CREATE',
                      parameters=args.parameters,
                      tags=args.tags,
                      capabilities=args.capabilities)
    change_set.describe()
    logger.info('Change set created, please deploy')
Example #5
0
def test_change_set_without_named_properties(client):
    CHANGESET = copy.deepcopy(CHANGESETCHANGES)

    # Find a property change in the changeset
    PROPERTY_CHANGE = CHANGESET['Changes'][1]['ResourceChange']['Details'][1]
    assert PROPERTY_CHANGE['Target']['Attribute'] == 'Properties'
    assert PROPERTY_CHANGE['Target']['Name'] == 'BucketName'

    # Remove the "Name" attribute
    del PROPERTY_CHANGE['Target']['Name']

    client.describe_change_set.return_value = CHANGESET

    change_set = ChangeSet(STACK)
    change_set.describe()
Example #6
0
def test_prints_nested_changes(logger, client):
    client.describe_change_set.side_effect = [CHANGESET_NESTED_CHANGES, CHANGESETCHANGES]
    change_set = ChangeSet(STACK)

    change_set.describe()

    change_set_output = '\n'.join([call[1][0] for call in logger.info.mock_calls])
    print(change_set_output)

    to_search = []
    to_search.extend(CHANGE_SET_HEADER)
    to_search.extend(['Changes for nested Stack: NestedStack'])
    to_search.extend(['NestedStack'])
    to_search.extend(['Remove', 'Modify', 'Add'])
    to_search.extend(['DeploymentBucket', 'DeploymentBucket2', 'DeploymentBucket3'])
    to_search.extend(['simpleteststack-deploymentbucket-1l7p61v6fxpry ',
                      'simpleteststack-deploymentbucket2-11ngaeftydtn7 '])
    to_search.extend(['AWS::S3::Bucket'])
    to_search.extend(['True'])
    to_search.extend(['BucketName, Tags'])
    for term in to_search:
        assert term in change_set_output

    assert 'None' not in change_set_output
Example #7
0
def test_prints_nested_changes(logger, client):
    client.describe_change_set.side_effect = [CHANGESET_NESTED_STACK_NO_NESTED_CHANGESET]
    change_set = ChangeSet(STACK)
    change_set.describe()
Example #8
0
def describe(args):
    client = AWS.current_session().client('cloudformation')
    change_set = ChangeSet(stack=args.stack, client=client)
    change_set.describe()