Пример #1
0
 def test_empty_include(self, mock_logger_warn):
     """https://github.com/mozilla-services/circus/pull/473"""
     try:
         get_config(_CONF['empty_include'])
     except:
         self.fail('Non-existent includes should not raise')
     self.assertTrue(mock_logger_warn.called)
Пример #2
0
 def test_expand_vars(self):
     """
     https://github.com/mozilla-services/circus/pull/554
     """
     conf = get_config(_CONF["expand_vars"])
     watcher = conf["watchers"][0]
     self.assertEqual(watcher["stdout_stream"]["filename"], "/tmp/echo.log")
Пример #3
0
 def test_expand_vars(self):
     '''
     https://github.com/mozilla-services/circus/pull/554
     '''
     conf = get_config(_CONF['expand_vars'])
     watcher = conf['watchers'][0]
     self.assertEqual(watcher['stdout_stream']['filename'], '/tmp/echo.log')
Пример #4
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        # creating arbiter
        arbiter = cls(watchers,
                      cfg['endpoint'],
                      cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'),
                      sockets=sockets)

        return arbiter
Пример #5
0
 def test_issue1088(self):
     # #1088 - graceful_timeout should be float
     conf = get_config(_CONF['issue1088'])
     watcher = conf['watchers'][0]
     self.assertEqual(watcher['graceful_timeout'], 25.5)
     watcher = Watcher.load_from_config(conf['watchers'][0])
     watcher.stop()
Пример #6
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        httpd = cfg.get('httpd', False)
        if httpd:
            # controlling that we have what it takes to run the web UI
            # if something is missing this will tell the user
            try:
                import circusweb     # NOQA
            except ImportError:
                logger.error('You need to install circus-web')
                sys.exit(1)

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'), sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=httpd,
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      ssh_server=cfg.get('ssh_server', None))

        return arbiter
Пример #7
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        # creating arbiter
        arbiter = cls(watchers,
                      cfg['endpoint'],
                      cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'),
                      sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=cfg.get('httpd', False),
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      stream_backend=cfg.get('stream_backend', 'thread'),
                      ssh_server=cfg.get('ssh_server', None))

        return arbiter
Пример #8
0
    def test_issue567(self):
        os.environ['GRAVITY'] = 'down'
        conf = get_config(_CONF['issue567'])

        # make sure the global environment makes it into the cfg environment
        # even without [env] section
        self.assertEqual(conf['watchers'][0]['cmd'], 'down')
Пример #9
0
    def test_issue310(self):
        '''
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        '''
        conf = get_config(_CONF['issue310'])
        watcher = Watcher.load_from_config(conf['watchers'][0])
        socket = CircusSocket.load_from_config(conf['sockets'][0])
        try:
            watcher.initialize(None, {'web': socket}, None)
            process = Process(watcher._nextwid, watcher.cmd,
                              args=watcher.args,
                              working_dir=watcher.working_dir,
                              shell=watcher.shell, uid=watcher.uid,
                              gid=watcher.gid, env=watcher.env,
                              rlimits=watcher.rlimits, spawn=False,
                              executable=watcher.executable,
                              use_fds=watcher.use_sockets,
                              watcher=watcher)

            sockets_fds = watcher._get_sockets_fds()
            formatted_args = process.format_args(sockets_fds=sockets_fds)

            fd = sockets_fds['web']
            self.assertEqual(formatted_args,
                             ['foo', '--fd', str(fd)])
        finally:
            socket.close()
Пример #10
0
    def test_issue310(self):
        """
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        """
        conf = get_config(_CONF["issue310"])
        watcher = Watcher.load_from_config(conf["watchers"][0])
        socket = CircusSocket.load_from_config(conf["sockets"][0])
        watcher.initialize(None, {"web": socket}, None)
        process = Process(
            watcher._process_counter,
            watcher.cmd,
            args=watcher.args,
            working_dir=watcher.working_dir,
            shell=watcher.shell,
            uid=watcher.uid,
            gid=watcher.gid,
            env=watcher.env,
            rlimits=watcher.rlimits,
            spawn=False,
            executable=watcher.executable,
            use_fds=watcher.use_sockets,
            watcher=watcher,
        )

        fd = watcher._get_sockets_fds()["web"]
        formatted_args = process.format_args()

        self.assertEquals(formatted_args, ["foo", "--fd", str(fd)])
