def test_preserve_original_scalyr_key(): ec2 = MagicMock() ec2.describe_images.return_value = { 'Images': [{'BlockDeviceMappings': []}] } saved_instance = { 'ImageId': 'ami-12345678', 'SecurityGroups': [{'GroupId': 'sg-abcdef'}, {'GroupId': 'sg-654321'}], 'InstanceType': 't2.micro', 'SubnetId': 'sn-123', 'PrivateIpAddress': '172.31.128.11', 'IamInstanceProfile': {'Arn': 'arn:barn', 'Id': '123'}, 'Tags': {'Name': 'my-cluster-name'}, 'UserData': { 'source': 'docker.registry/cassandra:101', 'mounts': { '/var/lib/cassandra': { 'partition': '/dev/xvdf' } }, 'scalyr_account_key': 'original-scalyr-key' } } options = { 'cluster_name': 'my-cluster-name', 'taupage_ami_id': None, 'instance_type': None } expected = { 'MinCount': 1, 'MaxCount': 1, 'ImageId': 'ami-12345678', 'SecurityGroupIds': ['sg-abcdef', 'sg-654321'], 'InstanceType': 't2.micro', 'SubnetId': 'sn-123', 'PrivateIpAddress': '172.31.128.11', 'BlockDeviceMappings': [], 'IamInstanceProfile': {'Arn': 'arn:barn'}, 'UserData': { 'source': 'docker.registry/cassandra:101', 'volumes': { 'ebs': { '/dev/xvdf': 'my-cluster-name-172.31.128.11' } }, 'mounts': { '/var/lib/cassandra': { 'partition': '/dev/xvdf' } }, 'scalyr_account_key': 'original-scalyr-key' } } actual = build_run_instances_params(ec2, saved_instance, options) assert actual == expected
def test_build_run_instances_params(): ec2 = MagicMock() ec2.describe_images.return_value = { 'Images': [{'BlockDeviceMappings': []}] } saved_instance = { 'ImageId': 'ami-12345678', 'SecurityGroups': [{'GroupId': 'sg-abcdef'}, {'GroupId': 'sg-654321'}], 'InstanceType': 't2.micro', 'SubnetId': 'sn-123', 'PrivateIpAddress': '172.31.128.11', 'IamInstanceProfile': {'Arn': 'arn:barn', 'Id': '123'}, 'Tags': {'Name': 'my-cluster-name'}, 'Monitoring': { 'State': 'enabled' }, 'UserData': { 'source': 'docker.registry/cassandra:101', 'mounts': { '/var/lib/cassandra': { 'partition': '/dev/xvdf' } }, 'environment': { 'key0': 'keepval0', 'key1': 'oldval1' } } } options = { 'cluster_name': 'my-cluster-name*', 'docker_image': 'docker.registry/cassandra:123', 'taupage_ami_id': 'ami-654321', 'instance_type': 'm4.xlarge', 'environment': { 'key1': 'value1', 'key2': 'value2' }, 'scalyr_region': 'eu', 'scalyr_key': 'new-shiny-scalyr-key', 'rsyslog_format': 'log-format' } expected = { 'MinCount': 1, 'MaxCount': 1, 'ImageId': 'ami-654321', 'SecurityGroupIds': ['sg-abcdef', 'sg-654321'], 'InstanceType': 'm4.xlarge', 'SubnetId': 'sn-123', 'PrivateIpAddress': '172.31.128.11', 'BlockDeviceMappings': [], 'IamInstanceProfile': {'Arn': 'arn:barn'}, 'Monitoring': {'Enabled': True}, 'UserData': { 'source': 'docker.registry/cassandra:123', 'volumes': { 'ebs': { '/dev/xvdf': 'my-cluster-name-172.31.128.11' } }, 'mounts': { '/var/lib/cassandra': { 'partition': '/dev/xvdf' } }, 'environment': { 'key0': 'keepval0', 'key1': 'value1', 'key2': 'value2' }, 'scalyr_region': 'eu', 'scalyr_account_key': 'new-shiny-scalyr-key', 'rsyslog_application_log_format': 'log-format' } } actual = build_run_instances_params(ec2, saved_instance, options) assert actual == expected