Example #1
0
def setup_paasta_api():
    if os.environ.get("PAASTA_API_DEBUG"):
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    # pyinotify is a better solution than turning off file caching completely
    service_configuration_lib.disable_yaml_cache()

    settings.system_paasta_config = load_system_paasta_config()
    settings.cluster = settings.system_paasta_config.get_cluster()

    settings.marathon_clients = marathon_tools.get_marathon_clients(
        marathon_tools.get_marathon_servers(settings.system_paasta_config),
    )

    settings.marathon_servers = marathon_tools.get_marathon_servers(system_paasta_config=settings.system_paasta_config)
    settings.marathon_clients = marathon_tools.get_marathon_clients(
        marathon_servers=settings.marathon_servers,
        cached=False,
    )

    # Set up transparent cache for http API calls. With expire_after, responses
    # are removed only when the same request is made. Expired storage is not a
    # concern here. Thus remove_expired_responses is not needed.
    requests_cache.install_cache("paasta-api", backend="memory", expire_after=5)
 def __init__(self) -> None:
     super().__init__()
     self.started = False
     self.daemon = True
     service_configuration_lib.disable_yaml_cache()
     self.config = load_system_paasta_config()
     self.setup_logging()
     self.metrics = get_metrics_interface("paasta.deployd")
     self.setup_instances_to_bounce()
     self.control = PaastaQueue("ControlQueue")
     self.marathon_clients = get_marathon_clients_from_config()
Example #3
0
 def __init__(self):
     super(DeployDaemon, self).__init__()
     self.started = False
     self.daemon = True
     service_configuration_lib.disable_yaml_cache()
     self.config = load_system_paasta_config()
     self.setup_logging()
     self.bounce_q = PaastaQueue("BounceQueue")
     self.inbox_q = PaastaQueue("InboxQueue")
     self.control = PaastaQueue("ControlQueue")
     self.inbox = Inbox(self.inbox_q, self.bounce_q)
Example #4
0
 def testread_yaml_file_no_cache(self, load_patch, open_patch):
     expected = {'water': 'slide'}
     filename = 'fake_fname_tres'
     service_configuration_lib.disable_yaml_cache()
     actual = service_configuration_lib.read_yaml_file(filename)
     actual_two = service_configuration_lib.read_yaml_file(filename)
     open_patch.assert_any_call(filename, 'r', encoding='UTF-8')
     assert open_patch.call_count == 2
     load_patch.assert_any_call(open_patch.return_value.__enter__().read())
     assert load_patch.call_count == 2
     assert expected == actual
     assert expected == actual_two
Example #5
0
 def __init__(self):
     super().__init__()
     self.started = False
     self.daemon = True
     service_configuration_lib.disable_yaml_cache()
     self.config = load_system_paasta_config()
     self.setup_logging()
     self.bounce_q = DedupedPriorityQueue("BounceQueue")
     self.inbox_q = PaastaQueue("InboxQueue")
     self.control = PaastaQueue("ControlQueue")
     self.inbox = Inbox(self.inbox_q, self.bounce_q)
     self.marathon_clients = get_marathon_clients_from_config()
Example #6
0
 def __init__(self):
     super().__init__()
     self.started = False
     self.daemon = True
     service_configuration_lib.disable_yaml_cache()
     self.config = load_system_paasta_config()
     self.setup_logging()
     self.instances_to_bounce_now = DedupedPriorityQueue("instances_to_bounce_now")
     self.instances_to_bounce_later = PaastaQueue("instances_to_bounce_later")  # noqa: E501
     self.control = PaastaQueue("ControlQueue")
     self.inbox = Inbox(
         self.instances_to_bounce_later, self.instances_to_bounce_now,
     )
     self.marathon_clients = get_marathon_clients_from_config()
Example #7
0
def setup_paasta_api():
    # pyinotify is a better solution than turning off file caching completely
    service_configuration_lib.disable_yaml_cache()

    # Exit on exceptions while loading settings
    settings.cluster = load_system_paasta_config().get_cluster()

    marathon_config = marathon_tools.load_marathon_config()
    settings.marathon_client = marathon_tools.get_marathon_client(
        marathon_config.get_url(), marathon_config.get_username(),
        marathon_config.get_password())

    # Set up transparent cache for http API calls. With expire_after, responses
    # are removed only when the same request is made. Expired storage is not a
    # concern here. Thus remove_expired_responses is not needed.
    requests_cache.install_cache("paasta-api",
                                 backend="memory",
                                 expire_after=5)
Example #8
0
def setup_paasta_api():
    # pyinotify is a better solution than turning off file caching completely
    service_configuration_lib.disable_yaml_cache()

    # Exit on exceptions while loading settings
    settings.cluster = load_system_paasta_config().get_cluster()

    marathon_config = marathon_tools.load_marathon_config()
    settings.marathon_client = marathon_tools.get_marathon_client(
        marathon_config.get_url(),
        marathon_config.get_username(),
        marathon_config.get_password()
    )

    # Set up transparent cache for http API calls. With expire_after, responses
    # are removed only when the same request is made. Expired storage is not a
    # concern here. Thus remove_expired_responses is not needed.
    requests_cache.install_cache("paasta-api", backend="memory", expire_after=30)
Example #9
0
 def __init__(self):
     super(DeployDaemon, self).__init__()
     self.started = False
     self.daemon = True
     service_configuration_lib.disable_yaml_cache()
     self.config = load_system_paasta_config()
     root_logger = logging.getLogger()
     root_logger.setLevel(
         getattr(logging, self.config.get_deployd_log_level()))
     log_handlers = [logging.StreamHandler()]
     if os.path.exists('/dev/log'):
         log_handlers.append(logging.handlers.SysLogHandler('/dev/log'))
     for handler in log_handlers:
         root_logger.addHandler(handler)
         handler.setFormatter(
             logging.Formatter('%(levelname)s:%(name)s:%(message)s'))
     self.bounce_q = PaastaQueue("BounceQueue")
     self.inbox_q = PaastaQueue("InboxQueue")
     self.control = PaastaQueue("ControlQueue")
     self.inbox = Inbox(self.inbox_q, self.bounce_q)
Example #10
0
def setup_paasta_api():
    if os.environ.get("PAASTA_API_DEBUG"):
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    # pyinotify is a better solution than turning off file caching completely
    service_configuration_lib.disable_yaml_cache()

    settings.system_paasta_config = load_system_paasta_config()
    if os.environ.get("PAASTA_API_CLUSTER"):
        settings.cluster = os.environ.get("PAASTA_API_CLUSTER")
    else:
        settings.cluster = settings.system_paasta_config.get_cluster()

    settings.marathon_clients = marathon_tools.get_marathon_clients(
        marathon_tools.get_marathon_servers(settings.system_paasta_config), )

    settings.marathon_servers = marathon_tools.get_marathon_servers(
        system_paasta_config=settings.system_paasta_config)
    settings.marathon_clients = marathon_tools.get_marathon_clients(
        marathon_servers=settings.marathon_servers,
        cached=False,
    )

    try:
        settings.kubernetes_client = kubernetes_tools.KubeClient()
    except FileNotFoundError:
        log.info('Kubernetes not found')
        settings.kubernetes_client = None
    except Exception:
        log.exception('Error while initializing KubeClient')
        settings.kubernetes_client = None

    # Set up transparent cache for http API calls. With expire_after, responses
    # are removed only when the same request is made. Expired storage is not a
    # concern here. Thus remove_expired_responses is not needed.
    requests_cache.install_cache("paasta-api",
                                 backend="memory",
                                 expire_after=5)