Пример #11
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        httpd = cfg.get('httpd', False)
        if httpd:
            # controlling that we have what it takes to run the web UI
            # if something is missing this will tell the user
            try:
                import circusweb     # NOQA
            except ImportError:
                logger.error('You need to install circus-web')
                sys.exit(1)

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'), sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=httpd,
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      ssh_server=cfg.get('ssh_server', None))

        return arbiter
Пример #12
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'), sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=cfg.get('httpd', False),
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      stream_backend=cfg.get('stream_backend', 'thread'),
                      ssh_server=cfg.get('ssh_server', None))

        return arbiter
Пример #13
0
    def test_issue567(self):
        os.environ["GRAVITY"] = "down"
        conf = get_config(_CONF["issue567"])

        # make sure the global environment makes it into the cfg environment
        # even without [env] section
        self.assertEqual(conf["watchers"][0]["cmd"], "down")
Пример #14
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get("watchers", []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get("sockets", []):
            sockets.append(CircusSocket.load_from_config(socket))

        # creating arbiter
        arbiter = cls(
            watchers,
            cfg["endpoint"],
            cfg["pubsub_endpoint"],
            check_delay=cfg.get("check_delay", 1.0),
            prereload_fn=cfg.get("prereload_fn"),
            stats_endpoint=cfg.get("stats_endpoint"),
            plugins=cfg.get("plugins"),
            sockets=sockets,
        )

        return arbiter
Пример #15
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket))

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      plugins=cfg.get('plugins'), sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=cfg.get('httpd', False),
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080))

        return arbiter
Пример #16
0
 def test_override(self):
     conf = get_config(_CONF['multiple_wildcard'])
     watchers = conf['watchers']
     self.assertEqual(len(watchers), 3)
     watchers = conf['watchers']
     watchers = sorted(watchers, key=lambda a: a['__name__'])
     self.assertEqual(watchers[2]['env']['INI'], 'private.ini')
     self.assertEqual(conf['check_delay'], 555)
Пример #17
0
 def test_override(self):
     conf = get_config(_CONF['multiple_wildcard'])
     watchers = conf['watchers']
     self.assertEquals(len(watchers), 3)
     watchers = conf['watchers']
     watchers.sort()
     self.assertEquals(watchers[2]['env']['INI'], 'private.ini')
     self.assertEqual(conf['check'], 555)
Пример #18
0
 def test_override(self):
     conf = get_config(_CONF["multiple_wildcard"])
     watchers = conf["watchers"]
     self.assertEquals(len(watchers), 3)
     watchers = conf["watchers"]
     watchers.sort()
     self.assertEquals(watchers[2]["env"]["INI"], "private.ini")
     self.assertEqual(conf["check"], 555)
Пример #19
0
 def test_override(self):
     conf = get_config(_CONF['multiple_wildcard'])
     watchers = conf['watchers']
     self.assertEquals(len(watchers), 3)
     watchers = conf['watchers']
     watchers.sort()
     self.assertEquals(watchers[2]['env'], {'INI': 'private.ini'})
     self.assertEqual(conf['check'], 555)
Пример #20
0
    def test_copy_env(self):
        # #564 make sure we respect copy_env
        os.environ['BAM'] = '1'
        conf = get_config(_CONF['copy_env'])
        for watcher in conf['watchers']:
            if watcher['name'] == 'watcher1':

                self.assertFalse('BAM' in watcher['env'])
            else:
                self.assertTrue('BAM' in watcher['env'])
            self.assertTrue('TEST1' in watcher['env'])
