def test_launch_config_edit(sys, read_input): add_launch_config( "web", user_data="echo 'web_machine' > /etc/config", spot_price=0.2, instance_monitoring=True, ) sys.argv = [ 'autoscaler_launch_config', 'edit', 'web', ] # "image_id", "key_name", "security_groups", "user_data", "instance_type", # "kernel_id", "ramdisk_id", "block_device_mappings", "instance_monitoring" # "instance_profile_name", "spot_price", "ebs_optimized", "associate_public_ip_address" read_input.side_effect = [ "", "", "", "echo 'other_machine' > /etc/config", "", "", "", "", "yes", "arn:aws:iam::123456789012:instance-profile/tester", "0.1", "yes", "yes", ] # Simulate CLI call launch_config() list(read_input.mock_calls).should.equal([ call('What image_id?', u'None'), call('What key_name?', ''), call('What security_groups?', ''), call('What user_data?', "echo 'web_machine' > /etc/config"), call('What instance_type?', u'm1.small'), call('What kernel_id?', ''), call('What ramdisk_id?', ''), call('What block_device_mappings?', BlockDeviceMapping()), call('What instance_monitoring?', "yes"), call('What instance_profile_name?', None), call('What spot_price?', 0.2), call('What ebs_optimized?', "no"), call('What associate_public_ip_address?', False), ]) conn = boto.connect_autoscale(use_block_device_types=True) configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'other_machine' > /etc/config") web_config.spot_price.should.equal(0.1) web_config.ebs_optimized.should.equal(True) web_config.associate_public_ip_address.should.equal(True)
def test_launch_config_edit(sys, user_input): add_launch_config("web", user_data="echo 'web_machine' > /etc/config") sys.argv = [ 'autoscaler_launch_config', 'edit', 'web', ] # "image_id", "key_name", "security_groups", "user_data", "instance_type", # "kernel_id", "ramdisk_id", "block_device_mappings", "instance_monitoring" user_input.side_effect = [ "", "", "", "echo 'other_machine' > /etc/config", "", "", "", "", "yes", "arn:aws:iam::123456789012:instance-profile/tester", "", ] # Simulate CLI call launch_config() conn = boto.connect_autoscale() configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'other_machine' > /etc/config")
def test_add_launch_configuration_with_named_base(): conn = boto.connect_autoscale() config = LaunchConfiguration( name='named_default_copy_from', image_id='ami-1234abcd', key_name='tester', security_groups=["default"], user_data="echo 'default_machine' > /etc/config", instance_type='m1.large', instance_monitoring=True, instance_profile_name='arn:aws:iam::123456789012:instance-profile/tester', spot_price=0.1, ) conn.create_launch_configuration(config) conn.get_all_launch_configurations().should.have.length_of(1) add_launch_config("web", base='named_default_copy_from', user_data="echo 'web_machine' > /etc/config") configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'web_machine' > /etc/config") web_config.image_id.should.equal('ami-1234abcd') web_config.key_name.should.equal('tester') web_config.instance_profile_name.should.equal('arn:aws:iam::123456789012:instance-profile/tester') web_config.spot_price.should.equal(0.1)
def test_add_launch_configuration_with_named_base(): conn = boto.connect_autoscale() config = LaunchConfiguration( name='named_default_copy_from', image_id='ami-1234abcd', key_name='tester', security_groups=["default"], user_data="echo 'default_machine' > /etc/config", instance_type='m1.large', instance_monitoring=True, instance_profile_name= 'arn:aws:iam::123456789012:instance-profile/tester', spot_price=0.1, ) conn.create_launch_configuration(config) conn.get_all_launch_configurations().should.have.length_of(1) add_launch_config("web", base='named_default_copy_from', user_data="echo 'web_machine' > /etc/config") configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'web_machine' > /etc/config") web_config.image_id.should.equal('ami-1234abcd') web_config.key_name.should.equal('tester') web_config.instance_profile_name.should.equal( 'arn:aws:iam::123456789012:instance-profile/tester') web_config.spot_price.should.equal(0.1)
def test_launch_config_edit(sys, read_input): add_launch_config( "web", user_data="echo 'web_machine' > /etc/config", spot_price=0.2, instance_monitoring=True, ) sys.argv = [ 'autoscaler_launch_config', 'edit', 'web', ] # "image_id", "key_name", "security_groups", "user_data", "instance_type", # "kernel_id", "ramdisk_id", "block_device_mappings", "instance_monitoring" # "instance_profile_name", "spot_price", "ebs_optimized", "associate_public_ip_address" read_input.side_effect = [ "", "", "", "echo 'other_machine' > /etc/config", "", "", "", "", "yes", "arn:aws:iam::123456789012:instance-profile/tester", "0.1", "yes", "yes", ] # Simulate CLI call launch_config() list(read_input.mock_calls).should.equal([ call('What image_id?', u'None'), call('What key_name?', ''), call('What security_groups?', ''), call('What user_data?', "echo 'web_machine' > /etc/config"), call('What instance_type?', u'm1.small'), call('What kernel_id?', ''), call('What ramdisk_id?', ''), call('What block_device_mappings?', []), call('What instance_monitoring?', "yes"), call('What instance_profile_name?', None), call('What spot_price?', 0.2), call('What ebs_optimized?', "no"), call('What associate_public_ip_address?', False), ]) conn = boto.connect_autoscale() configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'other_machine' > /etc/config") web_config.spot_price.should.equal(0.1) web_config.ebs_optimized.should.equal(True) web_config.associate_public_ip_address.should.equal(True)
def test_add_launch_configuration(): add_launch_config("web", user_data="echo 'web_machine' > /etc/config") conn = boto.connect_autoscale() configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'web_machine' > /etc/config")
def test_autoscaling_group_add(sys, user_input): sys.argv = [ 'autoscaler_auto_scaling_group', 'add', 'web', ] # INPUTS # "availability_zones", "default_cooldown", "desired_capacity", # "health_check_period", "health_check_type", "launch_config_name", # "load_balancers", "max_size", "min_size", "placement_group", # "vpc_zone_identifier", "termination_policies" user_input.side_effect = [ 'us-east-1b,us-east-1c', '60', "2", "", "", "web_config", "", "2", "2", "", "", "", ] # Create the launch config add_launch_config("web_config") # Simulate CLI call autoscaling_group() conn = boto.connect_autoscale(use_block_device_types=True) configs = conn.get_all_groups() configs.should.have.length_of(1) config = configs[0] config.name.should.equal("web") set(config.availability_zones).should.equal( set(["us-east-1b", "us-east-1c"])) config.default_cooldown.should.equal(60) config.desired_capacity.should.equal(2) config.health_check_period.should.equal(None) config.health_check_type.should.equal("EC2") config.launch_config_name.should.equal("web_config") list(config.load_balancers).should.equal([]) config.max_size.should.equal(2) config.min_size.should.equal(2) config.placement_group.should.equal(None) config.vpc_zone_identifier.should.equal("") list(config.termination_policies).should.equal([])
def test_autoscaling_group_add(sys, user_input): sys.argv = [ 'autoscaler_auto_scaling_group', 'add', 'web', ] # INPUTS # "availability_zones", "default_cooldown", "desired_capacity", # "health_check_period", "health_check_type", "launch_config_name", # "load_balancers", "max_size", "min_size", "placement_group", # "vpc_zone_identifier", "termination_policies" user_input.side_effect = [ 'us-east-1b,us-east-1c', '60', "2", "", "", "web_config", "", "2", "2", "", "", "", ] # Create the launch config add_launch_config("web_config") # Simulate CLI call autoscaling_group() conn = boto.connect_autoscale() configs = conn.get_all_groups() configs.should.have.length_of(1) config = configs[0] config.name.should.equal("web") set(config.availability_zones).should.equal(set(["us-east-1b", "us-east-1c"])) config.default_cooldown.should.equal(60) config.desired_capacity.should.equal(2) config.health_check_period.should.equal(None) config.health_check_type.should.equal("EC2") config.launch_config_name.should.equal("web_config") list(config.load_balancers).should.equal([]) config.max_size.should.equal(2) config.min_size.should.equal(2) config.placement_group.should.equal(None) config.vpc_zone_identifier.should.equal("") list(config.termination_policies).should.equal([])
def test_add_autoscaling_groups(): add_launch_config("web_config", user_data="echo 'web_machine' > /etc/config") add_auto_scaling_group( "web", availability_zones=['us-east-1c'], max_size=2, min_size=2, launch_config='web_config', ) conn = boto.connect_autoscale(use_block_device_types=True) configs = conn.get_all_groups(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.max_size.should.equal(2)
def test_autoscaling_group_edit(sys, user_input): add_launch_config("web_config", user_data="echo 'web_machine' > /etc/config") add_auto_scaling_group( "web", availability_zones=['us-east-1c'], max_size=2, min_size=2, launch_config='web_config', ) sys.argv = [ 'autoscaler_auto_scaling_group', 'edit', 'web', ] # INPUTS # "availability_zones", "default_cooldown", "desired_capacity", # "health_check_period", "health_check_type", "launch_config_name", # "load_balancers", "max_size", "min_size", "placement_group", # "vpc_zone_identifier", "termination_policies" user_input.side_effect = [ 'us-east-1b,us-east-1c', '60', "2", "", "", "web_config", "", "1", "2", "", "", "", ] # Create the launch config add_launch_config("web_config") # Simulate CLI call autoscaling_group() conn = boto.connect_autoscale(use_block_device_types=True) configs = conn.get_all_groups(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.max_size.should.equal(1)
def test_autoscaling_group_edit(sys, user_input): add_launch_config("web_config", user_data="echo 'web_machine' > /etc/config") add_auto_scaling_group( "web", availability_zones=['us-east-1c'], max_size=2, min_size=2, launch_config='web_config', ) sys.argv = [ 'autoscaler_auto_scaling_group', 'edit', 'web', ] # INPUTS # "availability_zones", "default_cooldown", "desired_capacity", # "health_check_period", "health_check_type", "launch_config_name", # "load_balancers", "max_size", "min_size", "placement_group", # "vpc_zone_identifier", "termination_policies" user_input.side_effect = [ 'us-east-1b,us-east-1c', '60', "2", "", "", "web_config", "", "1", "2", "", "", "", ] # Create the launch config add_launch_config("web_config") # Simulate CLI call autoscaling_group() conn = boto.connect_autoscale() configs = conn.get_all_groups(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.max_size.should.equal(1)
def test_edit_launch_configuration(): add_launch_config("web", user_data="echo 'web_machine' > /etc/config") conn = boto.connect_autoscale() configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'web_machine' > /etc/config") # Now edit the user data edit_launch_config("web", user_data="echo 'other_machine' > /etc/config") configs = conn.get_all_launch_configurations(names=['web']) configs.should.have.length_of(1) web_config = configs[0] web_config.user_data.should.equal("echo 'other_machine' > /etc/config") # And there should only be a single launch configuration conn.get_all_launch_configurations().should.have.length_of(1)
def test_editing_launch_configuration_update_AS_groups(): conn = boto.connect_autoscale() config = add_launch_config("web", user_data="echo 'web_machine' > /etc/config") group = AutoScalingGroup( name='web', launch_config=config, max_size=2, min_size=2, ) conn.create_auto_scaling_group(group) # Now edit the user data edit_launch_config("web", user_data="echo 'other_machine' > /etc/config") group = conn.get_all_groups()[0] config_name = group.launch_config_name config_name.should.equal("web") config = conn.get_all_launch_configurations(names=[config_name])[0] config.user_data.should.equal("echo 'other_machine' > /etc/config")
def test_editing_launch_configuration_update_AS_groups(): conn = boto.connect_autoscale(use_block_device_types=True) config = add_launch_config("web", user_data="echo 'web_machine' > /etc/config") group = AutoScalingGroup( name='web', launch_config=config, max_size=2, min_size=2, ) conn.create_auto_scaling_group(group) # Now edit the user data edit_launch_config("web", user_data="echo 'other_machine' > /etc/config") group = conn.get_all_groups()[0] config_name = group.launch_config_name config_name.should.equal("web") config = conn.get_all_launch_configurations(names=[config_name])[0] config.user_data.should.equal("echo 'other_machine' > /etc/config")