예제 #1
0
파일: test_patch.py 프로젝트: zeus911/senza
def test_patch_user_data_wrong_type(monkeypatch):

    lc = {
        'ImageId':
        'originalimage',
        'LaunchConfigurationName':
        'originallc',
        'UserData':
        codecs.encode(b'#firstline\nsource: oldsource',
                      'base64').decode('utf-8')
    }
    result = {'LaunchConfigurations': [lc]}

    asg = MagicMock()
    asg.describe_launch_configurations.return_value = result

    new_lc = {}

    def create_lc(**kwargs):
        new_lc.update(kwargs)

    asg.create_launch_configuration = create_lc
    monkeypatch.setattr('boto3.client', lambda x, region: asg)
    group = {
        'AutoScalingGroupName': 'myasg',
        'LaunchConfigurationName': 'originallc'
    }
    properties = {'UserData': "it's a string"}
    with pytest.raises(InvalidUserDataType) as exc_info:
        patch_auto_scaling_group(group, 'myregion', properties)

    assert str(exc_info.value) == ('Current user data is a map but provided '
                                   'user data is a string.')
예제 #2
0
파일: test_patch.py 프로젝트: zeus911/senza
def test_patch_auto_scaling_group(monkeypatch):

    lc = {
        'ImageId': 'originalimage',
        'LaunchConfigurationName': 'originallc',
        'UserData': codecs.encode(b'myuserdata', 'base64').decode('utf-8')
    }
    result = {'LaunchConfigurations': [lc]}

    asg = MagicMock()
    asg.describe_launch_configurations.return_value = result

    new_lc = {}

    def create_lc(**kwargs):
        new_lc.update(kwargs)

    asg.create_launch_configuration = create_lc
    monkeypatch.setattr('boto3.client', lambda x, region: asg)
    group = {
        'AutoScalingGroupName': 'myasg',
        'LaunchConfigurationName': 'originallc'
    }
    properties = {'ImageId': 'mynewimage'}
    patch_auto_scaling_group(group, 'myregion', properties)

    assert new_lc['UserData'] == 'myuserdata'
예제 #3
0
def test_patch_auto_scaling_group_taupage_config(monkeypatch):

    lc = {'ImageId': 'originalimage', 'LaunchConfigurationName': 'originallc',
          'UserData': codecs.encode(b'#firstline\nsource: oldsource', 'base64').decode('utf-8')}
    result = {'LaunchConfigurations': [lc]}

    asg = MagicMock()
    asg.describe_launch_configurations.return_value = result

    new_lc = {}

    def create_lc(**kwargs):
        new_lc.update(kwargs)

    asg.create_launch_configuration = create_lc
    monkeypatch.setattr('boto3.client', lambda x, region: asg)
    group = {'AutoScalingGroupName': 'myasg', 'LaunchConfigurationName': 'originallc'}
    properties = {'UserData': {'source': 'newsource'}}
    patch_auto_scaling_group(group, 'myregion', properties)

    assert new_lc['UserData'] == '#firstline\nsource: newsource\n'
예제 #4
0
def test_patch_user_data_wrong_type(monkeypatch):

    lc = {'ImageId': 'originalimage', 'LaunchConfigurationName': 'originallc',
          'UserData': codecs.encode(b'#firstline\nsource: oldsource', 'base64').decode('utf-8')}
    result = {'LaunchConfigurations': [lc]}

    asg = MagicMock()
    asg.describe_launch_configurations.return_value = result

    new_lc = {}

    def create_lc(**kwargs):
        new_lc.update(kwargs)

    asg.create_launch_configuration = create_lc
    monkeypatch.setattr('boto3.client', lambda x, region: asg)
    group = {'AutoScalingGroupName': 'myasg', 'LaunchConfigurationName': 'originallc'}
    properties = {'UserData': "it's a string"}
    with pytest.raises(InvalidUserDataType) as exc_info:
        patch_auto_scaling_group(group, 'myregion', properties)

    assert str(exc_info.value) == ('Current user data is a map but provided '
                                   'user data is a string.')
예제 #5
0
def test_patch_auto_scaling_group(monkeypatch):

    lc = {
        "ImageId": "originalimage",
        "LaunchConfigurationName": "originallc",
        "UserData": codecs.encode(b"myuserdata", "base64").decode("utf-8"),
    }
    result = {"LaunchConfigurations": [lc]}

    asg = MagicMock()
    asg.describe_launch_configurations.return_value = result

    new_lc = {}

    def create_lc(**kwargs):
        new_lc.update(kwargs)

    asg.create_launch_configuration = create_lc
    monkeypatch.setattr("boto3.client", lambda x, region: asg)
    group = {"AutoScalingGroupName": "myasg", "LaunchConfigurationName": "originallc"}
    properties = {"ImageId": "mynewimage"}
    patch_auto_scaling_group(group, "myregion", properties)

    assert new_lc["UserData"] == "myuserdata"