Exemple #1
0
    def task_sync_stop(self, ticket_id, app_name, sync_ticket_id):

        app = yield self.app_controller.get(app_name)

        client = yield app.get_client()

        s = Service(client=client)
        s.app_name = app_name
        s.name = '%s_%s_%s' % (app_name, '_rsync_', sync_ticket_id)

        yield s.inspect()

        if s.is_running():
            self.task_log(ticket_id, 'Stopping rsync container.')
            yield s.stop(ticket_id)

        if s.is_created():
            self.task_log(ticket_id, 'Destroying rsync container.')
            yield s.destroy(ticket_id)
Exemple #2
0
    def task_sync_stop(self, ticket_id, app_name, sync_ticket_id):

        app = yield self.app_controller.get(app_name)

        client = yield app.get_client()

        s = Service(client=client)
        s.app_name = app_name
        s.name = '%s_%s_%s' % (app_name, '_rsync_', sync_ticket_id)

        yield s.inspect()

        if s.is_running():
            self.task_log(ticket_id, 'Stopping rsync container.')
            yield s.stop(ticket_id)

        if s.is_created():
            self.task_log(ticket_id, 'Destroying rsync container.')
            yield s.destroy(ticket_id)
Exemple #3
0
def test_service_api():
    from twisted.python import log

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    yield redis.set('mcloud-ticket-id', 123122)

    eb = EventBus(redis)
    yield eb.connect()

    redis = flexmock()
    redis.should_receive('hgetall').and_return({})
    redis.should_receive('hget').and_return(None)

    fake_inject({
        EventBus: eb,
        'dns-server': 'local.dns',
        'dns-search-suffix': 'local',
        IDockerClient: DockerTwistedClient(),
        txredisapi.Connection: redis
    })

    name = 'test.foo'

    s = Service(image_builder=DockerfileImageBuilder(
        os.path.join(os.path.dirname(__file__), '_files/ct_bash')),
                name=name,
                client=inject.instance(IDockerClient))

    class Printer(object):
        def publish(self, *args):
            print args

    s.client.message_publisher = Printer()

    yield s.inspect()

    if s.is_created():
        yield s.stop(ticket_id=123123)
        yield s.destroy(ticket_id=123123)

    assert not s.is_created()
    assert not s.is_running()

    yield s.create(ticket_id=123123)
    assert s.is_created()
    assert not s.is_running()

    yield s.start(ticket_id=123123)
    assert s.is_created()
    assert s.is_running()

    yield s.stop(ticket_id=123123)
    assert s.is_created()
    assert not s.is_running()

    yield s.destroy(ticket_id=123123)
    assert not s.is_created()
    assert not s.is_running()


#
#
#
# @pytest.inlineCallbacks
# def test_volume_snapshot():
#     from twisted.python import log
#     log.startLogging(sys.stdout)
#
#     redis = yield txredisapi.Connection(dbid=2)
#     yield redis.flushdb()
#
#     yield redis.set('mcloud-ticket-id', 123122)
#
#     eb = EventBus(redis)
#     yield eb.connect()
#
#     with injector({EventBus: eb, 'dns-server': 'local.dns', 'dns-search-suffix': 'local', IDockerClient: DockerTwistedClient()}):
#
#         name = 'test.foo'
#
#         s = Service(
#             image_builder=DockerfileImageBuilder(os.path.join(os.path.dirname(__file__), '_files/ct_bash')),
#             name=name,
#             volumes=[
#                 {'local': os.path.join(os.path.dirname(__file__), '_files/boo'), 'remote': '/var/foo'}
#             ]
#         )
#
#         yield s.create(ticket_id=123123)
#         yield s.start(ticket_id=123123)
#
#         assert s.is_created()
#         assert s.is_running()
#
#
#
#         yield s.destroy(ticket_id=123123)
Exemple #4
0
def test_service_api():
    from twisted.python import log

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    yield redis.set('mcloud-ticket-id', 123122)

    eb = EventBus(redis)
    yield eb.connect()

    redis = flexmock()
    redis.should_receive('hgetall').and_return({})
    redis.should_receive('hget').and_return(None)

    fake_inject({
        EventBus: eb,
        'dns-server': 'local.dns',
        'dns-search-suffix': 'local',
        IDockerClient: DockerTwistedClient(),
        txredisapi.Connection: redis
    })

    name = 'test.foo'

    s = Service(
        image_builder=DockerfileImageBuilder(os.path.join(os.path.dirname(__file__), '_files/ct_bash')),
        name=name,
        client=inject.instance(IDockerClient)
    )

    class Printer(object):
        def publish(self, *args):
            print args

    s.client.message_publisher = Printer()

    yield s.inspect()

    if s.is_created():
        yield s.stop(ticket_id=123123)
        yield s.destroy(ticket_id=123123)

    assert not s.is_created()
    assert not s.is_running()

    yield s.create(ticket_id=123123)
    assert s.is_created()
    assert not s.is_running()

    yield s.start(ticket_id=123123)
    assert s.is_created()
    assert s.is_running()


    yield s.stop(ticket_id=123123)
    assert s.is_created()
    assert not s.is_running()

    yield s.destroy(ticket_id=123123)
    assert not s.is_created()
    assert not s.is_running()

#
#
#
# @pytest.inlineCallbacks
# def test_volume_snapshot():
#     from twisted.python import log
#     log.startLogging(sys.stdout)
#
#     redis = yield txredisapi.Connection(dbid=2)
#     yield redis.flushdb()
#
#     yield redis.set('mcloud-ticket-id', 123122)
#
#     eb = EventBus(redis)
#     yield eb.connect()
#
#     with injector({EventBus: eb, 'dns-server': 'local.dns', 'dns-search-suffix': 'local', IDockerClient: DockerTwistedClient()}):
#
#         name = 'test.foo'
#
#         s = Service(
#             image_builder=DockerfileImageBuilder(os.path.join(os.path.dirname(__file__), '_files/ct_bash')),
#             name=name,
#             volumes=[
#                 {'local': os.path.join(os.path.dirname(__file__), '_files/boo'), 'remote': '/var/foo'}
#             ]
#         )
#
#         yield s.create(ticket_id=123123)
#         yield s.start(ticket_id=123123)
#
#         assert s.is_created()
#         assert s.is_running()
#
#
#
#         yield s.destroy(ticket_id=123123)