Пример #21
0
    def load_from_config(cls, config_file, loop=None):
        cfg = get_config(config_file)
        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket_ in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket_))

        httpd = cfg.get('httpd', False)
        if httpd:
            # controlling that we have what it takes to run the web UI
            # if something is missing this will tell the user
            try:
                import circusweb  # NOQA
            except ImportError:
                logger.error('You need to install circus-web')
                sys.exit(1)

        # creating arbiter
        arbiter = cls(watchers,
                      cfg['endpoint'],
                      cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      statsd=cfg.get('statsd', False),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      papa_endpoint=cfg.get('papa_endpoint'),
                      multicast_endpoint=cfg.get('multicast_endpoint'),
                      plugins=cfg.get('plugins'),
                      sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=httpd,
                      loop=loop,
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      debug_gc=cfg.get('debug_gc', False),
                      ssh_server=cfg.get('ssh_server', None),
                      pidfile=cfg.get('pidfile', None),
                      loglevel=cfg.get('loglevel', None),
                      logoutput=cfg.get('logoutput', None),
                      loggerconfig=cfg.get('loggerconfig', None),
                      fqdn_prefix=cfg.get('fqdn_prefix', None),
                      umask=cfg['umask'],
                      endpoint_owner=cfg.get('endpoint_owner', None))

        # store the cfg which will be used, so it can be used later
        # for checking if the cfg has been changed
        arbiter._cfg = cls.get_arbiter_config(cfg)
        arbiter.config_file = config_file

        return arbiter
Пример #22
0
 def test_override(self):
     conf = get_config(_CONF["multiple_wildcard"])
     watchers = conf["watchers"]
     self.assertEqual(len(watchers), 3)
     watchers = conf["watchers"]
     if PY2:
         watchers.sort()
     else:
         watchers = sorted(watchers, key=lambda a: a["__name__"])
     self.assertEqual(watchers[2]["env"]["INI"], "private.ini")
     self.assertEqual(conf["check_delay"], 555)
Пример #23
0
    def test_copy_env(self):
        # #564 make sure we respect copy_env
        os.environ["BAM"] = "1"
        conf = get_config(_CONF["copy_env"])
        for watcher in conf["watchers"]:
            if watcher["name"] == "watcher1":

                self.assertFalse("BAM" in watcher["env"])
            else:
                self.assertTrue("BAM" in watcher["env"])
            self.assertTrue("TEST1" in watcher["env"])
Пример #24
0
 def test_override(self):
     conf = get_config(_CONF['multiple_wildcard'])
     watchers = conf['watchers']
     self.assertEqual(len(watchers), 3)
     watchers = conf['watchers']
     if PY2:
         watchers.sort()
     else:
         watchers = sorted(watchers, key=lambda a: a['__name__'])
     self.assertEqual(watchers[2]['env']['INI'], 'private.ini')
     self.assertEqual(conf['check_delay'], 555)
