Esempio n. 1
0
def test_versions_create_https(monkeypatch):
    subnet = MagicMock()
    subnet.id = 'subnet-mysubnet'
    vpc_conn = MagicMock()
    vpc_conn.get_all_subnets = lambda x: [subnet]

    monkeypatch.setattr('boto.vpc.connect_to_region', vpc_conn)
    monkeypatch.setattr('boto.ec2.connect_to_region', MagicMock())
    monkeypatch.setattr('boto.route53.connect_to_region', MagicMock())
    monkeypatch.setattr('boto.ec2.autoscale.connect_to_region', MagicMock())
    monkeypatch.setattr('boto.ec2.elb.connect_to_region', MagicMock())
    monkeypatch.setattr('time.sleep', lambda s: s)
    monkeypatch.setattr('aws_minion.cli.map_subnets', lambda s, r: {'public': [subnet], 'shared': [], 'private': []})
    monkeypatch.setattr('aws_minion.cli.docker_image_exists', lambda i: True)

    security_group = MagicMock()
    security_group.tags = {'Manifest': json.dumps({'exposed_ports': [8080], 'team_name': 'MyTeam'})}

    security_groups = {'app-myapp': security_group, 'app-myapp-lb': MagicMock()}

    auto_scaling_group = MagicMock()
    auto_scaling_group.tags = [MagicMock(key='DockerImage', value='foo/bar:123')]
    auto_scaling_group.desired_capacity = 3

    app = Application('myapp', security_group)

    version = ApplicationVersion('myregion', 'myapp', '1.0', auto_scaling_group)
    version.weight = 120

    context = Context({'region': 'caprica', 'vpc': 'myvpc', 'loggly_auth_token': 'abc', 'domain': 'mydomain',
                       'ssl_certificate_arn': 'super secret'})
    context.get_versions = lambda: [version]
    context.get_application = lambda x: app
    context.get_security_group = lambda x: security_groups.get(x)
    context.get_vpc_config = lambda: {'nameservers': ['8.8.8.8'], 'cacerts': ['https://example.org/cacert.pem'],
                                      'registry': 'example.org',
                                      'registry_insecure': True}
    context_constructor = lambda x, y: context

    monkeypatch.setattr('aws_minion.cli.Context', context_constructor)

    runner = CliRunner()

    with runner.isolated_filesystem():
        context.write_config('config.yaml')
        result = runner.invoke(cli, ['-p', 'default', '--config-file', 'config.yaml', 'versions', 'create', 'myapp', '1.0',
                                     'mydocker:2.3', '-e', 'MY_ENV_VAR=123'],
                               catch_exceptions=False)

    assert 'ABORTED. Default health check time to wait for members to become active has been exceeded.' in result.output
Esempio n. 2
0
def test_versions_list(monkeypatch):
    auto_scaling_group = MagicMock()
    auto_scaling_group.tags = [MagicMock(key='DockerImage', value='foo/bar:123')]
    auto_scaling_group.desired_capacity = 3

    version = ApplicationVersion('myregion', 'myapp', '1.0', auto_scaling_group)
    version.weight = 120

    context = Context({'region': 'caprica'})
    context.get_versions = lambda: [version]
    context.get_vpc_config = lambda: {}
    context_constructor = lambda x, y: context

    monkeypatch.setattr('aws_minion.cli.Context', context_constructor)

    runner = CliRunner()

    with runner.isolated_filesystem():
        context.write_config('config.yaml')
        result = runner.invoke(cli, ['-p', 'default', '--config-file', 'config.yaml', 'versions'], catch_exceptions=False)

    lines = result.output.splitlines()
    cols = lines[1].split()
    assert cols == ['myapp', '1.0', 'foo/bar:123', '(no', 'instances)', '3', '60.0']