Пример #1
0
    def test_read_env_bool(self):
        for true in BOOLEAN_TRUE:
            key = uuid.uuid4().hex
            os.environ[key] = true
            self.assertTrue(read_env_bool(key, False))

        for false in BOOLEAN_FALSE:
            key = uuid.uuid4().hex
            os.environ[key] = false
            self.assertFalse(read_env_bool(key, True))

        with self.assertRaises(AssertionError):
            read_env_bool("")

        with self.assertRaises(TypeError):
            key = uuid.uuid4().hex
            os.environ[key] = "42"
            read_env_bool(key, 1)

        with self.assertRaises(TypeError):
            key = uuid.uuid4().hex
            self.assertTrue(read_env_bool(key, 1))

        key = uuid.uuid4().hex
        self.assertTrue(read_env_bool(key, True))
Пример #2
0
    def __init__(self):  # pylint: disable=super-on-old-class
        super(Configuration, self).__init__("pyfarm.master")
        self.load()
        self.loaded = set(self.loaded)

        # Load model configuration
        models_config = _Configuration("pyfarm.models", version=self.version)
        models_config.load()
        self.update(models_config)
        self.loaded.update(models_config.loaded)

        # Load scheduler configuration
        sched_config = _Configuration("pyfarm.scheduler", version=self.version)
        sched_config.load()
        self.update(sched_config)
        self.loaded.update(sched_config.loaded)

        try:
            items = self.ENVIRONMENT_OVERRIDES.iteritems
        except AttributeError:  # pragma: no cover
            items = self.ENVIRONMENT_OVERRIDES.items

        overrides = {}
        for config_var, (envvar, load_func) in items():
            if envvar in os.environ:
                overrides[config_var] = load_func(envvar)

        if ("PYFARM_DEV_LISTEN_ON_WILDCARD" in os.environ
                and read_env_bool("PYFARM_DEV_LISTEN_ON_WILDCARD")):
            self.update(flask_listen_address="0.0.0.0")

        self.update(overrides)
Пример #3
0
    def __init__(self):  # pylint: disable=super-on-old-class
        super(Configuration, self).__init__("pyfarm.master")
        self.load()
        self.loaded = set(self.loaded)

        # Load model configuration
        models_config = _Configuration("pyfarm.models", version=self.version)
        models_config.load()
        self.update(models_config)
        self.loaded.update(models_config.loaded)

        # Load scheduler configuration
        sched_config = _Configuration("pyfarm.scheduler", version=self.version)
        sched_config.load()
        self.update(sched_config)
        self.loaded.update(sched_config.loaded)

        try:
            items = self.ENVIRONMENT_OVERRIDES.iteritems
        except AttributeError:  # pragma: no cover
            items = self.ENVIRONMENT_OVERRIDES.items

        overrides = {}
        for config_var, (envvar, load_func) in items():
            if envvar in os.environ:
                overrides[config_var] = load_func(envvar)

        if ("PYFARM_DEV_LISTEN_ON_WILDCARD" in os.environ
                and read_env_bool("PYFARM_DEV_LISTEN_ON_WILDCARD")):
            self.update(flask_listen_address="0.0.0.0")

        self.update(overrides)
 def test_display_traceback(self):
     self.assertEqual(
         read_env_bool("PYFARM_AGENT_API_DISPLAY_TRACEBACKS", True),
         Site.displayTracebacks)
Пример #5
0
from pyfarm.core.enums import AgentState, STRING_TYPES, PY3
from pyfarm.core.config import read_env_number, read_env_int, read_env_bool
from pyfarm.master.application import db, app
from pyfarm.models.core.functions import repr_ip
from pyfarm.models.core.mixins import (
    ValidatePriorityMixin, UtilityMixins, ReprMixin)
from pyfarm.models.core.types import (
    id_column, IPv4Address, IDTypeAgent, IDTypeTag, UseAgentAddressEnum,
    AgentStateEnum)
from pyfarm.models.core.cfg import (
    TABLE_AGENT, TABLE_SOFTWARE, TABLE_TAG, TABLE_AGENT_TAG_ASSOC,
    MAX_HOSTNAME_LENGTH, MAX_TAG_LENGTH, TABLE_AGENT_SOFTWARE_ASSOC,
    TABLE_PROJECT_AGENTS, TABLE_PROJECT)

PYFARM_REQUIRE_PRIVATE_IP = read_env_bool("PYFARM_REQUIRE_PRIVATE_IP", False)
REGEX_HOSTNAME = re.compile("^(?!-)[A-Z\d-]{1,63}(?<!-)"
                            "(\.(?!-)[A-Z\d-]{1,63}(?<!-))*\.?$"
                            , re.IGNORECASE)


AgentSoftwareAssociation = db.Table(
    TABLE_AGENT_SOFTWARE_ASSOC, db.metadata,
    db.Column("agent_id", IDTypeAgent,
              db.ForeignKey("%s.id" % TABLE_AGENT), primary_key=True),
    db.Column("software_id", db.Integer,
              db.ForeignKey("%s.id" % TABLE_SOFTWARE), primary_key=True))


AgentTagAssociation = db.Table(
    TABLE_AGENT_TAG_ASSOC, db.metadata,
Пример #6
0
        # Introspect dictionary objects for our
        # enum value type so we can dump out the string
        # value explicitly.  Otherwise, json.dumps will
        # dump out a tuple object instead.
        if isinstance(o, dict):
            o = o.copy()
            for key, value in o.items():
                if isinstance(value, Values):
                    o[key] = value.str

        return super(PyFarmJSONEncoder, self).encode(o)


dumps = partial(
    json.dumps,
    indent=4 if read_env_bool("PYFARM_PRETTY_JSON", False) else None,
    cls=PyFarmJSONEncoder)


class convert(object):
    """
    Namespace containing various static methods for converting data.

    Some staticmethods are named the same as builtin types. The name
    indicates the expected result but the staticmethod may not behave the
    same as the equivalently named Python object.  Read the documentation
    for each staticmethod to learn the differences, expected input and
    output.
    """
    @staticmethod
    def bytetomb(value):
Пример #7
0
    def encode(self, o):
        # Introspect dictionary objects for our
        # enum value type so we can dump out the string
        # value explicitly.  Otherwise, json.dumps will
        # dump out a tuple object instead.
        if isinstance(o, dict):
            o = o.copy()
            for key, value in o.items():
                if isinstance(value, Values):
                    o[key] = value.str

        return super(PyFarmJSONEncoder, self).encode(o)

dumps = partial(
    json.dumps,
    indent=4 if read_env_bool("PYFARM_PRETTY_JSON", False) else None,
    cls=PyFarmJSONEncoder)


class convert(object):
    """
    Namespace containing various static methods for converting data.

    Some staticmethods are named the same as builtin types. The name
    indicates the expected result but the staticmethod may not behave the
    same as the equivalently named Python object.  Read the documentation
    for each staticmethod to learn the differences, expected input and
    output.
    """
    @staticmethod
    def bytetomb(value):