Пример #25
0
    def load_from_config(cls, config_file, loop=None):
        cfg = get_config(config_file)
        watchers = []
        for watcher in cfg.get("watchers", []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket in cfg.get("sockets", []):
            sockets.append(CircusSocket.load_from_config(socket))

        httpd = cfg.get("httpd", False)
        if httpd:
            # controlling that we have what it takes to run the web UI
            # if something is missing this will tell the user
            try:
                import circusweb  # NOQA
            except ImportError:
                logger.error("You need to install circus-web")
                sys.exit(1)

        # creating arbiter
        arbiter = cls(
            watchers,
            cfg["endpoint"],
            cfg["pubsub_endpoint"],
            check_delay=cfg.get("check_delay", 1.0),
            prereload_fn=cfg.get("prereload_fn"),
            statsd=cfg.get("statsd", False),
            stats_endpoint=cfg.get("stats_endpoint"),
            multicast_endpoint=cfg.get("multicast_endpoint"),
            plugins=cfg.get("plugins"),
            sockets=sockets,
            warmup_delay=cfg.get("warmup_delay", 0),
            httpd=httpd,
            loop=loop,
            httpd_host=cfg.get("httpd_host", "localhost"),
            httpd_port=cfg.get("httpd_port", 8080),
            debug=cfg.get("debug", False),
            ssh_server=cfg.get("ssh_server", None),
            pidfile=cfg.get("pidfile", None),
            loglevel=cfg.get("loglevel", None),
            logoutput=cfg.get("logoutput", None),
            fqdn_prefix=cfg.get("fqdn_prefix", None),
            umask=cfg["umask"],
        )

        # store the cfg which will be used, so it can be used later
        # for checking if the cfg has been changed
        arbiter._cfg = cls.get_arbiter_config(cfg)
        arbiter.config_file = config_file

        return arbiter
Пример #26
0
    def test_env_casesense(self):
        # #730 make sure respect case
        conf = get_config(_CONF['env_sensecase'])
        w = conf['watchers'][0]
        self.assertEqual(w['name'], 'webapp')
        self.assertTrue('http_proxy' in w['env'])
        self.assertEqual(w['env']['http_proxy'], 'http://localhost:8080')

        self.assertTrue('HTTPS_PROXY' in w['env'])
        self.assertEqual(w['env']['HTTPS_PROXY'], 'http://localhost:8043')

        self.assertTrue('FunKy_soUl' in w['env'])
        self.assertEqual(w['env']['FunKy_soUl'], 'scorpio')
Пример #27
0
    def test_env_casesense(self):
        # #730 make sure respect case
        conf = get_config(_CONF["env_sensecase"])
        w = conf["watchers"][0]
        self.assertEqual(w["name"], "webapp")
        self.assertTrue("http_proxy" in w["env"])
        self.assertEqual(w["env"]["http_proxy"], "http://localhost:8080")

        self.assertTrue("HTTPS_PROXY" in w["env"])
        self.assertEqual(w["env"]["HTTPS_PROXY"], "http://localhost:8043")

        self.assertTrue("FunKy_soUl" in w["env"])
        self.assertEqual(w["env"]["FunKy_soUl"], "scorpio")
Пример #28
0
    def test_env_casesense(self):
        # #730 make sure respect case
        conf = get_config(_CONF['env_sensecase'])
        w = conf['watchers'][0]
        self.assertEqual(w['name'], 'webapp')
        self.assertTrue('http_proxy' in w['env'])
        self.assertEqual(w['env']['http_proxy'], 'http://localhost:8080')

        self.assertTrue('HTTPS_PROXY' in w['env'])
        self.assertEqual(w['env']['HTTPS_PROXY'], 'http://localhost:8043')

        self.assertTrue('FunKy_soUl' in w['env'])
        self.assertEqual(w['env']['FunKy_soUl'], 'scorpio')
Пример #29
0
    def load_from_config(cls, config_file, loop=None):
        cfg = get_config(config_file)
        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        sockets = []
        for socket_ in cfg.get('sockets', []):
            sockets.append(CircusSocket.load_from_config(socket_))

        httpd = cfg.get('httpd', False)
        if httpd:
            # controlling that we have what it takes to run the web UI
            # if something is missing this will tell the user
            try:
                import circusweb  # NOQA
            except ImportError:
                logger.error('You need to install circus-web')
                sys.exit(1)

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'),
                      statsd=cfg.get('statsd', False),
                      stats_endpoint=cfg.get('stats_endpoint'),
                      papa_endpoint=cfg.get('papa_endpoint'),
                      multicast_endpoint=cfg.get('multicast_endpoint'),
                      plugins=cfg.get('plugins'), sockets=sockets,
                      warmup_delay=cfg.get('warmup_delay', 0),
                      httpd=httpd,
                      loop=loop,
                      httpd_host=cfg.get('httpd_host', 'localhost'),
                      httpd_port=cfg.get('httpd_port', 8080),
                      debug=cfg.get('debug', False),
                      debug_gc=cfg.get('debug_gc', False),
                      ssh_server=cfg.get('ssh_server', None),
                      pidfile=cfg.get('pidfile', None),
                      loglevel=cfg.get('loglevel', None),
                      logoutput=cfg.get('logoutput', None),
                      loggerconfig=cfg.get('loggerconfig', None),
                      fqdn_prefix=cfg.get('fqdn_prefix', None),
                      umask=cfg['umask'],
                      endpoint_owner=cfg.get('endpoint_owner', None))

        # store the cfg which will be used, so it can be used later
        # for checking if the cfg has been changed
        arbiter._cfg = cls.get_arbiter_config(cfg)
        arbiter.config_file = config_file

        return arbiter
