Ejemplo n.º 1
0
def test_server_describe_all_resolvers(dynamodb):
    app.test_client().post('/resolver',
                           data=json.dumps({
                               'resolver_name': 'dns',
                               'nameserver_address': 'dnsmasq'
                           }))
    app.test_client().post('/resolver',
                           data=json.dumps({
                               'resolver_name': 'dns2',
                               'nameserver_address': 'dnsmasq'
                           }))
    response = json.loads(app.test_client().get('/resolver').data)
    resolvers = sorted(response["resolvers"], key=lambda x: x["name"])
    expected = [{
        "hold_valid": "30s",
        "name": "dns",
        "nameserver_address": "dnsmasq",
        "nameserver_port": 53,
        "resolve_retries": 10,
        "timeout_retry": "5s"
    }, {
        "hold_valid": "30s",
        "name": "dns2",
        "nameserver_address": "dnsmasq",
        "nameserver_port": 53,
        "resolve_retries": 10,
        "timeout_retry": "5s"
    }]
    assert resolvers == expected
Ejemplo n.º 2
0
def test_server_deregister_backend(dynamodb):
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))
    app.test_client().post('/target',
                           data=json.dumps({
                               'service_name': 'foo',
                               'target_group_name': 'foo-blue',
                               'weight': 50,
                           }))
    app.test_client().post('/backend',
                           data=json.dumps({
                               'host': '10.0.0.1:80',
                               'service_name': 'foo',
                               'target_group_name': 'foo-blue',
                           }))
    response = app.test_client().delete('/backend/foo/foo-blue/10.0.0.1:80')
    assert response.status_code == 200
    service = json.loads(app.test_client().get('/service/foo').data)
    assert service['target_groups'][0]['backends'] == []
    second_response = app.test_client().delete(
        '/backend/foo/foo-blue/10.0.0.1:80')
    assert second_response.status_code == 404
    service = json.loads(app.test_client().get('/service/foo').data)
    assert service['target_groups'][0]['backends'] == []
Ejemplo n.º 3
0
def test_server_describe_service(dynamodb):
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))
    response = app.test_client().get('/service/foo')
    assert response.status_code == 200
    assert json.loads(response.data)['name'] == 'foo'
Ejemplo n.º 4
0
def test_server_describe_resolver(dynamodb):
    app.test_client().post('/resolver',
                           data=json.dumps({
                               'resolver_name': 'dns',
                               'nameserver_address': 'dnsmasq'
                           }))
    response = app.test_client().get('/resolver/dns')
    assert response.status_code == 200
    assert json.loads(response.data)['name'] == 'dns'
    assert json.loads(response.data)['nameserver_address'] == 'dnsmasq'
Ejemplo n.º 5
0
def test_server_deregister_service(dynamodb):
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))
    response = app.test_client().delete('/service/foo')
    assert response.status_code == 200
    describe_response = app.test_client().get('/service/foo')
    assert describe_response.status_code == 404
    deletion_response = app.test_client().delete('/service/foo')
    assert deletion_response.status_code == 404
    assert deletion_response.data.decode(
        'UTF-8') == 'Service: foo not currently registered with Flyby.'
Ejemplo n.º 6
0
def test_server_update_service(dynamodb):
    # Setup service to test update on
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))

    response = app.test_client().put('/service/foo',
                                     data=json.dumps({
                                         'name': 'foo',
                                         'fqdn': 'bar.example.com'
                                     }))
    assert response.status_code == 200
    assert json.loads(response.data)['fqdn'] == 'bar.example.com'
Ejemplo n.º 7
0
def test_server_deregister_resolver(dynamodb):
    app.test_client().post('/resolver',
                           data=json.dumps({
                               'resolver_name': 'dns',
                               'nameserver_address': 'dnsmasq'
                           }))
    response = app.test_client().delete('/resolver/dns')
    assert response.status_code == 200

    describe_response = app.test_client().get('/resolver/dns')
    assert describe_response.status_code == 404

    deletion_response = app.test_client().delete('/resolver/dns')
    assert deletion_response.status_code == 404
    assert deletion_response.data.decode(
        'UTF-8') == 'Resolver: dns not currently registered with Flyby.'
Ejemplo n.º 8
0
def test_server_register_target_group(dynamodb):
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))
    response = app.test_client().post('/target',
                                      data=json.dumps({
                                          'target_group_name': 'foo-blue',
                                          'service_name': 'foo',
                                          'weight': 80
                                      }))
    assert response.status_code == 200
    assert json.loads(response.data) == {
        'target_group_name': 'foo-blue',
        'weight': 80
    }
Ejemplo n.º 9
0
def test_server_query_services(dynamodb):
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'foo',
                               'fqdn': 'foo.example.com'
                           }))
    app.test_client().post('/service',
                           data=json.dumps({
                               'name': 'bar',
                               'fqdn': 'bar.example.com'
                           }))
    response = app.test_client().get('/service')
    assert response.status_code == 200
    services = json.loads(response.data)['services']
    assert len(services) == 2
    assert set([services[0]['name'],
                services[1]['name']]) == set(['foo', 'bar'])
Ejemplo n.º 10
0
def test_server_home():
    response = app.test_client().get('/')
    assert response.status_code == 200
    assert response.data == b'Hello flyby!'