Example #1
0
def test_service_generator():
    
    import ginkgo.core
    class MyService(ginkgo.core.Service): pass

    expected_children = [('hi', MyService()), ('also named', MyService())]
    expected_main = MyService()

    def service():
        for name, child in expected_children:
            yield name, child
        yield expected_main
        
    from ginkgo.runner import Runner
    
    Runner._args = ['run', '-C', 'config', '-u', 'nobody']
    Runner._opener = mock_open({'{}/config'.format(os.getcwd()): ""})

    runner = Runner()
    
    service_gen = service()
        
    children, main_service = runner._expand_service_generators(service_gen)

    print children, main_service
    assert children == expected_children
    assert main_service == expected_main
Example #2
0
def test_runner_no_daemonize():
    from ginkgo.runner import Runner
    class EmptyRunner(Runner):
        def run(self): pass
    EmptyRunner._args = ['start', '-C', 'config', '-n']
    EmptyRunner._opener = mock_open({'{}/config'.format(os.getcwd()): "", "serviced.log": "", "serviced.pid": ""})
    with silencer():
        EmptyRunner()
Example #3
0
def get_runner():
    from ginkgo.runner import Runner
    
    Runner._args = ['run', '-C', 'config', '-u', 'nobody']
    Runner._opener = mock_open({'{}/config'.format(os.getcwd()): ""})

    runner = Runner()
    return runner
Example #4
0
def test_privileged_configuration():
    from ginkgo.runner import Runner
    from ginkgo import config
    import os

    uids = {}

    Runner._args = ['run', '-C', 'config', '-u', 'nobody']
    Runner._opener = mock_open({'{}/config'.format(os.getcwd()): ""})

    runner = Runner()

    # mock out the os getuid/setuid modules
    import os
    props = {'uid': 0, 'gid': 0}
    def getuid(): return props['uid']
    def setuid(uid): props['uid'] = uid
    def getgid(): return props['gid']
    def setgid(gid): props['gid'] = gid

    os.getuid = getuid
    os.setuid = setuid
    os.getgid = getgid
    os.setgid = setgid

    # capture the uid of the service at start and stop time
    def service():
        import ginkgo.core
        class Service(ginkgo.core.Service):
            def do_start(self):
                print "asked to do_start"
                uids['start'] = os.getuid()

                def stop(): self.stop()
                gevent.spawn_later(0.1, stop)
            
            def do_stop(self):
                print "asked to do_stop"
                uids['stop'] = os.getuid()
                print "done stopping"

        return Service()

    config.load({'service': service,
                 '_allow_early_gevent_import_for_tests': True})

    print "before action"
    runner.do_action()
    
    assert uids['start'] != runner.uid
    assert uids['stop'] == runner.uid
Example #5
0
def test_extend_file_config_option():
    from ginkgo.runner import Runner
    from ginkgo.config import Setting

    class ConfigCheckRunner(Runner):
        foo = Setting('foo')
        def run(self):
            assert self.foo == 'bar2'

    ConfigCheckRunner._args = ['run', '-C', 'config1', '-X', "foo = 'bar2'"]
    ConfigCheckRunner._opener = mock_open({'{}/config1'.format(os.getcwd()): "foo = 'bar1'"})

    with silencer():
        ConfigCheckRunner().do_action()
Example #6
0
def test_command_line_override_config():
    """ Test that specifying an option on the command line override any
        value set in a config file"""
    from ginkgo.runner import Runner

    class ConfigCheckRunner(Runner):
        def run(self):
            assert self.pidfile_path == 'mypidfile.pid'

    ConfigCheckRunner._args = ['run', '-C', 'config', '-p', 'mypidfile.pid']
    ConfigCheckRunner._opener = mock_open({'{}/config'.format(os.getcwd()): "pidfile = 'configpidfile.pid'"})

    with silencer():
        ConfigCheckRunner().do_action()
Example #7
0
def test_runner_reads_config():
    from ginkgo.runner import Runner
    Runner._args = ['start', '-C', 'config']
    Runner._opener = mock_open({'{}/config'.format(os.getcwd()): "", "serviced.log": ""})
    with silencer():
        Runner()