Пример #30
0
    def test_variables_everywhere(self):
        os.environ["circus_stats_endpoint"] = "tcp://0.0.0.0:9876"
        os.environ["circus_statsd"] = "True"

        # these will be overriden
        os.environ["circus_uid"] = "ubuntu"
        os.environ["circus_gid"] = "ubuntu"

        conf = get_config(_CONF["issue442"])

        self.assertEqual(conf["stats_endpoint"], "tcp://0.0.0.0:9876")
        self.assertTrue(conf["statsd"])
        self.assertEqual(conf["watchers"][0]["uid"], "tarek")
        self.assertEqual(conf["watchers"][0]["gid"], "root")
Пример #31
0
    def test_env_section(self):
        conf = get_config(_CONF['env_section'])
        watchers_conf = {}
        for watcher_conf in conf['watchers']:
            watchers_conf[watcher_conf['name']] = watcher_conf
        watcher1 = Watcher.load_from_config(watchers_conf['watcher1'])
        watcher2 = Watcher.load_from_config(watchers_conf['watcher2'])

        self.assertEquals('lie', watcher1.env['CAKE'])
        self.assertEquals('cake', watcher2.env['LIE'])

        for watcher in [watcher1, watcher2]:
            self.assertEquals("%s:/bin" % os.getenv('PATH'),
                              watcher.env['PATH'])
Пример #32
0
    def test_env_section(self):
        conf = get_config(_CONF['env_section'])
        watchers_conf = {}
        for watcher_conf in conf['watchers']:
            watchers_conf[watcher_conf['name']] = watcher_conf
        watcher1 = Watcher.load_from_config(watchers_conf['watcher1'])
        watcher2 = Watcher.load_from_config(watchers_conf['watcher2'])

        self.assertEquals('lie', watcher1.env['CAKE'])
        self.assertEquals('cake', watcher2.env['LIE'])

        for watcher in [watcher1, watcher2]:
            self.assertEquals("%s:/bin" % os.getenv('PATH'),
                              watcher.env['PATH'])
Пример #33
0
    def test_variables_everywhere(self):
        os.environ['circus_stats_endpoint'] = 'tcp://0.0.0.0:9876'
        os.environ['circus_statsd'] = 'True'

        # these will be overriden
        os.environ['circus_uid'] = 'ubuntu'
        os.environ['circus_gid'] = 'ubuntu'

        conf = get_config(_CONF['issue442'])

        self.assertEqual(conf['stats_endpoint'], 'tcp://0.0.0.0:9876')
        self.assertTrue(conf['statsd'])
        self.assertEqual(conf['watchers'][0]['uid'], 'tarek')
        self.assertEqual(conf['watchers'][0]['gid'], 'root')
Пример #34
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get('watchers', []):
            watchers.append(Watcher.load_from_config(watcher))

        # creating arbiter
        arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
                      check_delay=cfg.get('check_delay', 1.),
                      prereload_fn=cfg.get('prereload_fn'))

        return arbiter
Пример #35
0
    def message(self, *args, **opts):
        if len(args) != 2:
            raise ArgumentError("invalid number of arguments")

        config_file, name = args

        config = get_config(config_file)
        watchers = config.get('watchers', [])
        config = filter(lambda w: w['name'] == name, watchers)
        if not config:
            raise ArgumentError("watcher not found")
        config = config[0]
        config['stdout_stream'] = {'class': 'StdoutStream'}
        config['stderr_stream'] = {'class': 'StdoutStream'}
        config['_exec'] = True
        watcher = Watcher.load_from_config(config)
        # the next call will exec(), replacing the current process
        watcher.start()
Пример #36
0
    def load_from_config(cls, config_file):
        cfg = get_config(config_file)

        # hack reload ioloop to use the monkey patched version
        reload(ioloop)

        watchers = []
        for watcher in cfg.get("watchers", []):
            watchers.append(Watcher.load_from_config(watcher))

        # creating arbiter
        arbiter = cls(
            watchers,
            cfg["endpoint"],
            cfg["pubsub_endpoint"],
            check_delay=cfg.get("check_delay", 1.0),
            prereload_fn=cfg.get("prereload_fn"),
        )

        return arbiter
