def test_two_facts():
    r = ResourceWithFacts('AName')
    f = Facts()
    f['fact1'] = 'value1'
    f['fact2'] = 'value2'

    r.facts = {'some_key': f}

    assert to_json(ResourceCollection(r)) == to_json({
        'Resources': {
            'AName': {
                'Type': 'ResourceWithFacts',
                'Properties': {
                    'facts': {
                        'some_key': "---\nfact1: value1\nfact2: value2\n"
                    }
                }
            }
        }
    }
    )
Exemplo n.º 2
0
user_data_script = """#!/bin/bash
/usr/bin/cfn-init --region '{AWS.Region}' -s '{AWS.StackName}' -r 'Ec2Instance' --access-key '{CFNKeys}' --secret-key '{CFNKeys.SecretAccessKey}' -v
/usr/bin/cfn-signal -e $? '{WaitHandle}'
while [ ! -e '/dev/xvd{DataVolumeDevice}' ]; do echo Waiting for EBS volume to attach; sleep 5; done
while [ ! "$(hostname -f)" ]; do echo Waiting for FQDN to be set; sleep 5; done;
puppetd --test --waitforcert=120 --color=no --pluginsync --environment={PuppetEnvironment}
""".format(AWS=AWS,
           CFNKeys=CFNKeys,
           WaitHandle=WaitHandle,
           DataVolumeDevice=DataVolumeDevice,
           PuppetEnvironment=PuppetEnvironment)
instance.UserData = user_data_script

Ec2InstanceDNS = AWS.Route53.RecordSet(HostedZoneName=HostedZone + '.',
                                       Name='{0}.'.format(
                                           instance.PrivateDnsName),
                                       Type='A',
                                       ResourceRecords=instance.PrivateIp,
                                       TTL=60)

DNS = AWS.Route53.RecordSet(HostedZoneName=HostedZone + '.',
                            Name='{0}.{1}.{2}.{3}.'.format(
                                ServiceName, Environment, AWS.Region,
                                HostedZone),
                            Type='CNAME',
                            ResourceRecords=Ec2InstanceDNS)

stack = ResourceCollection(locals())
print to_json(stack)
user_data_script = """#!/bin/bash
/usr/bin/cfn-init --region '{AWS.Region}' -s '{AWS.StackName}' -r 'Ec2Instance' --access-key '{CFNKeys}' --secret-key '{CFNKeys.SecretAccessKey}' -v
/usr/bin/cfn-signal -e $? '{WaitHandle}'
while [ ! -e '/dev/xvd{DataVolumeDevice}' ]; do echo Waiting for EBS volume to attach; sleep 5; done
while [ ! "$(hostname -f)" ]; do echo Waiting for FQDN to be set; sleep 5; done;
puppetd --test --waitforcert=120 --color=no --pluginsync --environment={PuppetEnvironment}
""".format(
        AWS=AWS,
        CFNKeys=CFNKeys,
        WaitHandle=WaitHandle,
        DataVolumeDevice=DataVolumeDevice,
        PuppetEnvironment=PuppetEnvironment
        )
instance.UserData = user_data_script

Ec2InstanceDNS = AWS.Route53.RecordSet(
        HostedZoneName=HostedZone + '.',
        Name='{0}.'.format(instance.PrivateDnsName),
        Type='A',
        ResourceRecords=instance.PrivateIp,
        TTL=60)

DNS = AWS.Route53.RecordSet(
        HostedZoneName=HostedZone + '.',
        Name='{0}.{1}.{2}.{3}.'.format(ServiceName, Environment, AWS.Region, HostedZone),
        Type='CNAME',
        ResourceRecords=Ec2InstanceDNS)

stack = ResourceCollection(locals())
print to_json(stack)