Exemplo n.º 1
0
def test_start_volumes_from():

    with injector({'dns-server': 'local.dns', 'dns-search-suffix': 'local'}):
        s = Service()
        s.name = 'my_service'
        s.volumes_from = ['foo', 'bar']

        flexmock(s)

        s.client = flexmock()

        s.client.should_receive('find_container_by_name').with_args(
            'my_service').once().and_return(defer.succeed('123abc'))
        s.client.should_receive('start_container').with_args(
            '123abc',
            ticket_id=123123,
            config={
                "VolumesFrom": ['foo', 'bar'],
                'DnsSearch': 'None.local',
                'Dns': ['local.dns']
            }).once().and_return(defer.succeed('boo'))
        s.should_receive('inspect').with_args().once().and_return(
            defer.succeed('baz'))

        r = yield s.start(ticket_id=123123)

        assert r == 'baz'
Exemplo n.º 2
0
def test_start_ports():

    with injector({'dns-server': 'local.dns', 'dns-search-suffix': 'local'}):
        s = Service()
        s.name = 'my_service'
        s.ports = ['22/tcp']

        flexmock(s)

        s.client = flexmock()

        s.client.should_receive('find_container_by_name').with_args(
            'my_service').once().and_return(defer.succeed('123abc'))
        s.client.should_receive('start_container').with_args(
            '123abc',
            ticket_id=123123,
            config={
                "PortBindings": {
                    '22/tcp': [{}]
                },
                'DnsSearch': 'None.local',
                'Dns': ['local.dns']
            }).once().and_return(defer.succeed('boo'))
        s.should_receive('inspect').with_args().once().and_return(
            defer.succeed('baz'))

        r = yield s.start(ticket_id=123123)

        assert r == 'baz'
Exemplo n.º 3
0
def test_create():

    redis = flexmock()
    redis.should_receive('hgetall').and_return([])

    fake_inject({txredisapi.Connection: redis})

    s = Service()
    s.name = 'my_service'
    flexmock(s)

    s.image_builder = flexmock()
    s.image_builder.should_receive('build_image').with_args(ticket_id=123123, service=s).ordered().once()\
        .and_return(defer.succeed('boo'))

    s.client = flexmock()
    s.client.should_receive('create_container').with_args(
        {
            "Hostname": 'my_service',
            "Image": 'boo'
        },
        'my_service',
        ticket_id=123123).ordered().once().and_return('magic')

    s.should_receive('inspect').with_args().ordered().once().and_return(
        'magic')

    r = yield s.create(ticket_id=123123)

    assert r == 'magic'
Exemplo n.º 4
0
def test_start_volumes():

    with injector({'dns-server': 'local.dns', 'dns-search-suffix': 'local'}):
        s = Service()
        s.name = 'my_service'
        s.volumes = [
            {'local': '/base/path/foo1', 'remote': '/bar1'},
            {'local': '/base/path/foo2', 'remote': '/bar2'},
            {'local': '/base/path/foo3', 'remote': '/bar3'}
        ]
        flexmock(s)

        s.client = flexmock()

        s.client.should_receive('find_container_by_name').with_args('my_service').once().and_return(defer.succeed('123abc'))
        s.client.should_receive('start_container').with_args('123abc', ticket_id=123123, config={
            "Binds": ['/base/path/foo1:/bar1', '/base/path/foo2:/bar2', '/base/path/foo3:/bar3'],
            'DnsSearch': 'None.local',
            'Dns': ['local.dns']
        }).once().and_return(defer.succeed('boo'))
        s.should_receive('inspect').with_args().once().and_return(defer.succeed('baz'))

        r = yield s.start(ticket_id=123123)

        assert r == 'baz'
Exemplo n.º 5
0
def test_create():

    redis = flexmock()
    redis.should_receive('hgetall').and_return([])

    fake_inject({
        txredisapi.Connection: redis
    })

    s = Service()
    s.name = 'my_service'
    flexmock(s)

    s.image_builder = flexmock()
    s.image_builder.should_receive('build_image').with_args(ticket_id=123123, service=s).ordered().once()\
        .and_return(defer.succeed('boo'))

    s.client = flexmock()
    s.client.should_receive('create_container').with_args({
        "Hostname": 'my_service',
        "Image": 'boo'
    }, 'my_service', ticket_id=123123).ordered().once().and_return('magic')

    s.should_receive('inspect').with_args().ordered().once().and_return('magic')

    r = yield s.create(ticket_id=123123)

    assert r == 'magic'
Exemplo n.º 6
0
def test_start():

    with injector({'dns-server': 'local.dns', 'dns-search-suffix': 'local'}):

        s = Service()
        s.name = 'my_service'
        flexmock(s)

        s.client = flexmock()

        s.client.should_receive('find_container_by_name').with_args('my_service').once().and_return(defer.succeed('123abc'))
        s.client.should_receive('start_container').with_args('123abc', ticket_id=123123, config={'DnsSearch': 'None.local', 'Dns': ['local.dns']}).once().and_return(defer.succeed('boo'))
        s.should_receive('inspect').with_args().once().and_return(defer.succeed('baz'))

        r = yield s.start(ticket_id=123123)

        assert r == 'baz'
Exemplo n.º 7
0
def test_start_volumes():

    with injector({'dns-server': 'local.dns', 'dns-search-suffix': 'local'}):
        s = Service()
        s.name = 'my_service'
        s.volumes = [{
            'local': '/base/path/foo1',
            'remote': '/bar1'
        }, {
            'local': '/base/path/foo2',
            'remote': '/bar2'
        }, {
            'local': '/base/path/foo3',
            'remote': '/bar3'
        }]
        flexmock(s)

        s.client = flexmock()

        s.client.should_receive('find_container_by_name').with_args(
            'my_service').once().and_return(defer.succeed('123abc'))
        s.client.should_receive('start_container').with_args(
            '123abc',
            ticket_id=123123,
            config={
                "Binds": [
                    '/base/path/foo1:/bar1', '/base/path/foo2:/bar2',
                    '/base/path/foo3:/bar3'
                ],
                'DnsSearch':
                'None.local',
                'Dns': ['local.dns']
            }).once().and_return(defer.succeed('boo'))
        s.should_receive('inspect').with_args().once().and_return(
            defer.succeed('baz'))

        r = yield s.start(ticket_id=123123)

        assert r == 'baz'