Пример #37
0
    def test_issue310(self):
        """
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        """
        conf = get_config(_CONF["issue310"])
        watcher = Watcher.load_from_config(conf["watchers"][0])
        socket = CircusSocket.load_from_config(conf["sockets"][0])
        try:
            watcher.initialize(None, {"web": socket}, None)

            if IS_WINDOWS:
                # We can't close the sockets on Windows as we
                # are redirecting stdout
                watcher.use_sockets = True

            process = Process(
                watcher._nextwid,
                watcher.cmd,
                args=watcher.args,
                working_dir=watcher.working_dir,
                shell=watcher.shell,
                uid=watcher.uid,
                gid=watcher.gid,
                env=watcher.env,
                rlimits=watcher.rlimits,
                spawn=False,
                executable=watcher.executable,
                use_fds=watcher.use_sockets,
                watcher=watcher,
            )

            sockets_fds = watcher._get_sockets_fds()
            formatted_args = process.format_args(sockets_fds=sockets_fds)

            fd = sockets_fds["web"]
            self.assertEqual(formatted_args, ["foo", "--fd", str(fd)])
        finally:
            socket.close()
Пример #38
0
    def test_env_section(self):
        conf = get_config(_CONF["env_section"])
        watchers_conf = {}
        for watcher_conf in conf["watchers"]:
            watchers_conf[watcher_conf["name"]] = watcher_conf
        watcher1 = Watcher.load_from_config(watchers_conf["watcher1"])
        watcher2 = Watcher.load_from_config(watchers_conf["watcher2"])

        self.assertEqual("lie", watcher1.env["CAKE"])
        self.assertEqual("cake", watcher2.env["LIE"])

        for watcher in [watcher1, watcher2]:
            self.assertEqual("%s:/bin" % os.getenv("PATH"), watcher.env["PATH"])

        self.assertEqual("test1", watcher1.env["TEST1"])
        self.assertEqual("test1", watcher2.env["TEST1"])

        self.assertEqual("test2", watcher1.env["TEST2"])
        self.assertEqual("test2", watcher2.env["TEST2"])

        self.assertEqual("test3", watcher1.env["TEST3"])
        self.assertEqual("test3", watcher2.env["TEST3"])
Пример #39
0
    def test_legacy_stream_settings(self):
        """The legacy stream settings should create a plugin when used.
        """
        conf = get_config(_CONF['publish'])
        watcher = conf['watchers'][0]
        self.assertTrue(watcher['publish']['stdout'])

        pub_watcher = conf['watchers'][1]
        self.assertTrue(pub_watcher['publish']['stdout'])

        print(conf['plugins'])

        plugins = dict(
            (plugin_conf['topic'], plugin_conf)
            for plugin_conf in conf['plugins']
        )

        self.assertTrue(plugins['watcher.legacy.stdout'])
        self.assertEqual(plugins['watcher.legacy.stdout']['use'],
                         'circus.plugins.loggers.StdoutStream')

        self.assertTrue(plugins['watcher.publisher.stdout'])
        self.assertEqual(plugins['watcher.publisher.stdout']['use'],
                         'circus.plugins.loggers.FancyStdoutStream')
Пример #40
0
 def test_issue137(self):
     conf = get_config(_CONF['issue137'])
     watcher = conf['watchers'][0]
     self.assertEqual(watcher['uid'], 'me')
Пример #41
0
 def test_check_delay(self):
     conf = get_config(_CONF['issue651'])
     self.assertEqual(conf['check_delay'], 10.5)
Пример #42
0
 def test_socket_so_reuseport_no(self):
     conf = get_config(_CONF['reuseport'])
     s1 = conf['sockets'][1]
     self.assertEqual(s1['so_reuseport'], False)
Пример #43
0
 def test_socket_so_reuseport_yes(self):
     conf = get_config(_CONF['reuseport'])
     s1 = conf['sockets'][0]
     self.assertEqual(s1['so_reuseport'], True)
Пример #44
0
 def test_watcher_stop_signal(self):
     conf = get_config(_CONF['issue594'])
     self.assertEqual(conf['watchers'][0]['stop_signal'], signal.SIGINT)
     watcher = Watcher.load_from_config(conf['watchers'][0])
     watcher.stop()
Пример #45
0
 def test_logoutput(self):
     conf = get_config(_CONF['circus'])
     self.assertEqual(conf['logoutput'], 'logoutput')
Пример #46
0
    def test_env_everywhere(self):
        conf = get_config(_CONF['env_everywhere'])

        self.assertEqual(conf['endpoint'], 'tcp://127.0.0.1:1234')
        self.assertEqual(conf['sockets'][0]['path'], '/var/run/broken.sock')
        self.assertEqual(conf['plugins'][0]['use'], 'bad.has.been.broken')
Пример #47
0
 def test_watcher_graceful_timeout(self):
     conf = get_config(_CONF['issue210'])
     watcher = Watcher.load_from_config(conf['watchers'][0])
     watcher.stop()
Пример #48
0
 def test_watcher_env_var(self):
     conf = get_config(_CONF['env_var'])
     watcher = Watcher.load_from_config(conf['watchers'][0])
     self.assertEqual("%s:/bin" % os.getenv('PATH'), watcher.env['PATH'])
     watcher.stop()
Пример #49
0
 def test_issue395(self):
     conf = get_config(_CONF['issue395'])
     watcher = conf['watchers'][0]
     self.assertEqual(watcher['graceful_timeout'], 88)
Пример #50
0
 def test_loglevel(self):
     conf = get_config(_CONF['circus'])
     self.assertEqual(conf['loglevel'], 'debug')
Пример #51
0
    def test_issues665(self):
        '''
        https://github.com/mozilla-services/circus/pull/665

        Ensure args formatting when shell = True.
        '''
        conf = get_config(_CONF['issue665'])

        def load(watcher_conf):
            watcher = Watcher.load_from_config(watcher_conf.copy())
            process = Process(watcher._nextwid, watcher.cmd,
                              args=watcher.args,
                              working_dir=watcher.working_dir,
                              shell=watcher.shell, uid=watcher.uid,
                              gid=watcher.gid, env=watcher.env,
                              rlimits=watcher.rlimits, spawn=False,
                              executable=watcher.executable,
                              use_fds=watcher.use_sockets,
                              watcher=watcher)
            return process.format_args()

        import circus.process
        is_win = circus.process.is_win

        try:
            # force nix
            circus.process.is_win = lambda: False

            # without shell_args
            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][0])
                self.assertEqual(formatted_args, ['foo --fd'])
                self.assertFalse(mock_logger_warn.called)

            # with shell_args

            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][1])
                self.assertEqual(formatted_args,
                                 ['foo --fd', 'bar', 'baz', 'qux'])
                self.assertFalse(mock_logger_warn.called)

            # with shell_args but not shell

            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][2])
                self.assertEqual(formatted_args, ['foo', '--fd'])
                self.assertTrue(mock_logger_warn.called)

            # force win
            circus.process.is_win = lambda: True

            # without shell_args

            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][0])
                self.assertEqual(formatted_args, ['foo --fd'])
                self.assertFalse(mock_logger_warn.called)

            # with shell_args

            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][1])
                self.assertEqual(formatted_args, ['foo --fd'])
                self.assertTrue(mock_logger_warn.called)

            # with shell_args but not shell

            with patch.object(logger, 'warn') as mock_logger_warn:
                formatted_args = load(conf['watchers'][2])
                self.assertEqual(formatted_args, ['foo', '--fd'])
                self.assertTrue(mock_logger_warn.called)
        finally:
            circus.process.is_win = is_win
Пример #52
0
 def test_hooks(self):
     conf = get_config(_CONF['hooks'])
     watcher = Watcher.load_from_config(conf['watchers'][0])
     self.assertEqual(watcher.hooks['before_start'].__doc__, hook.__doc__)
     self.assertTrue('before_start' not in watcher.ignore_hook_failure)
Пример #53
0
 def test_dashes(self):
     conf = get_config(_CONF['issue546'])
     replaced = replace_gnu_args(conf['watchers'][0]['cmd'],
                                 sockets={'some-socket': 3})
     self.assertEqual(replaced, '../bin/chaussette --fd 3')
Пример #54
0
 def test_pidfile(self):
     conf = get_config(_CONF['circus'])
     self.assertEqual(conf['pidfile'], 'pidfile')